IO view in Atmel Studio 6

Discussion in 'Embedded Systems and Microcontrollers' started by drbenne, Oct 23, 2013.

  1. drbenne

    Thread Starter Member

    Jul 30, 2013
    45
    0
    I'm simulating an ATmega328p trying to get a better understanding of the inner workings of a uC using the IO and processor view but am getting confused about a few things.

    First, looking at the 3 registers in the IO view of each port (DDRx, PINx, PORTx) there is an address next to them identifying each one separately. But what is confusing me is that the address listed in the IO view does not correspond to the atmega328's datasheet or M328PDEF.INC file.

    For example, the addresses listed in the datasheet and .INC file for the registers in PORTB are:

    PINB: 0x03
    DDRB: 0x04
    PORTB: 0x05


    But, when looking in the IO view at these registers they are listed as:

    PINB: 0x23
    DDRB: 0x24
    PORTB: 0x25

    [​IMG]



    Second, in the processor view there are 32 registers, R00-R31. Which registers are those referring to and what would they be called in the .INC file?


    Here is a the code that I am using. It is supposed to send a square wave to PORTB to produce a sound. It was originally written for a different MCU but I just changed the .INC file to the one designated for the Atmega328.

    Code ( (Unknown Language)):
    1.  
    2. .INCLUDE "M328PDEF.INC"
    3. ;-----------------------------------------;
    4. ; FIRST WE'LL DEFINE SOME REGISTER TO USE ;
    5. ;-----------------------------------------;
    6. .DEF A = R16 ;GENERAL PURPOSE ACCUMULATOR
    7. .DEF I = R21 ;INDEXES FOR LOOP CONTROL
    8. .DEF J = R22
    9. .ORG $0000
    10. ;-----------------------------------------;
    11. ; FIRST WE SETUP A STACK AREA THEN SET ;
    12. ; DIRECTION BIT ON PORT-B FOR OUTPUT/SPKR ;
    13. ;-----------------------------------------;
    14. START:
    15.      LDI A,LOW(RAMEND) ;SETUP STACK POINTER
    16.      OUT SPL,A ;SO CALLS TO SUBROUTINES
    17.      LDI A,HIGH(RAMEND) ;WORK CORRECTLY
    18.      OUT SPH,A ;
    19.      LDI A,0b1111_1111 ;SET ALL PORTB FOR OUTPUT
    20.      OUT DDRB,A ;WRITE 1s TO DIRECTN REGS
    21. ;--------------;
    22. ; MAIN ROUTINE ;
    23. ;--------------;
    24. BEEP: CLR I
    25. BLUPE:
    26.      SER A ;TURN SPKR ON
    27.      OUT PORTB,A
    28.      RCALL PAUSE ;WAIT
    29.      CLR A ;TURN IT OFF
    30.      OUT PORTB,A
    31.      RCALL PAUSE ;WAIT AGAIN
    32.      DEC I
    33.      BRNE BLUPE
    34. LOOP: RJMP LOOP ;STAY HERE WHEN DONE
    35. ;----------------;
    36. ;PAUSE ROUTINE ;
    37. ;----------------;
    38. PAUSE:
    39.      CLR J
    40.      PLUPE:
    41.      NOP
    42.      DEC J
    43.      BRNE PLUPE
    44. RET

    Thanks,

    Dave
     
Loading...