'----------------------------------
' Running Hour
'
' OUTPUT : LCD 2X16
'----------------------------------
$regfile = "m16def.dat"
$crystal = 16000000
Dim Jam As Word , Menit As Byte , Detik As Byte
Dim J_set As Word , M_set As Byte , D_set As Byte
Dim Menu As Byte , F_start As Byte , F_scan As Byte , F_led As Byte
Config Timer1 = Timer , Prescale = 256
Portd.0 = 1
Portd.1 = 1
Portd.2 = 1
Portd.3 = 1
Portd.4 = 1
Portd.5 = 0
Ddrd.0 = 0
Ddrd.1 = 0
Ddrd.2 = 0
Ddrd.3 = 0
Ddrd.4 = 0
Ddrd.5 = 1 ' Led
On Timer1 Interupsi_timer1
Enable Ovf1
Config Lcdpin = Pin , Db4 = Portb.3 , Db5 = Portb.4 , Db6 = Portb.5 , Db7 = Portb.6 , E = Portb.2 , Rs = Portb.1
Config Lcd = 16 * 2
Cursor Off
Cls
Lcd " Running Hour "
Lowerline
Lcd " Timer Controll "
Wait 2
Cls
Lcd "Hour :"
Lowerline
Lcd "Sett :"
Timer1 = 3035
Restart:
'------baca nilai awal timer---
Readeeprom Jam , 5
Readeeprom Menit , 7
Readeeprom Detik , 8
If Jam = &HFFFF Then Jam = 0
If Menit = &HFF Then Menit = 0
If Detik = &HFF Then Detik = 0
Locate 1 , 7
If Jam < 10 Then
Lcd "000" ; Jam ; ":"
Elseif Jam < 100 Then
Lcd "00" ; Jam ; ":"
Elseif Jam < 1000 Then
Lcd "0" ; Jam ; ":"
End If
If Menit < 10 Then
Lcd "0" ; Menit ; ":"
Else
Lcd Menit ; ":"
End If
If Detik < 10 Then
Lcd "0" ; Detik
Else
Lcd Detik
End If
'-------------------------------
'------baca nilai awal set time---
Readeeprom J_set , 1
Readeeprom M_set , 3
Readeeprom D_set , 4
If J_set = &HFFFF Then J_set = 0
If M_set = &HFF Then M_set = 0
If D_set = &HFF Then D_set = 0
Locate 2 , 7
If J_set < 10 Then
Lcd "000" ; J_set ; ":"
Elseif J_set < 100 Then
Lcd "00" ; J_set ; ":"
Elseif J_set < 1000 Then
Lcd "0" ; J_set ; ":"
End If
If M_set < 10 Then
Lcd "0" ; M_set ; ":"
Else
Lcd M_set ; ":"
End If
If D_set < 10 Then
Lcd "0" ; D_set
Else
Lcd D_set
End If
'-------------------------------
F_scan = 1
Gosub Scan_tombol
Do
Locate 1 , 7
If Jam < 10 Then
Lcd "000" ; Jam ; ":"
Elseif Jam < 100 Then
Lcd "00" ; Jam ; ":"
Elseif Jam < 1000 Then
Lcd "0" ; Jam ; ":"
End If
'---------
If Menit < 10 Then
Lcd "0" ; Menit ; ":"
Else
Lcd Menit ; ":"
End If
'---------
If Detik < 10 Then
Lcd "0" ; Detik
Else
Lcd Detik
End If
Gosub Scan_tombol
'----control
If Jam >= J_set And Menit >= M_set And Detik >= D_set Then
'Portd.5 = 1
F_led = 1
End If
Loop
End
'----------------------
Scan_tombol:
Do
'UP
If Pind.0 = 0 Then
If Menu = 1 And J_set < 9999 Then
Incr J_set
Locate 2 , 7
If J_set < 10 Then
Lcd "000" ; J_set ; ":"
Elseif J_set < 100 Then
Lcd "00" ; J_set ; ":"
Elseif J_set < 1000 Then
Lcd "0" ; J_set ; ":"
End If
Elseif Menu = 2 And M_set < 59 Then
Incr M_set
Locate 2 , 12
If M_set < 10 Then
Lcd "0" ; M_set ; ":"
Else
Lcd M_set ; ":"
End If
Elseif Menu = 3 And D_set < 59 Then
Incr D_set
Locate 2 , 15
If D_set < 10 Then
Lcd "0" ; D_set
Else
Lcd D_set
End If
End If
Waitms 250
'DOWN
Elseif Pind.1 = 0 Then
If Menu = 1 And J_set > 0 Then
Decr J_set
Locate 2 , 7
If J_set < 10 Then
Lcd "000" ; J_set ; ":"
Elseif J_set < 100 Then
Lcd "00" ; J_set ; ":"
Elseif J_set < 1000 Then
Lcd "0" ; J_set ; ":"
End If
Elseif Menu = 2 And M_set > 0 Then
Decr M_set
Locate 2 , 12
If M_set < 10 Then
Lcd "0" ; M_set ; ":"
Else
Lcd M_set ; ":"
End If
Elseif Menu = 3 And D_set > 0 Then
Decr D_set
Locate 2 , 15
If D_set < 10 Then
Lcd "0" ; D_set
Else
Lcd D_set
End If
End If
Waitms 250
'OK
Elseif Pind.2 = 0 Then
If Menu = 0 Then
Menu = 1
Elseif Menu = 1 Then
Menu = 2
Writeeeprom J_set , 1
Elseif Menu = 2 Then
Menu = 3
Writeeeprom M_set , 3
Elseif Menu = 3 Then
Menu = 0
Writeeeprom D_set , 4
End If
Waitms 250
'START
Elseif Pind.4 = 0 And F_start = 0 Then
Start Timer1
Enable Interrupts
F_start = 1
F_scan = 0
Waitms 250
'STOP/PAUSE
Elseif Pind.4 = 1 And F_start = 1 Then
Stop Timer1
Disable Interrupts
F_start = 0
F_scan = 0
Waitms 250
'RESET
Elseif Pind.3 = 0 Then
Menu = 0
Jam = 0
Menit = 0
Detik = 0
J_set = 0
M_set = 0
D_set = 0
F_led = 0
Writeeeprom J_set , 1
Writeeeprom M_set , 3
Writeeeprom D_set , 4
Writeeeprom Jam , 5
Writeeeprom Menit , 7
Writeeeprom Detik , 8
Waitms 250
Goto Restart
End If
Loop Until F_scan = 0
Return
Interupsi_timer1:
Stop Timer1
Detik = Detik + 1
Writeeeprom Detik , 8
If Detik >= 60 Then
Menit = Menit + 1
Writeeeprom Menit , 7
If Menit >= 60 Then
Jam = Jam + 1
Writeeeprom Jam , 5
If Jam >= 9999 Then
Jam = 0
Menit = 0
Detik = 0
Writeeeprom Jam , 5
Writeeeprom Menit , 7
Writeeeprom Detik , 8
End If
Menit = 0
End If
Detik = 0
End If
Timer1 = 3035
Start Timer1
If F_led = 1 Then Portd.5 = Not Portd.5
Return