I'm sorry I'm a slow learner... I don't know which ports and registers to properly setup parameters for my RTC
PRELUDE:
In my latest Butterfly Bootloader (Cricket) I wanted to totally change the upload logic. I got tired of holding down the joystick in the middle postion and I think it's wearing out. I designed it mostly for my own personal use and find it very difficult to use anything else now that I am used to how much easier it is to use.
What I wanted was when the Cricket was RESET it would "chirp" once then calibrate the OSciallator then "chirp" again and automatically wait for you to either upload a new program or to move the joystick to launch a program. After a reasonable amount of time it would "chirp" one last time to let you know it was going to sleep to conserve battery.
I used a timer to do this, and perhaps this listing will help you to get started with your RTC in ASM. The only lines you really need to worry about are the first three and four near the end that read the clock and exit when high byte gets to 255.
THE MATH:
Here is how the Math works out:
The clock speed I chose to use for this part of program is 8Mhz and writing a 5 to TCCRB1 set the "prescaler" to 1024.
That mean that the timer will only "tick" after 1024 clock cycles.
Since I am using 2 bytes for the clock/timer the lower-byte is going to "roll-over" and increment the high-byte when it hits 256:
CODE
HighByteTick = 256 x 0.000128 = 0.032768 Sec
Since I Exit when HighByte gets to 255:
CODE
Exit=255 x 0.032768 = 8.35 Seconds
When I initially worked this out, I figured the 8 seconds was way too short to start uploads, and was going to extend it, but it turns out that 8 seconds is ideal.
THE PROGRAM SEGMENT:
CODE
;----------------------------------; ; BOOT SENSORY LOOP ; ; CHECK JOYSTICK & UART THEN SLEEP; ;----------------------------------; STS TCCR1B,FIVE;PRESCALE /1024 STS TCNT1L,ZERO;START AT ZERO STS TCNT1H,ZERO
BOOT_LOOP: CLR TMP SBIS PINB,6 ;JOYSTICK UP RJMP START_8MHZ SBIS PINB,7 ;JOYSTICK DOWN RJMP START_2MHZ SBIS PINE,2 ;JOYSTICK LEFT RJMP START_4MHZ SBIS PINE,3 ;JOYSTICK RIGHT RJMP START_1MHZ
So I don't profess to be an expert on using timers in ASM, but I hope that you can work-out your own MATH using this as an example, and get you on-your-way to designing your own RTC.
ADDENDUM:
Another example of the Math using the same clock and prescaler: