Forum Menu




 


Log in Problems?
New User? Sign Up!
AVR Freaks Forum Index

Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Author Message
andrewortman
PostPosted: Aug 16, 2009 - 08:13 PM
Newbie


Joined: Jun 02, 2009
Posts: 4


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. Wink

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 Smile
Andrew
 
 View user's profile Send private message  
Reply with quote Back to top
Koshchi
PostPosted: Aug 16, 2009 - 08:16 PM
10k+ Postman


Joined: Nov 17, 2004
Posts: 13825
Location: Vancouver, BC

If you read the section in the datasheet on "Accessing 16bit Registers" you find that TCNT1L must be read before TCNTH. Also in that section it tells you how to write 16 bit registers. Datasheets can be useful that way Smile

_________________
Regards,
Steve A.

The Board helps those that help themselves.
 
 View user's profile Send private message  
Reply with quote Back to top
andrewortman
PostPosted: Aug 16, 2009 - 08:21 PM
Newbie


Joined: Jun 02, 2009
Posts: 4


Oh, I didn't know that. Thanks Koshchi! Smile
 
 View user's profile Send private message  
Reply with quote Back to top
Display posts from previous:     
Jump to:  
All times are GMT + 1 Hour
Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Powered by PNphpBB2 © 2003-2006 The PNphpBB Group
Credits