Device = 18F43k22
Clock = 8
//Config MCLRE = off
// some LCD options...
#option LCD_DATA = PORTD.4
#option LCD_RS = PORTD.2
#option LCD_EN = PORTD.3
// import LCD library...
Include "SetDigitalIO.bas"
Include "IntOSC.bas"
Include "LCD.bas"
Include "utils.bas"
'INCLUDE "Keypad16pullup.bas"
Include "Convert.bas"
Include "isrtimer.bas"
Include "EEPROM.bas"
Dim s As String
Dim mS As Word
Dim GO_1 As PORTC.0 //goes LOW when player presses switch
Dim GO_2 As PORTC.2 //goes LOW when player presses switch
Dim green As PORTE.0
Dim red_1 As PORTE.1
Dim red_2 As PORTE.3
Dim Shift_led As PORTA.0 //SHIFT LED
Dim blue1 As PORTA.1
Dim blue2 As PORTA.2
Dim yellow1 As PORTA.3
Dim yellow2 As PORTA.4
Dim YELLOW3 As PORTA.5
//Dim S_press As PORTC.0 //SHIFT BUTTON
Dim x As Byte //USED FOR SHIFT POINTS
Dim RT_1 As LongWord //REACTION TIME player 1
Dim RT_2 As LongWord //REACTION TIME player 2
Dim ET_1 As LongWord //elasped time player 1
Dim ET_2 As LongWord //elasped time player 2
Dim Start_Time_1 As Word
Dim Start_Time_2 As Word
Dim End_Time_1 As Word
Dim End_Time_2 As Word
Dim timer1 As Word
Dim timer2 As Word
//Const
//Timer1 = 0,
// Timer2 = 1
Sub Int_Timer()
Timer.Initialize(1)
Timer.Items(0).interval=1 //ms
Timer.Items(0).OnTimer=@OnTimer //timer event handler
//enable timers
Timer.Items(0).enabled=true
If GO_1=0 Then //insert this into all the sub sequences but only last key in sequence
Timer.Stop //need to insert GETKEY
End If
End Sub
//RED LIGHT FOUL
Sub Foul()
If GO_1=0 And green = 0 Then
red_1=1
WriteAt(1,1,"FOUL" )
DelayMS(3000)
blue1=0 //led is off
blue2=0
yellow1=0
yellow2=0
YELLOW3=0
green=0
red_1=0
Cls
EndIf
End Sub
// OnTimer event, flash LED...
Sub OnTimer()
Inc(mS)
End Sub
Sub ET_time() //dispay results
Timer.Stop //stop timer
Cls
s=DecToStr(timer1/1000)+"."+DecToStr((timer1 Mod 1000))
WriteAt(1,1,"timer1 ") //display players score
WriteAt(2,1,"seconds ",s," ")
s=DecToStr(timer2/1000)+"."+DecToStr((timer2 Mod 1000))
WriteAt(3,1,"timer2 ") //display players score
WriteAt(4,1,"seconds ",s," ")
// EE.Write(6,RT_1)
// EE.Write(6,RT_1)
DelayMS(5000)
Cls
End Sub
Sub End_of_game()
blue1=0 //led is off
blue2=0
yellow1=0
yellow2=0
YELLOW3=0
green=0
red_1=0
DelayMS(2000)
End Sub
mS=0
timer1=mS
timer2=mS
Start_Time_1=mS
Start_Time_2=mS
End_Time_1=mS
End_Time_2=mS
Output(Shift_led)
Output (blue1)
Output(blue2)
Output(yellow1)
Output(yellow2)
Output(YELLOW3)
Output (green)
Output(red_1)
Input(GO_1) //button press
//Input(S_press)//shift button
//GO_1 = 1 //input
blue1=0 //led
blue2=0 //led
green = 0 //led
mS=0 //timer set to zero
//initialize timer
Timer.Initialize(2)
Timer.Items(1).interval=1 //ms
Timer.Items(1).OnTimer=@OnTimer //timer event handler
Timer.Items(2).interval=1 //ms
//enable timers
Timer.Items(0).enabled=true
Timer.Items(1).enabled=true
'mS = 0
'Timer.Start()
SetAllDigital
//START OF GAME
While True
DelayMS(1000)
blue1=1 //first stage light
If GO_1=0 And green=0
GoTo skipcode //skipcode is a foul start
DelayMS(1000)
blue2=1
If GO_1=0 And green=0
GoTo skipcode
DelayMS(1000)
yellow1=1
If GO_1=0 And green=0
GoTo skipcode
DelayMS(500)
yellow2=1
If GO_1=0 And green=0
GoTo skipcode
DelayMS(500)
YELLOW3=1
If GO_1=0 And green=0
GoTo skipcode
DelayMS(500)
If GO_1=0 And green = 0 //Then //green = 0
GoTo skipcode
DelayMS(200)
mS=0
'Repeat
green=1 //start race
timer1=0
timer2=0
Timer.Start
' Until
if GO_1=0 Then //press of GO_x button
timer1=mS
EndIf
if go_2=0 then
timer2=mS
endif
End_Time_1=
End_Time_2=mS
ET_1=(End_Time_1-Start_Time_1)
ET_2=(End_Time_2-Start_Time_2)
ET_time() //display time
//mS=0
skipcode:
Foul()
End_of_game()
Wend