Question:

Atmel AVR Studio - code to input and iutput?

by  |  earlier

0 LIKES UnLike

could someone please help me to do the following code. Using the AVR8515 Project Board, Input 8-bits of data from the PORT C pins and Output the result to PORT B

 Tags:

   Report

1 ANSWERS


  1. EDIT:  Reenterd code text to avoid Yahoo truncation and added missing DDRB code line.

    Basically setup your input port data direction registers to 0 and if you want pull ups enabled write a 1 the input PORTx after the DDRx have been set to zero's.  MCUCR has a pull up disable bit which must be set to zero to globally enable the pull ups.

    Next configure your outout port by setting its DDR to 1's this automatically disable the pullups on any pin defined as an output.

    Once set up your main code section will loop. Reading the input port into a temp register and then writting the temp register to the output port.

    Copy and paste the following code into studio 4

    ;(1<<DDC7) is notation that means take a 1 and shift it left to the DDC7 bit position

    ;DDC7 is defined in the 8515def.inc  (definition include file) as 7

    ;the pipe symbol (|) means OR so individual bits are shifted and then OR'ed

    ;together to form an 8 bit word. This is supposed to be easier to read what specific

    ;bits are set to rather than looking at a raw binary or hex number as each bit is labled

    ;

    ;

    ;*** NOTE: the MCUCR (MCU Control register) PUD (Pull Up Disable) bit must be cleared

    ;to zero inorder for pull up resistors to be active.

    ;the \ is a line continuation character

    ;

    ;

    .def      temp =r16

    ;

    .cseg

    .org  0x20    ;places code well after interrupt vectors

    ;

    init:;   line label initialize

    ;

    ;Set Port C to Input using Data Direction register

    ldir16,(0<<DDC7)|(0<<DDC6)\

               |(0<<DDC5)|(0<<DDC4)\

               |(0<<DDC3)|(0<<DDC2)\

               |(0<<DDC1)|(0<<DDC0) ;equiv to ldi r16,0x00

    outDDRC,temp

    ;

    ;Set pull ups on port C

    ldir16,(1<<PC7)|(1<<PC6)\

               |(1<<PC5)|(1<<PC4)\

               |(1<<PC3)|(1<<PC2)\

               |(1<<PC1)|(1<<PC0) ;equiv to ldi r16,0xFF

    outPORTC,temp

    ;

    ;Configure Port B as outputs (Pull ups automatically disabled)

    ldi r16,  (1<<DDB7)|(1<<DDB6)\

                 |(1<<DDB5)|(1<<DDB4)\

                 |(1<<DDB3)|(1<<DDB2)\

                 |(1<<DDB1)|(1<<DDB0)

    out DDRB,r16

    main:;Line Label Main - main program loop

    in   temp,  PORTC   ;read port C pins into temp register r16

    out PORTB,  temp   ;Place temp onto output pins of PORTB

    rjmp   main   ;Endless loop back to main

Question Stats

Latest activity: earlier.
This question has 1 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.