This piece of code turns pin 2 on and off for 20 secs each when setint is commented out.
When coded as below, the output is on for 20secs and off for 3secs.
I have run it on 08M and 08M2 with same result.
I would appreciate and help on why.
Fred
When coded as below, the output is on for 20secs and off for 3secs.
I have run it on 08M and 08M2 with same result.
I would appreciate and help on why.
Fred
Code:
symbol timeon = 20 'time on for fan in seconds
symbol timeoff = 20 'time off for fan in seconds
symbol fantime = w3 'counter for fan
fantime = timeon 'initialise as timeon
symbol fanon = b0 'fan on flag
symbol fanflag = b1 'fan flag
symbol fanctr = w4 'fan counter
symbol fan = 2 'output pin for fan
'*****************************************************
main:
setint %00001000,%00001000 'activate interrupt when pin3 only goes high
gosub fancontrol '
pause 1000 'this is the 1 sec time delay
goto main
'***********************************************
Fancontrol: 'count seconds for turning fan on and off
inc fanctr
if fanctr < fantime and fanon = 0 and fanflag = 0 then
goto fanrun
else if fanctr < fantime and fanon = 0 and fanflag = 1 then
return
else if fanctr > fantime and fanon = 1 then
goto fanoff
else if fanctr > fantime and fanflag = 1 then
fanflag = 0
goto fanrun
endif
return
fanrun:
high fan
fanon = 1
fantime = timeon
fanctr = 1
return
fanoff:
low fan
fanon = 0
fantime = timeoff
fanctr = 1
fanflag = 1
return
'**************************************
interrupt: 'button pushed
pause 100 'debounce switch
return