I'm not using an interrupt as such I'm polling the Timer1 flag.
Some code extracts here below
Code:
Initialise: 'Initialise 250ms Timer 8mhz clock
PreLoad = 3035 'Preload Constant Loads Timer with 3035 to get 250ms ticks
PIE1.0 = 1 'Enable TMR1 Interrupts (Not sure about this)
TMR1L = PreLoad.LowByte 'Load the Timer with preload value
TMR1H = PreLoad.HighByte 'Load the Timer with preload value
TMR1IF = 0 'Clear TMR1 int flag
My Serin2 command is here in the code.
Code:
IF TMR1IF = 0 THEN TimerJump 'If 250ms has not elapsed then jump over below section
T1CON.0=0 'Stop the Clock
TMR1RunOn.Highbyte = TMR1H 'Load the Run-On (Over-Run) value (if any)
TMR1RunOn.Lowbyte = TMR1L 'Load the Run-On (Over-Run) value (if any)
TMR1RunOn = PreLoad + TMR1RunOn 'Calculate new Preload setting to include any timer overrun
TMR1H = TMR1RunOn.HighByte 'Load the timer with new value
TMR1L = TMR1RunOn.LowByte 'Load the timer with new value
T1CON.0=1 'Restart the Clock
TMR1IF = 0 'Clear TMR1 int flag
'PIR1.0=0 'Reset TMR1's Interupt Flag (Not sure about this)
So you can see i intialise the timer for 250ms ticks. Then poll the flag. If it is set then I execute some code and then reinitialise the timer adding any overrun to the preload value.
Bookmarks