Using PortG in Assembler on a AtMega128

Go To Last Post
3 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I was messing with the below assembler program and I am confused about how to get it to set PortG to output and toggle the PING0 high and low.
If I use the "Out DDRG, Temp" command I get a compiler error, so I tried the individual pin command instead. Thus it compiles without errors and appears to run OK.
When I run the below program on the emulator and debug single step it, PortG doesn't do anything at all.
I am using AVRStudio 4.04.

Can anyone please tell me what I am doing wrong?
Thanks
Earl

;A simple program
.include "m128def.inc" ;Includes the m128 definitions file

;define the variables being used
.def Temp = R16

.org 0x0000 ;Start the program code at address 0x0000
rjmp RESET ;Take a Relative Jump to the RESET Label

RESET:
; initialize the stack pointer
ldi Temp,HIGH(RAMEND)
out SPH,Temp
ldi Temp,LOW(RAMEND)
out SPL,Temp

ldi Temp, 0xFF ;Store 255 in Temp
;out DDRG, Temp ;causes an error
out DDG0,Temp

ldi Temp, 0xFF

Loop:

ldi Temp, 0x01
out PG0,Temp
ldi Temp,0x00
out PG0,Temp

rjmp Loop ; Loop Endlessly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Port G (and F) are mapped above the range of the IN/OUT commands. To access these registers, use LD/LDS/LDD and ST/STS/STD.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks, that was it.
I got it to work now.