Full Version : Problem with register handling
avr >>ASM PROGRAMMING (AVR) >>Problem with register handling


mikael_gronhage- 03-04-2007
Timer2 in ATmega48 is set for interrupt every 5msec. Then I create 4 more timers using this interrupt, i.e. at 10ms (counts in r7),50ms (r8),100ms (r9),500ms(r10).

Step1: If main prgm request to use 10ms timer, my case structure do like this:

ldi Temp, 0x07 ;address to register r7 is 0x07
sts TimeUnit_reg, Temp ;store adress to register that holds the timer request
;in sram variabel

Step2: Turn on LED (Temp value*Timer Unit Request)

lds Temp, LED_OnTime
Wait_xTimeUnit:
lds Temp2, TimeUnit_reg
cp Temp2, Temp
brne Wait_xTimeUnit
rcall STOP_PWM

This does not work, but If I replace "lds Temp2, TimeUnit_reg" with lds Temp2, 0x07" it works.

Can someone please give some help solving this problem

idratsina- 03-05-2007
Register to register copy should use MOV instruction instead LDS.
Example: mov r7,r8 ; copy value of r8 to r7

Register R0 to R31 is map to SRAM but use to special porpuse.

Use LDS and STS intruction to move value from/to register from/to
SRAM memory with address > $60 (60 hexadecimal).

Forumer™ is Voted #1 Free Forum Hosting provider
Build your own community today with the largest message board hosting company.