Code:
'COUNTDOWN MENU
'--------------
MenuA:
PAUSE 1000
TIMER=0
MENUCD:
LCDOUT $FE, 1, " Preset 1"
LCDOut $FE,$C0,"00:30:00.00"
pause 100
IF BUTSTART=0 THEN
GOTO preset1
ENDIF
IF BUTDWN=0 THEN
GOTO CUSTOMA
ENDIF
IF BUTUP=0 THEN
GOTO PRESET2
ENDIF
IF BUTRESET=0 THEN
GOTO MAINMENU
ENDIF
GOTO MENUCD
CUSTOMA:
PAUSE 1000
CUSTOMB:
LCDOUT $FE, 1, "CUSTOM TIME"
LCDOut $FE,$C0,"ENTER A CUSTOM TIME"
PAUSE 100
IF BUTSTART=0 THEN
GOTO CUSTOM
ENDIF
IF BUTDWN=0 THEN
GOTO PRESET2
ENDIF
IF BUTUP=0 THEN
GOTO MENUCD
ENDIF
IF BUTRESET=0 THEN
GOTO MAINMENU
ENDIF
PAUSE 50
GOTO CUSTOMB
'----------------------------
PRESET1:
PAUSE 1000
PRESET1A
LCDOUT $FE, 1, "Accept Preset 1?"
LCDOut $FE,$C0,"00:30:00.00"
PAUSE 100
IF BUTSTART=0 THEN
GOTO PRESET1set
ENDIF
IF BUTRESET=0 THEN
GOTO MENUCD
ENDIF
GOTO PRESET1A
PRESET1SET:
IHOURS=0
IMINUTES=30
PAUSE 50
GOTO CONTINUE
'---------------------------
PRESET2:
PAUSE 1000
PRESET2A
LCDOUT $FE, 1, " Preset 2"
LCDOut $FE,$C0,"00:45:00.00"
PAUSE 100
IF BUTSTART=0 THEN
GOTO PRESET2A
ENDIF
IF BUTUP=0 THEN
GOTO CUSTOMA
ENDIF
IF BUTDWN=0 THEN
GOTO menuCD
ENDIF
IF BUTRESET=0 THEN
GOTO MAINMENU
ENDIF
GOTO PRESET2A
PRESET2B:
PAUSE 1000
PRESET2C
LCDOUT $FE, 1, "Accept Preset 2?"
LCDOut $FE,$C0,"00:45:00.00"
PAUSE 100
IF BUTSTART=0 THEN
GOTO PRESET2SET
ENDIF
IF BUTRESET=0 THEN
GOTO MENUCD
ENDIF
GOTO PRESET2C
PRESET2SET:
IHOURS=0
IMINUTES=45
PAUSE 50
GOTO CONTINUE
'
' Custom Time Setup
'----------------------------
CUSTOM:
PAUSE 1000
IHOURS=0
IMINUTES=3
HOURSI:
If Butup=0 then
IHOURS=IHOURS+1
endif
If BUTDWN=0 THEN
IHOURS=IHOURS-1
ENDIF
IF BUTSTART=0 THEN
GOTO MINSA
ENDIF
IF BUTRESET=0 THEN
GOTO MENUA
ENDIF
pause 50
GOSUB TIMESETUP
GOTO HOURSI
MINSA:
PAUSE 1000
MINSI:
IF BUTUP=0 THEN
IMINUTES=IMINUTES+1
ENDIF
IF BUTDWN=0 THEN
IMINUTES=IMINUTES-1
ENDIF
IF BUTRESET=0 THEN
GOTO HOURSI
ENDIF
IF BUTSTART=0 THEN
GOTO CONTINUE
ENDIF
PAUSE 50
GOSUB TIMESETUP
GOTO MINSI
timesetup:
pause 50
LCDOUT $FE, 1, "GAME LENGTH"
LCDOut $FE,$C0,DEC2 IHours,":",DEC2 IMinutes,":00.00"
PAUSE 50
REturn
Continue:
LCDOUT $FE, 1, "Settings Saved"
LCDOut $FE,$C0,DEC2 IHours,":",DEC2 IMinutes,":00.00"
pause 6000
BEGINNING
'
' Initialise TMR1 Interrupts*******************************************************************************************
' --------------------------
Gosub SetTimer ' Set the Timer for next 10mS Interrupt
IF TIMER=1 THEN
On Interrupt goto TickCountUP
ELSE
On Interrupt goto TickCount
ENDIF
PIE1.0=1 ' Enable TMR1 Interrupts
INTCON.6=1 ' Enable all unmasked Interrupts
INTCON.7=1 ' Enable Global Interrupts
'
' -----------------------------------------------------
' Following the above "On Interrupt", no Basic Command
' is allowed that takes more than 10mS to execute
' otherwise the 10mS Interrupt interval is compromised.
' -----------------------------------------------------
'
' Reset Timer Variables for Start
' -------------------------------
DisplayReset:
LCDOut $FE,1 ' Clear LCD
Read 0,TMR1CalAR ' Read Calibration Advance/Retard Indicator
Read 1,TMR1Cal ' Read Calibration Value
Hundredths=0 ' Reset Timer Counter variables
Seconds=0
Minutes=IMINUTES
Hours=IHOURS
OverflowError=0
'
' Main Program Loop
' =================
Enable
DisplayLoop:
If ButStart=0 then RunningFlag=1
If ButStop=0 then RunningFlag=0
LCDOut $FE,$80,DEC2 Hours,":",DEC2 Minutes,":",DEC2 Seconds,".",DEC2 Hundredths
If OverflowError=1 then
If Seconds.0=1 then
LCDOut $FE,$8C,"ERR"
else
LCDOut $FE,$8C," "
endif
endif
If RunningFlag=1 then goto DisplayLoop
If ButReset=1 then goto DisplayLoop
Disable
'
' Reset Clock
' ===========
' Momentarily Press the Reset Button for RESET action.
' Continue holding the Reset Button for MORE than 5 seconds
' to jump into Calibration/Set-Up Mode
'
ResetClock:
LCDOut $FE,1,"Reset OK"
Pause 1000
Seconds=1
While Seconds < 5
Pause 1000
If ButReset=1 then goto DisplayReset
Seconds=Seconds+1
Wend
'
' Calibration Adjustment
' ======================
' If No Button is Pressed for 20 Seconds, then the program
' will automatically exit Calibration/Set-Up Mode WITHOUT saving
' any new values.
'
SetUpTimeout=0
Calibration:
LCDOut $FE,1,"Calibrate: "
While ButReset=0:Wend ' Wait for User to release finger
CalibrationLoop:
LCDOut $FE,$8B
If TMR1Cal=0 then
LCDOut " "
else
If TMR1CalAR=0 then
LCDOut "+"
else
LCDOut "-"
endif
endif
LCDOut #TMR1Cal," "
' ----------------------------------------------------------
' Press Start Button to ADVANCE (speed-up) Clock
' Press STOP Button to RETARD (slow-down) Clock
' Press RESET Button to SAVE new Calibration Setting
' ----------------------------------------------------------
' Remember each Calibration 'tick' will advance or
' retard the Timing by 1uS in every 10mS period - that's
' 360mS/Hour per setting. Example: A setting of +8 will
' SPEED-UP the Timer by 2.88 Seconds (8 x 360mS) in an Hour.
' ----------------------------------------------------------
If TMR1CalAR=0 then
If ButStart=0 then Gosub CalAdvance
If ButStop=0 then Gosub CalRetard
else
If ButStart=0 then Gosub CalRetard
If ButStop=0 then Gosub CalAdvance
endif
If ButReset=0 then
Write 0,TMR1CalAR
Write 1,TMR1Cal
LCDOut $FE,1,"Have a Nice Day"
Pause 1000
Goto DisplayReset
endif
SetupTimeout=SetupTimeout+1
If SetupTimeout>200 then goto DisplayReset
Pause 100
Goto CalibrationLoop
'
' Subroutine Increments Calibration Value
' ---------------------------------------
CalAdvance:
SetupTimeout=0
If TMR1Cal=>TMR1CalMax then
TMR1Cal=TMR1cALmAX
TMR1CalAR=TMR1CalAR^1
else
TMR1Cal=TMR1Cal+1
endif
Return
'
' Subroutine Decrements Calibration Value
' ---------------------------------------
CalRetard:
SetupTimeout=0
If TMR1Cal=0 then
TMR1Cal=1
TMR1CalAR=TMR1CalAR^1
else
TMR1Cal=TMR1Cal-1
endif
Return
'
' Subroutine Displays Banner Intro
' --------------------------------
DisplayBanner:
CounterC=BannerOffset+15
LCDOut $FE,$80
For CounterB=BannerOffset to CounterC
Read CounterB,DataA
LCDOut DataA
Next CounterB
Return
'
' Subroutine Loads TMR1 values
' ============================
SetTimer:
T1CON.0=0 ' Stop the Clock
TMR1RunOn.Highbyte=TMR1H ' Load the Run-On (Over-Run) value (if any)
TMR1RunOn.Lowbyte=TMR1L
TMR1RunOn=TMR1Preset+TMR1RunOn
' Calculate the New (adjusted) value for TMR1
If TMR1CalAR=0 then ' Calibration ADVANCE (add) or RETARD (subtract)
TMR1RunOn=TMR1RunOn+TMR1Cal
else
TMR1RunOn=TMR1RunOn-TMR1Cal
endif
TMR1H=TMR1RunOn.Highbyte ' Save new values to TMR1
TMR1L=TMR1RunOn.Lowbyte
T1CON.0=1 ' Restart the Clock
PIR1.0=0 ' Reset TMR1's Interupt Flag
Return
'
' Timer Interrupt Handler
' =======================
TickCount:
Gosub SetTimer ' Set the Timer for next 10mS Interrupt
If RunningFlag=1 then ' If timing actually enabled... then...
IF HUNDREDTHS=0 THEN
IF SECONDS=0 THEN
IF MINUTES=0 THEN
IF HOURS=0 THEN
GOTO TIMEUP
ENDIF
ENDIF
ENDIF
ENDIF
If seconds=0 then
hundredths=0
'goSUB timeup
else
Hundredths=Hundredths-1
' Increment 10mS Seconds Counter
If Hundredths=0 then
Hundredths=99
seconds=seconds-1
endif
endif
' Increment the Seconds
If minutes>0 then
If Seconds=0 then
Seconds=59
minutes=minutes-1
endif
endif
If hours>0 then
If Minutes=0 then
Minutes=59
hours=hours-1
endif
endif
If Hours>99 then
' Handle any Overflow
Hours=0
OverFlowError=1
endif
endif
Resume
timeup:
LCDOUT $FE,$C0
LCDOUT "Time is up"
GOTO timeup
TickCountUP:
Gosub SetTimer ' Set the Timer for next 10mS Interrupt
If RunningFlag=1 then ' If timing actually enabled... then...
Hundredths=Hundredths+1
' Increment 10mS Seconds Counter
If Hundredths>99 then
Hundredths=0
Seconds=Seconds+1
' Increment the Seconds
If Seconds>59 then
Seconds=0
Minutes=Minutes+1
' Increment the Minutes
If Minutes>59 then
Minutes=0
Hours=Hours+1
' Increment the Hours
If Hours>99 then
' Handle any Overflow
Hours=0
OverFlowError=1
endif
endif
endif
endif
endif
Resume
End
Bookmarks