OSCCON = %01110011
DEFINE OSC 8
DEFINE WRITE_INT 1
Include "modedefs.bas"
SSW var PortA.7
redport var PortB.5
blueport var PortB.7
greenport var PortB.6
enable1 var PortB.2
enable2 var PortB.3
runtime var word
RunningFlag var BIT
Startswitch var PortA.3
ended var bit
Thousandths var word
Hundredths var word
Seconds var word
comp var bit
adcon0.0 = 0
adcon1.3 = 1
adcon1.4 = 1
adcon1.5 = 1
adcon1.6 = 1
TRISA = %11111000
TRISB = %00010011
PortB.5 = 0
PortB.2 = 0
T1CON = %00000100
comp = 0
redport = 0
greenport = 0
blueport = 0
enable1 = 0
enable2 = 0
ended = 0
runningflag = 0
thousandths = 0
Hundredths = 0
Seconds = 0
Gosub SetTimer
blueport = 1 'testing outputs
pause 2000
blueport = 0
greenport = 1
pause 2000
greenport = 0
On Interrupt goto Starttimer
PIE1.0=1 ' Enable TMR1 Interrupts
INTCON.6=1 ' Enable all unmasked Interrupts
INTCON.7=1 ' Enable Global Interrupts
main:
if PortB.0 = 0 then
if PortB.1 = 1 then
if PortB.4 = 1 then
runtime = 60
endif
endif
endif
if PortB.0 = 1 then
if PortB.1 = 1 then
if PortB.4 = 1 then
runtime = 90
endif
endif
endif
if PortB.0 = 1 then
if PortB.1 = 0 then
if PortB.4 = 0 then
runtime = 120
endif
endif
endif
write 5, runtime
if SSW = 1 then
redport = 1
pause 200
redport = 0
pause 200
goto main
endif
if SSW = 0 then
redport = 1
goto main1
endif
goto main
'main code loop
Enable
main1:
if ssw = 1 then 'checks to see if lid is closed, if not,
goto main 'go back to first loop and wait
endif 'if lid is closed, continue on to next requirement
if SSW = 0 and startswitch = 1 then 'starts the first run of the timer if lid
ended = 0 'is closed and push button has been pressed
runningflag = 1 'and sets a flag to show timer is running
GOSUB StartTimer
endif
if runningflag = 1 then 'checks to see if timer was started and
gosub starttimer 'if true loops for next cycle
endif
goto main1
disable
completed:
T1CON.0=0
enable1 = 0
enable2 = 0
greenport = 1
redport = 0
blueport = 0
runningflag = 0
comp = 1
if ssw = 1 then
greenport = 0
goto main
endif
goto completed
return
'
' Subroutine Loads TMR1 values
' ============================
SetTimer:
T1CON.0=0 ' Stop the Clock
TMR1H=$B1
TMR1L=$e7
PIR1.0=0 ' Reset TMR1's Interupt Flag
Return
' Subroutine to stop the timer, reset, and shutoff outputs
Stoptimer:
T1CON.0=0
TMR1H=$B1
TMR1L=$E7
PIR1.0=0
enable1 = 0
enable2 = 0
thousandths = 0
Hundredths = 0
Seconds = 0
redport = 0
blueport = 0
greenport = 1
runningflag = 0
ended = 1
'gosub settimer
Pause 1000
return
Starttimer:
redport = 1 'output to show timer is running
blueport = 1
greenport = 0 'provides a pulse to measure for diagnostics to check timer is actually running
greenport= 1
greenport = 0
enable1 = 1 'turns on both LED channels
enable2 = 1
Gosub SetTimer ' Set the Timer for next Interrupt
If RunningFlag=1 then ' If timing actually enabled then continue
thousandths=thousandths+1
if thousandths>999 then
thousandths=0
Hundredths=Hundredths+1
If Hundredths>99 then
Hundredths=0
Seconds=Seconds+1
write 10, seconds 'just to see if it turns off at runtime seconds
' Increment the Seconds
if seconds = runtime then
gosub stoptimer
goto completed
endif
endif
endif
endif
if ssw = 1 then
gosub stoptimer
goto main
endif
Resume
End
Bookmarks