There's two problems that I see.
When using the timers in 16-bit mode, you must write the high-byte then the low-byte, so make some changes to the Timer0.bas file:
Code: Select all
//
// a 16-bit timer must be set highbyte then lowbyte to set the TMRH latch first.
// use a macro here instead of a sub since it's used in an ISR, so low overhead
// and no frame variables used. The syntax of the macro allows it to be used
// with variables and/or constant values.
//
public macro LoadCount(wval)
TMR0H = ((wval) >> 8)
TMR0L = byte(wval)
end macro
Public Sub SInterrupt()
OnISR()
LoadCount(FPreload)
ClearInterrupt()
End Sub
Now, the code in main never initially sets a value for the timer count, so the first time it'll be wrong until it gets loaded after the first interrupt. Change the main routine around a bit:
Code: Select all
Dim LED As PORTC.0
Event LEDFlash()
Toggle(LED)
End Event
Interrupt ISR()
If Timer0.InterruptFlag =1 Then
Timer0.SInterrupt()
EndIf
End Interrupt
// main
SetAllDigital()
Output(LED)
Timer0.Initialize(LEDFlash)
Timer0.SetPrescaler(Timer0.PS256)
Timer0.EightBit = 0
Timer0.Preload = 60500
Timer0.LoadCount(Timer0.Preload) // **ADDED** to load count
Timer0.EnableInterrupt()
Timer0.Enabled()
Enable(ISR)
While true
Wend
I added initially loading the timer using the new LoadCount() macro, and got rid of statements in the ISR messing around with INTCON.7 (which is the GIE bit). No need to play around with this.
See if that works out any better. I didn't test it, so let us know.