| CODE |
'Stopwatch Routine - by Rob Reeder 'Started 10/20/02 Dim Hours As Byte , Mins As Byte , Secs As Byte , Huns As Byte , Thous As Byte Dim Hourss As Byte , Minss As Byte , Secss As Byte , Hunss As Byte , Thouss As Byte Dim Tick As Byte , Ikey As Byte , Ik As Byte Dim B1flag As Byte , B2flag As Byte , Running As Byte , Lap As Byte Hours = 0 Mins = 0 Secs = 0 Huns = 0 Thous = 0 Running = 1 B1flag = 0 B2flag = 0 'Use Compare1a value to trim to accuracy -- Calibration Compare1a = 10000 - 13 Timer1 = 0 Config Timer1 = Timer , Prescale = 1 On Compare1 Stopwatch Nosave Enable Compare1a Enable Interrupts Print "Stopwatch Program" Print "Press Button 1 to Start/Stop" Print "Press Button 2 to Lap/Reset" 'Button 1 is INT0 'Button 2 is INT1 Home Cls Waitms 2 Cursor Off Upperline Lcd "Stopwatch Prog." Loop1: Home : Lowerline If Lap = 0 Then Gosub Snap If Hourss < 10 Then Lcd "0"; Lcd Hourss; ":"; If Minss < 10 Then Lcd "0"; Lcd Minss; ":"; If Secss < 10 Then Lcd "0"; Lcd Secss; "."; If Hunss < 10 Then Lcd "0"; Lcd Hunss; Thouss; Loop2: Ikey = Inkey() If Ikey = 0 Then Goto Nookey Print Chr(ikey) If Ikey = "s" Then If Running = 0 Then Running = 1 Else Running = 0 End If Goto Nookey End If If Ikey = "l" Then If Lap = 0 Then Lap = 1 Else Lap = 0 End If Goto Nookey End If If Ikey = "r" Then Hours = 0 Mins = 0 Secs = 0 Huns = 0 Thous = 0 Running = 0 Goto Nookey Else Print " Stopwatch" Print "S Start/Stop" Print "L Lap" Print "R Reset" End If Nookey: Goto Loop1 Snap: Disable Interrupts $asm lds r31,{Thous} sts {Thouss},r31 lds r31,{Huns} sts {Hunss},r31 lds r31,{Secs} sts {Secss},r31 lds r31,{Mins} sts {Minss},r31 lds r31,{Hours} sts {Hourss},r31 $end Asm Enable Interrupts Return 'Interrupt Routines Stopwatch: 'r31, r30, and sreg are changed. This routine driven by Timer0 $asm push r31 in r31,sreg push r31 clr r31 Out Tcnt1h , R31 Out Tcnt1l , R31 lds r31,{running} or r31,r31 breq jret lds r31,{Thous} inc r31 sts {Thous},r31 Subi R31,10 brne Jret sts {Thous},r31 lds r31,{Huns} inc r31 sts {Huns},r31 subi r31,100 brne Jret sts {Huns},r31 lds r31,{Secs} inc r31 sts {secs},r31 subi r31,60 brne Jret sts {secs},r31 lds r31,{mins} inc r31 sts {mins},r31 subi r31,60 brne Jret sts {mins},r31 lds r31,{hours} inc r31 sts {hours},r31 subi r31,100 brne Jret sts {hours},r31 Jret: pop r31 Out Sreg , R31 pop r31 $end Asm Return End |