$regfile = "M16DEF.dat" : $crystal = 1000000
Config Lcdpin = Pin , Db4 = Pinc.3 , Db5 = Pinc.2 , Db6 = Pinc.1 , Db7 = Pinc.0 , E = Pinc.4 , Rs = Pinc.5
Config Lcd = 16 * 2 : Cursor Off : Cls
Dim Cc As Byte , Mm As Byte , Ss As Byte , Sectic As Byte , F As Byte , W As Word
Gosub Showcc : Gosub Showmm : Gosub Showss
Config Timer2 = Timer , Prescale = 32 , Async = On
Enable Interrupts : Enable Timer2 : On Timer2 Sectic
Sw_s Alias Pind.0 : Sw_i Alias Pind.1 : Sw_d Alias Pind.2
Star:
F = 0 : Start Timer2
Do
Debounce Sw_s , 1 , Cc
Loop
'===============================================================================
Sectic:
Incr Sectic
Select Case Sectic
Case 1:
Gosub Offlcd
Case 2:
Ss = Ss + 1 : Toggle Portd.7
If Ss > 59 Then : Ss = 0 : Mm = Mm + 1
End If
If Mm > 59 Then : Mm = 0 : Cc = Cc + 1
End If
If Cc > 23 Then : Cc = 0
End If
Gosub Onlcd
Case 3:
Gosub Offlcd
Case 4:
Gosub Onlcd : Sectic = 0
End Select
Locate 2 , 22
Return
'===============================================================================
Cc:
F = 2
Do
Debounce Sw_s , 1 , Mm
Debounce Sw_i , 1 , Cc1
Debounce Sw_d , 1 , Cc2
Loop
Cc1:
Incr Cc : If Cc > 23 Then Cc = 0
Gosub Showcc : Goto Cc
Cc2:
Decr Cc : If Cc > 23 Then Cc = 23
Gosub Showcc : Goto Cc
'-------------------------------------------------------------------------------
Mm:
F = 3 : Gosub Showcc
Do
Debounce Sw_s , 1 , Ss
Debounce Sw_i , 1 , Mm1
Debounce Sw_d , 1 , Mm2
Loop
Mm1:
Incr Mm : If Mm > 59 Then Mm = 0
Gosub Showmm : Goto Mm
Mm2:
Decr Mm : If Mm > 59 Then Mm = 59
Gosub Showmm : Goto Mm
'-------------------------------------------------------------------------------
Ss:
F = 4 : Gosub Showmm : Gosub Showss
Do
Debounce Sw_s , 1 , Star
Debounce Sw_i , 1 , Ss1
Debounce Sw_d , 1 , Ss2
Loop
Ss1:
Timer2 = 0 : Sectic = 0
If Ss > 29 Then : Mm = Mm + 1
End If
If Mm = 60 Then : Mm = 0 : Incr Cc
End If
If Cc = 24 Then Cc = 0
Ss = 0 : Goto Ss
Ss2:
Timer2 = 0 : Ss = 0 : Sectic = 0 : Goto Ss
'===============================================================================
Onlcd:
Gosub Showcc : Gosub Showmm : Gosub Showss
Return
'-------------------------------------------------------------------------------
Offlcd:
If F = 0 Then : Return
Elseif F = 2 Then : Locate 1 , 1 : Lcd " "
Elseif F = 3 Then : Locate 1 , 4 : Lcd " "
Elseif F = 4 Then : Locate 1 , 7 : Lcd " "
End If
Return
'-------------------------------------------------------------------------------
Showcc:
Home
If Cc < 10 Then : Lcd " " ; Cc
Else : Lcd Cc
End If
Lcd ":"
Return
Showmm:
Locate 1 , 4
If Mm < 10 Then : Lcd "0" ; Mm
Else : Lcd Mm
End If
Lcd ":"
Return
Showss:
Locate 1 , 7
If Ss < 10 Then : Lcd "0" ; Ss
Else : Lcd Ss
End If
Lcd " "
Return