// 18F1320@ 8MHz - they are just used here for clarity...
device = 18F1320
clock = 8
include "ISRTimer.bas"
// constant ID to 4 * 16 bit timers...
const
Timer1 = 0,
Timer2 = 1,
Timer3 = 2,
Timer4 = 3
// OnTimer1 event...
event OnTimer1()
toggle(PORTB.0)
end event
// OnTimer2 event...
event OnTimer2()
toggle(PORTB.1)
end event
// OnTimer3 event...
event OnTimer3()
toggle(PORTB.2)
end event
// activate the timer module...
Timer.Initialize
// initialise the timers - refresh every 1000Hz (1ms)...
Timer.Items(Timer1).Interval = 50 // 50ms
Timer.Items(Timer1).OnTimer = OnTimer1 // timer event handler
Timer.Items(Timer2).Interval = 250 // 250ms
Timer.Items(Timer2).OnTimer = OnTimer2 // timer event handler
Timer.Items(Timer3).Interval = 500 // 500ms
Timer.Items(Timer3).OnTimer = OnTimer3 // timer event handler
Timer.Items(Timer4).Interval = 2000 // 2000ms, no event handler
// enable the timers...
Timer.Items(Timer1).Enabled = true
Timer.Items(Timer2).Enabled = true
Timer.Items(Timer3).Enabled = true
Timer.Items(Timer4).Enabled = true
// start processing all timers...
Timer.Start
// main program loop...
while true
// this is a polled timer, not event driven - check to see
// if it has timeout...
if not Timer.Items(Timer4).Enabled then
toggle(PORTB.3)
Timer.Items(Timer4).Enabled = true
endif
// background flash LED...
high(PORTB.7)
delayms(500)
low(PORTB.7)
delayms(500)
wend