IO view in Atmel Studio 6

Thread Starter

drbenne

Joined Jul 30, 2013
48
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





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.

Rich (BB code):
.INCLUDE "M328PDEF.INC" 
;-----------------------------------------;
; FIRST WE'LL DEFINE SOME REGISTER TO USE ;
;-----------------------------------------;
.DEF A = R16 ;GENERAL PURPOSE ACCUMULATOR
.DEF I = R21 ;INDEXES FOR LOOP CONTROL
.DEF J = R22
.ORG $0000
;-----------------------------------------;
; FIRST WE SETUP A STACK AREA THEN SET ;
; DIRECTION BIT ON PORT-B FOR OUTPUT/SPKR ;
;-----------------------------------------;
START:
     LDI A,LOW(RAMEND) ;SETUP STACK POINTER
     OUT SPL,A ;SO CALLS TO SUBROUTINES
     LDI A,HIGH(RAMEND) ;WORK CORRECTLY
     OUT SPH,A ;
     LDI A,0b1111_1111 ;SET ALL PORTB FOR OUTPUT
     OUT DDRB,A ;WRITE 1s TO DIRECTN REGS
;--------------;
; MAIN ROUTINE ;
;--------------;
BEEP: CLR I
BLUPE:
     SER A ;TURN SPKR ON
     OUT PORTB,A
     RCALL PAUSE ;WAIT
     CLR A ;TURN IT OFF
     OUT PORTB,A
     RCALL PAUSE ;WAIT AGAIN
     DEC I
     BRNE BLUPE
LOOP: RJMP LOOP ;STAY HERE WHEN DONE
;----------------;
;PAUSE ROUTINE ;
;----------------;
PAUSE:
     CLR J
     PLUPE:
     NOP
     DEC J
     BRNE PLUPE
RET

Thanks,

Dave
 
Top