Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
// 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
3rd chip and nothing happens??
have resistors and LEDs connected on breadboard to ports B0, B1, B6, B7
no LEDs lighting up??
// 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)//pin 8
End Event
// activate the timer module...
Timer.Initialize
// initialise the timers - refresh every 1000Hz (1ms)...
Timer.Items(Timer1).Interval = 20 // [COLOR="Red"]led lights for 5 seconds[/COLOR]
Timer.Items(Timer1).OnTimer = OnTimer1 // timer event handler
// timer event handler
Timer.Items(Timer4).Interval = 2000 // 2000ms, no event handler
// enable the timers...
Timer.Items(Timer1).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.0)//pin 8
Timer.Items(Timer4).Enabled = true
EndIf
// background flash LED...
High(PORTB.7)//pin 13// [COLOR="Red"]why does the LED on pins 12 & 13 stay on all the time?[/COLOR]
DelayMS(50)
Low(PORTB.6)// pin 12
DelayMS(50)
Wend
set your portswhy does the LED on pins 12 & 13 stay on all the time
[COLOR="Red"]trisb =$0 //sets all pins to output on PORTB [/COLOR]
[COLOR="Red"]PORTB =$0 //sets all pin low on PORTB[/COLOR]
// 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.0)//pin 8
Timer.Items(Timer4).Enabled = true
EndIf
// background flash LED...
High(PORTB.7)//pin 13// why does the LED on pins 12 & 13 stay on all the time?
DelayMS(50)
Low(PORTB.6)// pin 12
DelayMS(50)
Wend