کد:
$regfile = "M8DEF.dat" : $crystal = 2000000
Config Lcdpin = Pin , Db4 = Pinb.3 , Db5 = Pinb.2 , Db6 = Pinb.1 , Db7 = Pinb.0 , E = Pinb.4 , Rs = Pinb.5
Config Lcd = 16 * 2 : Cursor Off : Cls
Config Portd = &B11111000
Config Adc = Single , Prescaler = Auto , Reference = Internal
Deflcdchar 0 , 24 , 24 , 32 , 7 , 4 , 4 , 4 , 7 '.C
'-------------------------------------------------------------------------------
Dim Sal As Byte , Mah As Byte , Roz As Byte , B As Byte , F As Byte , T As Word
Dim Tt As Byte , S As Single , Days As Word , Eroz As Eram Byte
Dim Esal As Eram Byte At 5 , Emah As Eram Byte At 10 , Ft As Byte , W As Word
Dim A As Single , I As String * 8 , V As String * 8 , Fv As Byte
'-------------------------------------------------------------------------------
Sal = Esal : Mah = Emah : Roz = Eroz : Tt = 150
If Sal > 99 Then Sal = 10
If Mah > 12 Then Mah = 00
If Roz > 31 Then Roz = 1
Gosub Showsal : Gosub Showmah : Gosub Showroz
'-------------------------------------------------------------------------------
Config Timer2 = Timer , Prescale = 32 , Async = On
Enable Interrupts : Enable Timer2
On Timer2 Sectic
Start Timer2
'-------------------------------------------------------------------------------
'-------------------------------------------------------------------------------
Star:
F = 0 : Ft = 0
Do
Debounce Pind.0 , 1 , Ant
Loop
'-------------------------------------------------------------------------------
Ant:
For T = 0 To 1200
If Pind.0 = 0 Then Goto Star
Waitms 1
Next
Goto sal
'-------------------------------------------------------------------------------
'-------------------------------------------------------------------------------
Sectic:
Incr B
Select Case B
Case 1:
Start Adc : W = Getadc(1) : Stop Adc
If W > 800 Then : Fv = 1 : Set Portd.6 : Reset Portd.7
Else : S = W / 400 : S = S + 0.003 : V = Fusing(s , "#.###")
End If
Gosub Offlcd
Case 2:
Days = Days + 1 : Toggle Portd.3
If Days > 3599 Then :
Incr Roz : Eroz = Roz
End If
If Mah < 7 Then :
If Roz > 31 Then :
Roz = 1 : Eroz = Roz : Mah = Mah + 1 : Emah = Mah
End If
Elseif Mah < 13 Then :
If Roz > 30 Then :
Roz = 1 : Eroz = Roz : Mah = Mah + 1 : Emah = Mah
End If
Else :
Mah = 9
If Roz > 30 Then :
Roz = 1 : Eroz = Roz : Mah = Mah + 1 : Emah = Mah
End If
End If
If Mah > 12 Then :
Mah = 1 : Emah = Mah : Sal = Sal + 1 : Esal = Sal
End If
If Sal > 99 Then :
Sal = 0 : Esal = Sal
End If
Gosub Onlcd
If Fv = 1 Then :
Start Adc : W = Getadc(1) : Stop Adc
If W > 800 Then : Fv = 1 : Reset Portd.6 : Set Portd.7
Else : S = W / 40 : S = S + 0.03 : Fv = 0 : V = Fusing(s , "##.##")
End If
End If
Case 3:
Gosub Offlcd
Start Adc : W = Getadc(0) : Stop Adc : W = W / 2 : A = W / 2
If Fv = 1 Then :
Start Adc : W = Getadc(1) : Stop Adc
S = W / 4 : Fv = 0 : V = Fusing(s , "###.#")
End If
Case 4:
Start Adc : W = Getadc(2) : Stop Adc : S = W / 49.95 : I = Fusing(s , "#.###")
B = 0 : Gosub Onlcd : Toggle Portd.3 : Reset Portd.6 : Reset Portd.7 : Fv = 0
End Select
Locate 2 , 22
Return
'-------------------------------------------------------------------------------
'-------------------------------------------------------------------------------
sal:
F = 2 : Ft = 0
Do
Debounce Pind.0 , 1 , mah
Debounce Pind.1 , 1 , sal1
Debounce Pind.2 , 1 , sal2
Loop
'-------------------------------------------------------------------------------
sal1:
Incr Sal : If Sal > 99 Then Sal = 0
Gosub Showsal
For T = 0 To Tt
If Pind.1 = 0 Then Goto sal
Waitms 4
Next
Ft = 1
Do
Gosub Showsal
For T = 0 To Tt
If Pind.1 = 0 Then Goto sal
Waitms 1
Next
Incr Sal : If Sal > 99 Then Sal = 0
Gosub Showsal
Loop
'-------------------------------------------------------------------------------
sal2:
Decr Sal : If Sal > 99 Then Sal = 99
Gosub Showsal
For T = 0 To Tt
If Pind.2 = 0 Then Goto sal
Waitms 4
Next
Ft = 1
Do
Gosub Showsal
For T = 0 To Tt
If Pind.2 = 0 Then Goto sal
Waitms 1
Next
Decr Sal : If Sal > 99 Then Sal = 99
Gosub Showsal
Loop
'-------------------------------------------------------------------------------
'-------------------------------------------------------------------------------
mah:
F = 3 : Esal = sal : Ft = 0 : Gosub Showsal
Do
Debounce Pind.0 , 1 , roz
Debounce Pind.1 , 1 , mah1
Debounce Pind.2 , 1 , mah2
Loop
'-------------------------------------------------------------------------------
mah1:
Incr mah : If mah > 12 Then mah = 0
Gosub Showmah
For T = 0 To Tt
If Pind.1 = 0 Then Goto mah
Waitms 4
Next
Ft = 1
Do
Gosub Showmah
For T = 0 To Tt
If Pind.1 = 0 Then Goto mah
Waitms 1
Next
Incr mah : If mah > 12 Then mah = 0
Gosub Showmah
Loop
'-------------------------------------------------------------------------------
mah2:
Decr mah : If mah > 12 Then mah = 12
Gosub Showmah
For T = 0 To Tt
If Pind.2 = 0 Then Goto mah
Waitms 4
Next
Ft = 1
Do
Gosub Showmah
For T = 0 To Tt
If Pind.2 = 0 Then Goto mah
Waitms 1
Next
Decr mah : If mah > 12 Then mah = 12
Gosub Showmah
Loop
'-------------------------------------------------------------------------------
roz:
Ft = 0 : F = 4 : Emah = mah : Gosub Showmah : Gosub Showroz
Do
Debounce Pind.0 , 1 , Ended
Debounce Pind.1 , 1 , roz1
Debounce Pind.2 , 1 , roz2
Loop
Ended:
Days = 0 : Goto Star
'-------------------------------------------------------------------------------
Roz1:
Incr Roz
If Mah < 7 Then :
If Roz > 31 Then :
Roz = 1 : Eroz = Roz : Mah = Mah + 1 : Emah = Mah
End If
Elseif Mah < 13 Then :
If Roz > 30 Then :
Roz = 1 : Eroz = Roz : Mah = Mah + 1 : Emah = Mah
End If
Else :
Mah = 9
If Roz > 30 Then :
Roz = 1 : Eroz = Roz : Mah = Mah + 1 : Emah = Mah
End If
End If
Gosub Showroz
For T = 0 To Tt
If Pind.1 = 0 Then Goto roz
Waitms 4
Next
Ft = 1
Do
Gosub Showroz
For T = 0 To Tt
If Pind.1 = 0 Then Goto roz
Waitms 1
Next
Incr Roz
If Mah < 7 Then :
If Roz > 31 Then :
Roz = 1 : Eroz = Roz : Mah = Mah + 1 : Emah = Mah
End If
Elseif Mah < 13 Then :
If Roz > 30 Then :
Roz = 1 : Eroz = Roz : Mah = Mah + 1 : Emah = Mah
End If
Else :
Mah = 9
If Roz > 30 Then :
Roz = 1 : Eroz = Roz : Mah = Mah + 1 : Emah = Mah
End If
End If
Gosub Showroz
Loop
'-------------------------------------------------------------------------------
Roz2:
Decr Roz
If Mah < 7 Then :
If Roz > 31 Then :
Roz = 1 : Eroz = Roz : Mah = Mah + 1 : Emah = Mah
End If
Elseif Mah < 13 Then :
If Roz > 30 Then :
Roz = 1 : Eroz = Roz : Mah = Mah + 1 : Emah = Mah
End If
Else :
Mah = 9
If Roz > 30 Then :
Roz = 1 : Eroz = Roz : Mah = Mah + 1 : Emah = Mah
End If
End If
Gosub Showroz
For T = 0 To Tt
If Pind.2 = 0 Then Goto roz
Waitms 4
Next
Ft = 1
Do
Gosub Showroz
For T = 0 To Tt
If Pind.2 = 0 Then Goto roz
Waitms 1
Next
Decr Roz
If Mah < 7 Then :
If Roz > 31 Then :
Roz = 1 : Eroz = Roz : Mah = Mah + 1 : Emah = Mah
End If
Elseif Mah < 13 Then :
If Roz > 30 Then :
Roz = 1 : Eroz = Roz : Mah = Mah + 1 : Emah = Mah
End If
Else :
Mah = 9
If Roz > 30 Then :
Roz = 1 : Eroz = Roz : Mah = Mah + 1 : Emah = Mah
End If
End If
Gosub Showroz
Loop
'-------------------------------------------------------------------------------
'-------------------------------------------------------------------------------
Onlcd:
Gosub Showsal : Gosub Showmah : Gosub Showroz : Gosub Showa : Gosub Showi
Return
'-------------------------------------------------------------------------------
Offlcd:
If Ft = 1 Then Return
If F = 0 Then : Return
Else :
If F = 2 Then : Home : Lcd " "
Elseif F = 3 Then : Locate 1 , 4 : Lcd " "
Else :
If F = 4 Then : Locate 1 , 7 : Lcd " "
End If
End If
End If
Return
'-------------------------------------------------------------------------------
'-------------------------------------------------------------------------------
Showa:
Locate 1 , 12
If A < 10 Then : Lcd " " ; A ; Chr(0) ; " "
Else : Lcd A ; Chr(0) ; " "
End If
Return
'-------------------------------------------------------------------------------
Showsal:
Home
If sal < 10 Then : Lcd " " ; sal
Else : Lcd sal
End If
Lcd "/"
Return
'-------------------------------------------------------------------------------
Showmah:
Locate 1 , 4
If mah < 10 Then : Lcd "0" ; mah
Else : Lcd mah
End If
Lcd "/"
Return
'-------------------------------------------------------------------------------
Showroz:
Locate 1 , 7
If roz < 10 Then : Lcd "0" ; roz
Else : Lcd roz
End If
Lcd " "
Return
'-------------------------------------------------------------------------------
Showi:
Home L : Lcd V ; "V "
Locate 2 , 10 : Lcd I ; "A "
Return
'-------------------------------------------------------------------------------
'-------------------------------------------------------------------------------