$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
Dim Cc1 As Byte , Mm1 As Byte , Cc2 As Byte , Mm2 As Byte , Day As Word
Dim Cc3 As Byte , Mm3 As Byte , Cc4 As Byte , Mm4 As Byte
Gosub Showcc : Gosub Showmm : Gosub Showss
Config Timer2 = Timer , Prescale = 32 , Async = On
Enable Interrupts : Enable Timer2 : On Timer2 Sectic
Ddrd = &B11000000 : Portd = 7
Sw_s Alias Pind.0 : Sw_i Alias Pind.1 : Sw_d Alias Pind.2
Led Alias Pind.6
'===============================================================================
Star:
F = 0 : Start Timer2 : Home L : Lcd " "
Do
Debounce Sw_s , 0 , Ant
Loop
Ant:
For W = 0 To 1000
If Sw_s = 1 Then Goto Cc1
Waitms 1
Next
Goto Cc
'===============================================================================
Sectic:
Incr Sectic
Select Case Sectic
Case 1:
Gosub Offlcd
Case 2:
Ss = Ss + 1
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 : Incr Day
End If
Gosub Onlcd
Case 3:
Gosub Offlcd
If Ss = 0 Then :
If Cc1 = Cc And Mm1 = Mm Then : Set Led
Elseif Cc2 = Cc And Mm2 = Mm Then : Reset Led
Elseif Cc3 = Cc And Mm3 = Mm Then : Set Led
Elseif Cc4 = Cc And Mm4 = Mm Then : Reset Led
End If
End If
Case 4:
Gosub Onlcd : Sectic = 0
End Select
Locate 2 , 22
Return
'===============================================================================
Cc:
F = 2
Do
Debounce Sw_s , 0 , Mm
Debounce Sw_i , 0 , Cci
Debounce Sw_d , 0 , Ccd
Loop
Cci:
Incr Cc : If Cc > 23 Then Cc = 0
Gosub Showcc : Goto Cc
Ccd:
Decr Cc : If Cc > 23 Then Cc = 23
Gosub Showcc : Goto Cc
'-------------------------------------------------------------------------------
Mm:
F = 3 : Gosub Showcc
Do
Debounce Sw_s , 0 , Ss
Debounce Sw_i , 0 , Mmi
Debounce Sw_d , 0 , Mmd
Loop
Mmi:
Incr Mm : If Mm > 59 Then Mm = 0
Gosub Showmm : Goto Mm
Mmd:
Decr Mm : If Mm > 59 Then Mm = 59
Gosub Showmm : Goto Mm
'-------------------------------------------------------------------------------
Ss:
F = 4 : Gosub Showmm : Gosub Showss
Do
Debounce Sw_s , 0 , Star
Debounce Sw_i , 0 , Ssi
Debounce Sw_d , 0 , Ssd
Loop
Ssi:
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
Ssd:
Timer2 = 0 : Ss = 0 : Sectic = 0 : Goto Ss
'===============================================================================
Cc1:
F = 11 : Home L : Lcd "TIME ON1= "
Do
Debounce Sw_s , 0 , Mm1
Debounce Sw_i , 0 , Cc1i
Debounce Sw_d , 0 , Cc1d
Loop
Cc1i:
Incr Cc1 : If Cc1 > 23 Then Cc1 = 0
Gosub Showcc1 : Goto Cc1
Cc1d:
Decr Cc1 : If Cc1 > 23 Then Cc1 = 23
Gosub Showcc1 : Goto Cc1
'-------------------------------------------------------------------------------
Mm1:
F = 12 : Gosub Showcc1
Do
Debounce Sw_s , 0 , Cc2
Debounce Sw_i , 0 , Mm1i
Debounce Sw_d , 0 , Mm1d
Loop
Mm1i:
Incr Mm1 : If Mm1 > 59 Then Mm1 = 0
Gosub Showmm1 : Goto Mm1
Mm1d:
Decr Mm1 : If Mm1 > 59 Then Mm1 = 59
Gosub Showmm1 : Goto Mm1
'-------------------------------------------------------------------------------
Cc2:
F = 15 : Home L : Lcd "TIME OFF1= "
Do
Debounce Sw_s , 0 , Mm2
Debounce Sw_i , 0 , Cc2i
Debounce Sw_d , 0 , Cc2d
Loop
Cc2i:
Incr Cc2 : If Cc2 > 23 Then Cc2 = 0
Gosub Showcc2 : Goto Cc2
Cc2d:
Decr Cc2 : If Cc2 > 23 Then Cc2 = 23
Gosub Showcc2 : Goto Cc2
'-------------------------------------------------------------------------------
Mm2:
F = 16 : Gosub Showcc2
Do
Debounce Sw_s , 0 , Cc3
Debounce Sw_i , 0 , Mm2i
Debounce Sw_d , 0 , Mm2d
Loop
Mm2i:
Incr Mm2 : If Mm2 > 59 Then Mm2 = 0
Gosub Showmm2 : Goto Mm2
Mm2d:
Decr Mm2 : If Mm2 > 59 Then Mm2 = 59
Gosub Showmm2 : Goto Mm2
'-------------------------------------------------------------------------------
Cc3:
F = 21 : Home L : Lcd "TIME ON2= "
Do
Debounce Sw_s , 0 , Mm3
Debounce Sw_i , 0 , Cc3i
Debounce Sw_d , 0 , Cc3d
Loop
Cc3i:
Incr Cc3 : If Cc3 > 23 Then Cc3 = 0
Gosub Showcc3 : Goto Cc3
Cc3d:
Decr Cc3 : If Cc3 > 23 Then Cc3 = 23
Gosub Showcc3 : Goto Cc3
'-------------------------------------------------------------------------------
Mm3:
F = 22 : Gosub Showcc3
Do
Debounce Sw_s , 0 , Cc4
Debounce Sw_i , 0 , Mm3i
Debounce Sw_d , 0 , Mm3d
Loop
Mm3i:
Incr Mm3 : If Mm3 > 59 Then Mm3 = 0
Gosub Showmm3 : Goto Mm3
Mm3d:
Decr Mm3 : If Mm3 > 59 Then Mm3 = 59
Gosub Showmm3 : Goto Mm3
'-------------------------------------------------------------------------------
Cc4:
F = 25 : Home L : Lcd "TIME OFF2= "
Do
Debounce Sw_s , 0 , Mm4
Debounce Sw_i , 0 , Cc4i
Debounce Sw_d , 0 , Cc4d
Loop
Cc4i:
Incr Cc4 : If Cc4 > 23 Then Cc4 = 0
Gosub Showcc4 : Goto Cc4
Cc4d:
Decr Cc4 : If Cc4 > 23 Then Cc4 = 23
Gosub Showcc4 : Goto Cc4
'-------------------------------------------------------------------------------
Mm4:
F = 26 : Gosub Showcc4
Do
Debounce Sw_s , 0 , Star
Debounce Sw_i , 0 , Mm4i
Debounce Sw_d , 0 , Mm4d
Loop
Mm4i:
Incr Mm4 : If Mm4 > 59 Then Mm4 = 0
Gosub Showmm4 : Goto Mm4
Mm4d:
Decr Mm4 : If Mm4 > 59 Then Mm4 = 59
Gosub Showmm4 : Goto Mm4
'===============================================================================
Onlcd:
Gosub Showcc : Gosub Showmm : Gosub Showss : Gosub Showday
If F = 0 Then : Return
Elseif F = 11 Or F = 12 Then : Gosub Showcc1 : Gosub Showmm1
Elseif F = 15 Or F = 16 Then : Gosub Showcc2 : Gosub Showmm2
Elseif F = 21 Or F = 22 Then : Gosub Showcc3 : Gosub Showmm3
Elseif F = 25 Or F = 26 Then : Gosub Showcc4 : Gosub Showmm4
End If
Return
'-------------------------------------------------------------------------------
Offlcd:
Toggle Portd.7
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 " "
Elseif F = 11 Or F = 15 Or F = 21 Or F = 25 Then : Locate 2 , 12 : Lcd " "
Elseif F = 12 Or F = 16 Or F = 22 Or F = 26 Then : Locate 2 , 15 : 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 " "
Showday:
Locate 1 , 12 : Lcd Day ; " "
Return
'-------------------------------------------------------------------------------
Showcc1:
Locate 2 , 12
If Cc1 < 10 Then : Lcd " " ; Cc1
Else : Lcd Cc1
End If
Lcd ":"
Return
Showmm1:
Locate 2 , 15
If Mm1 < 10 Then : Lcd "0" ; Mm1
Else : Lcd Mm1
End If
Return
'-------------------------------------------------------------------------------
Showcc2:
Locate 2 , 12
If Cc2 < 10 Then : Lcd " " ; Cc2
Else : Lcd Cc2
End If
Lcd ":"
Return
Showmm2:
Locate 2 , 15
If Mm2 < 10 Then : Lcd "0" ; Mm2
Else : Lcd Mm2
End If
Return
'-------------------------------------------------------------------------------
Showcc3:
Locate 2 , 12
If Cc3 < 10 Then : Lcd " " ; Cc3
Else : Lcd Cc3
End If
Lcd ":"
Return
Showmm3:
Locate 2 , 15
If Mm3 < 10 Then : Lcd "0" ; Mm3
Else : Lcd Mm3
End If
Return
'-------------------------------------------------------------------------------
Showcc4:
Locate 2 , 12
If Cc4 < 10 Then : Lcd " " ; Cc4
Else : Lcd Cc4
End If
Lcd ":"
Return
Showmm4:
Locate 2 , 15
If Mm4 < 10 Then : Lcd "0" ; Mm4
Else : Lcd Mm4
End If
Return
'===============================================================================