Hello,
I'm teaching myself assembly and all is good so far. I'm using AVRstudio (the latest version 4.17) to simulate an atmega88 (using simulator II)
Here's my problem.
Im trying to make my 16 bit timer count to 19531 or higher - but when reading the High byte of TCNT1, it always reads zero. Here is my code. Please bear if it is so blindingly incorrect - I am trying to learn.
Code:
.NOLIST
.INCLUDE "m88def.inc"
.LIST
.DEF rmp = r16 ;multipurpose register
.CSEG
.ORG 0000
rjmp main
main:
ldi r16,HIGH(RAMEND) ;Initiate Stackpointer
out SPH,r16 ; for the use by interrupts and subroutines
ldi r16,LOW(RAMEND)
out SPL,r16
;set up the output and timer
ldi rmp, 0xFF
out DDRC, rmp
ldi rmp, (1<<CS10) ;prescaler : 1/1024
sts TCCR1B, rmp
; reset the timer
reset:
ldi rmp, 0x00
sts TCNT1H, rmp
sts TCNT1L, rmp
loop: ;wait for the counter to reach 19531 cycles
lds rmp, TCNT1H ; <---- HERE IS where rmp will always be 0
cpi rmp, 0x4B
brlo loop ;<-- Always goes back to loop
lds rmp, TCNT1L
cpi rmp, 0x4A
brlo loop
;we waited just about one second
;toggle the LEDS
in rmp, PORTC
com rmp
out PORTC, rmp
rjmp reset
rjmp main
If someone encountered this before, please let me know. I will really appreciate it.
Thanks in advance
Andrew |