Well, just take the Olympic Timer as an example and strip it out and refit it to your requirements (after all that's why I created it)... First let's take that interrupt handler and rebuild it to toggle a Flag every minute instead of keeping track of actual Minutes, Hours and Overflow which are unnescessary for your needs....
The SetTimer subroutine can be simplified to junk the Calibration value like so...Code:' ' Timer Interrupt Handler ' ======================= TickCount: Gosub SetTimer Hundredths=Hundredths+1 If Hundredths>99 then Hundredths=0 Seconds=Seconds+1 If Seconds>59 then Seconds=0 MinuteFlag=MinuteFlag^1 endif endif Resume
Finally we lose our entire Main program body, Reset Code, Calibration Set-Up, and all the unnescessary subroutines, EEPROM settings etc etc leaving us just your desired application... and if you notice the main body is pretty much the exact code that you've written... so in effect you were already 99.9% of the way to your own solution...Code:' ' Subroutine Loads TMR1 values ' ============================ SetTimer: T1CON.0=0 TMR1RunOn.Highbyte=TMR1H TMR1RunOn.Lowbyte=TMR1L TMR1RunOn=TMR1Preset+TMR1RunOn TMR1H=TMR1RunOn.Highbyte TMR1L=TMR1RunOn.Lowbyte T1CON.0=1 PIR1.0=0 Return
Just remember that no command in your Main Program Loop can exceed 10mS execution time otherwise you will lose your timing integrity (program won't die, but you won't get a 1 Minute timing interval for the Flag to toggle, it'll be 1 Minute plus the number of 10mS interrupt ticks you've missed).Code:' ' Software Defines ' ---------------- Hundredths var BYTE MinuteFlag var BIT Seconds var BYTE TMR1RunOn var WORD ' ' Software Constants ' ------------------ TMR1Preset con $D910 ' ' Start Program ' ============= ' ' Initialise Processor ' -------------------- ' Put your TRIS and Register initialisation statements here MinuteFlag=0 Hundredths=0 Seconds=0 ' ' Initialise TMR1 Interrupts ' -------------------------- Gosub SetTimer On Interrupt goto TickCount PIE1.0=1 INTCON.6=1 INTCON.7=1 ' ' Main Program Loop ' ================= Enable Begin: let portb.0 = porta.0 If MinuteFlag=1 then goto LoopXXX goto begin loopXXX: let portb.0 = porta.1 goto loopXXX Disable
If accuracy in your minutes is important to you, adjust the TMR1Preset constant. Increase the value to speed up by 100uS per minute, Decrease the value to slow down by 100uS per minute (at 4MHz clock).
See... easy peasy... don't be afraid to take any of my code and trash it into anything that you need... it's posted for you to learn from.
Melanie




Bookmarks