$regfile = "m8adef.dat" $crystal = 12000000 Config Lcd = 16 * 2
'MIKROKONTROLER YANG DI GUNAKAN TYPE ATMEGA8A 'CRSTAL YANG DI PAKAI 12MHZ 'KONFIGURASI LCD YANG DI GUNAKAN 16x2
Config Lcdpin = Pin , Db4 = Portb.4 , Db5 = Portb.3 , Db6 = Portb.2 , Db7 = Portb.1 , E = Portb.5 , Rs = Portc.0 Cursor Off Noblink
'MATIKAN KRUSOR LCD DAN KRUSOR TIDAK BERKEDIP
Config Scl = Portc.2 Config Sda = Portc.5 '------------------------------------------------------------------------------Declare Sub Baca_rtcc Declare Sub Tulis_rtcc Declare Sub Tampil_display Declare Sub Tampil_hari Declare Sub Beep Declare Sub Keypad Declare Sub Empat Declare Sub Lima Declare Sub Enam Declare Sub Set_jam Declare Sub Set_tanggal Declare Sub Set_on Declare Sub Set_off Declare Sub Akan_off Declare Sub Akan_on '------------------------------------------------------------------------------Sqw Alias Pinc.1
Config Portc.1 = Input Buzer Alias Portc.4 Relay_out Alias Portb.0 Config Relay_out = Output Config Buzer = Output Buzer = 1 Waitms 100 Buzer = 0 'DEKLARASI KEYPAD 4X4
Baris1 Alias Portd.0 Config Portd.0 = Output Baris2 Alias Portd.1 Config Portd.1 = Output Baris3 Alias Portd.2 Config Portd.2 = Output Baris4 Alias Portd.3 Config Portd.3 = Output Kolom1 Alias Pind.4 Ddrd.4 = 0 Portd.4 = 1 Kolom2 Alias Pind.5 Ddrd.5 = 0 Portd.5 = 1 Kolom3 Alias Pind.6
Ddrd.6 = 0 Portd.6 = 1 Kolom4 Alias Pind.7 Ddrd.7 = 0 Portd.7 = 1 '------------------------------------------------------------------------------Const Baca_rtc = &HD1 Const Tulis_rtc = &HD0 '------------------------------------------------------------------------------Dim Jam As Byte , Menit As Byte , Detik As Byte Dim Hari As Byte , Tanggal As Byte , Bulan As Byte , Tahun As Byte Dim Key As Byte , Jam_on As Byte , Jam_off As Byte Dim Menit_on As Byte , Menit_off As Byte , Relay As Bit '############################################################################### 'PROGRAM UTAMA '############################################################################### Cls
'clear lcd
Readeeprom Jam_on , 1
'baca nilai jam on yang di simpan di eprom
Readeeprom Jam_off , 2
'baca nilai jam off yang di simpan di eprom
Readeeprom Menit_on , 3
'baca nilai menit on yang di simpan di eprom
Readeeprom Menit_off , 4
'baca nilai menit off yang di simpan di eprom
Do Utama: Call Baca_rtcc
'baca rtc(jam,menit ,tanggal dsb)
Call Tampil_display
'tampilkan display lcd
While Sqw = 0
'ulangi terus jika sqw=0
Call Keypad
'panggil sub rutin keypad
If Key = "A" Then Call Set_jam If Key = "B" Then Call Set_tanggal
'jika A di tekan panggil set tanggal 'jika B di tekan panggil set tanggal
If Key = "C" Then Call Set_on
'jika C di tekan panggil set on
If Key = "D" Then Call Set_off
'jika D di tekan panggil set off
Wend Call Tampil_display
'tampilkan ke display lcd
While Sqw = 1
'ulangi terus jika sqw=1
Call Keypad
'panggil sub rutin keypad
If Key = "A" Then Call Set_jam If Key = "B" Then Call Set_tanggal
'jika A di tekan panggil set tanggal 'jika B di tekan panggil set tanggal
If Key = "C" Then Call Set_on
'jika C di tekan panggil set on
If Key = "D" Then Call Set_off
'jika D di tekan panggil set off
Wend If Jam_on < Jam_off Then If Jam = Jam_on Then Call Akan_on
'PANGGIL MENIT AKAN ON
If Jam = Jam_off Then Call Akan_off
'PANGGIL MENIT AKAN OFF
If Jam < Jam_on Then Relay = 0 If Jam > Jam_on Then If Jam < Jam_off Then Relay = 1 If Jam > Jam_off Then Relay = 0 End If End If
If Jam_on > Jam_off Then If Jam = Jam_off Then Call Akan_off
'PANGGIL MENIT AKAN OFF
If Jam = Jam_on Then Call Akan_on
'PANGGIL MENIT AKAN On
If Jam < Jam_off Then Relay = 1 If Jam > Jam_off Then If Jam < Jam_on Then Relay = 0 If Jam > Jam_on Then Relay = 1 End If
End If If Jam_on = Jam_off Then If Menit_on > Menit_off Then If Menit < Menit_off Then Relay = 1 If Menit = Menit_off Then Relay = 0 If Menit > Menit_off Then If Menit = Menit_on Then Relay = 1 If Menit > Menit_on Then Relay = 1 If Menit < Menit_on Then Relay = 0 End If Else If Menit < Menit_on Then Relay = 0 If Menit = Menit_on Then Relay = 1 If Menit > Menit_on Then If Menit = Menit_off Then Relay = 0 If Menit > Menit_off Then Relay = 0
If Menit < Menit_off Then Relay = 1 End If End If If Menit_on = Menit_off Then Relay = 1 End If Relay_out = Relay Loop
'ULANGI LAGI DARI DO/AWAL SAMPAI CATUDAYA DI MATIKAN
'############################################################################### 'END PROGRAM UTAMA '############################################################################### Sub Akan_on If Menit >= Menit_on Then Relay = 1 Else Relay = 0 End If End Sub Sub Akan_off If Menit >= Menit_off Then Relay = 0 Else Relay = 1 End If End Sub
'############################################################################### Sub Beep Buzer = 1
'HIDUPKAN BUZER
Waitms 100 Buzer = 0
'TUNGGU 100MS 'MATIKAN BUZER
End Sub Sub Keypad Key = &HFF 'scan baris 1
'
Reset Baris1 Waitms 1 If Kolom1 = 0 Then Key = 1 Call Beep
'isi key dengan 'panggil hidupkan buzer
Bitwait Kolom1 , Set End If If Kolom2 = 0 Then Key = 2 Call Beep
'isi key dengan 'panggil hidupkan buzer
Bitwait Kolom2 , Set End If If Kolom3 = 0 Then Key = 3 Call Beep Bitwait Kolom3 , Set
'isi key dengan 'panggil hidupkan buzer
End If If Kolom4 = 0 Then Key = "A"
'isi key dengan
Call Beep
'panggil hidupkan buzer
Bitwait Kolom4 , Set End If 'Scan Baris 2 Set Baris1 Reset Baris2 Waitms 1 If Kolom1 = 0 Then Key = 4 Call Beep
'isi key dengan 'panggil hidupkan buzer
Bitwait Kolom1 , Set End If If Kolom2 = 0 Then Key = 5 Call Beep
'isi key dengan 'panggil hidupkan buzer
Bitwait Kolom2 , Set End If If Kolom3 = 0 Then Key = 6 Call Beep Bitwait Kolom3 , Set End If
'isi key dengan 'panggil hidupkan buzer
If Kolom4 = 0 Then Key = "B"
'isi key dengan
Call Beep
'panggil hidupkan buzer
Bitwait Kolom4 , Set End If Set Baris2 'scan baris 3 Reset Baris3 Waitms 1 If Kolom1 = 0 Then Key = 7 Call Beep
'isi key dengan 'panggil hidupkan buzer
Bitwait Kolom1 , Set End If If Kolom2 = 0 Then Key = 8 Call Beep
'isi key dengan 'panggil hidupkan buzer
Bitwait Kolom2 , Set End If
If Kolom3 = 0 Then Key = 9 Call Beep Bitwait Kolom3 , Set End If
'isi key dengan 'panggil hidupkan buzer
If Kolom4 = 0 Then Key = "C"
'isi key dengan
Call Beep
'panggil hidupkan buzer
Bitwait Kolom4 , Set End If Set Baris3 'scan baris 4 Reset Baris4 Waitms 1 If Kolom1 = 0 Then Key = "*"
'isi key dengan
Call Beep
'panggil hidupkan buzer
Bitwait Kolom1 , Set End If If Kolom2 = 0 Then Key = 0 Call Beep
'isi key dengan 'panggil hidupkan buzer
Bitwait Kolom2 , Set End If If Kolom3 = 0 Then Key = "#"
'isi key dengan
Call Beep
'panggil hidupkan buzer
Bitwait Kolom3 , Set End If If Kolom4 = 0 Then
Key = "D"
'isi key dengan
Call Beep
'panggil hidupkan buzer
Bitwait Kolom4 , Set End If Set Baris4 End Sub '############################################################################### Sub Tampil_display Upperline
' SETING KRUSOR KE ATAS
Call Tampil_hari If Sqw = 0 Then Lcd "," ; Bcd(jam) ; " " ; Bcd(menit) ; " " ; Bcd(detik) ; " " Else Lcd "," ; Bcd(jam) ; ":" ; Bcd(menit) ; ":" ; Bcd(detik) ; " " End If Lowerline
'SETTING CRUSOR LCD KE BAWAH
Lcd Bcd(tanggal) ; "/" ; Bcd(bulan) ; "/20" ; Bcd(tahun) Locate 2 , 14 If Relay = 1 Then Lcd "ON " Else Lcd "OFF"
'JIKA RELAY =1 'TAMPILKAN KE LCD ON 'JIKA BUKAN 1 'TAMPILKAN KE LCD OFF
End If End Sub '-------------------------------------------------------------------------------
Sub Tampil_hari Select Case Hari Case 1 : Lcd "MINGGU"
'JIKA HARI =1 TAMPILKAN KE LCD MINGGU
Case 2 : Lcd "SENIN"
'JIKA HARI =2 TAMPILKAN KE LCD SENIN
Case 3 : Lcd "SELASA"
'JIKA HARI =3 TAMPILKAN KE LCD SELASA
Case 4 : Lcd "RABU"
'JIKA HARI =4 TAMPILKAN KE LCD RABU
Case 5 : Lcd "KAMIS"
'JIKA HARI =5 TAMPILKAN KE LCD KAMIS
Case 6 : Lcd "JUM'AT"
'JIKA HARI =6 TAMPILKAN KE LCD JUM'AT
Case 7 : Lcd "SABTU"
'JIKA HARI =7 TAMPILKAN KE LCD SABTU
End Select End Sub '############################################################################### Sub Baca_rtcc I2cstart I2cwbyte Tulis_rtc I2cwbyte 0 I2cstart I2cwbyte Baca_rtc I2crbyte Detik , Ack I2crbyte Menit , Ack I2crbyte Jam , Ack I2crbyte Hari , Ack I2crbyte Tanggal , Ack I2crbyte Bulan , Ack I2crbyte Tahun , Nack
I2cstop End Sub '############################################################################### Sub Tulis_rtcc I2cstart I2cwbyte Tulis_rtc I2cwbyte 0 I2cwbyte Detik I2cwbyte Menit I2cwbyte Jam I2cwbyte Hari I2cwbyte Tanggal I2cwbyte Bulan I2cwbyte Tahun I2cwbyte &H10
'control
I2cstop End Sub '############################################################################### Sub Set_on Cls Upperline
'CLEAR LCD ' SETING KRUSOR KE ATAS
Lcd "SET ON" Do Call Keypad Lowerline
'SETTING CRUSOR LCD KE BAWAH
If Sqw = 0 Then Lcd " " Else Lcd Bcd(jam_on) End If Lcd ":" ; Bcd(menit_on) If Key = "C" Then Exit Do If Key >= 0 And Key <= 9 Then Shift Jam_on , Left , 4 Jam_on = Jam_on Or Key End If Loop Jam_on = Makedec(jam_on) If Jam_on > 23 Then Jam_on = 23 Jam_on = Makebcd(jam_on) 'set menit Do Call Keypad Lowerline Lcd Bcd(jam_on) ; ":" If Sqw = 0 Then Lcd " " Else Lcd Bcd(menit_on) End If
'SETTING CRUSOR LCD KE BAWAH
If Key = "C" Then Exit Do If Key >= 0 And Key <= 9 Then Shift Menit_on , Left , 4 Menit_on = Menit_on Or Key End If Loop Menit_on = Makedec(menit_on) If Menit_on > 59 Then Menit_on = 59 Menit_on = Makebcd(menit_on)
Writeeeprom Jam_on , 1 Writeeeprom Jam_off , 2 Writeeeprom Menit_on , 3 Writeeeprom Menit_off , 4 End Sub '############################################################################### Sub Set_off Cls Upperline
'CLEAR LCD ' SETING KRUSOR KE ATAS
Lcd "SET OFF" Do Call Keypad Lowerline If Sqw = 0 Then Lcd " "
'SETTING CRUSOR LCD KE BAWAH
Else Lcd Bcd(jam_off) End If Lcd ":" ; Bcd(menit_off) If Key = "D" Then Exit Do If Key >= 0 And Key <= 9 Then Shift Jam_off , Left , 4 Jam_off = Jam_off Or Key End If Loop Jam_off = Makedec(jam_off) If Jam_off > 23 Then Jam_off = 23 Jam_off = Makebcd(jam_off) 'set menit Do Call Keypad Lowerline Lcd Bcd(jam_off) ; ":" If Sqw = 0 Then Lcd " " Else Lcd Bcd(menit_off) End If If Key = "D" Then Exit Do If Key >= 0 And Key <= 9 Then
Shift Menit_off , Left , 4 Menit_off = Menit_off Or Key End If Loop Menit_off = Makedec(menit_off) If Menit_off > 59 Then Menit_off = 59 Menit_off = Makebcd(menit_off) Writeeeprom Jam_on , 1 Writeeeprom Jam_off , 2 Writeeeprom Menit_on , 3 Writeeeprom Menit_off , 4 End Sub '------------------------------------------------------------------------------Sub Enam Lcd "
"
End Sub Sub Lima Lcd "
"
End Sub Sub Empat Lcd " " End Sub '############################################################################### Sub Set_jam Cls
'CLEAR LCD
Call Baca_rtcc Upperline
' SETING KRUSOR KE ATAS
Lcd "SET JAM" 'set hari Do Call Keypad If Key > 0 And Key < 8 Then Hari = Key Lowerline
'JIKA YANG DI TEKAN ANGKA 1 SAMPAI 7 'SETTING CRUSOR LCD KE BAWAH
If Sqw = 0 Then Select Case Hari Case 1 : Call Enam Case 2 : Call Lima Case 3 : Call Enam Case 4 : Call Empat Case 5 : Call Lima Case 6 : Call Enam Case 7 : Call Lima End Select Else Call Tampil_hari End If Lcd "," ; Bcd(jam) ; ":" ; Bcd(menit) ; ":" ; Bcd(detik) ; " " '------------------------------------------------------------------------------If Key = "A" Then Exit Do
End If Loop 'set jam Do Call Keypad Lowerline
'SETTING CRUSOR LCD KE BAWAH
Call Tampil_hari Lcd "," If Sqw = 0 Then Lcd " " Else Lcd Bcd(jam) End If Lcd ":" ; Bcd(menit) ; ":" ; Bcd(detik) ; " " If Key = "A" Then Exit Do If Key >= 0 And Key <= 9 Then Shift Jam , Left , 4 Jam = Jam Or Key End If Loop Jam = Makedec(jam) If Jam > 23 Then Jam = 23 Jam = Makebcd(jam) 'set menit Do
'JIKA YANG DI TEKAN ANGKA 0 SAMPAI 9
Call Keypad Lowerline
'SETTING CRUSOR LCD KE BAWAH
Call Tampil_hari Lcd "," ; Bcd(jam) ; ":" If Sqw = 0 Then Lcd " " Else Lcd Bcd(menit) End If Lcd ":" ; Bcd(detik) ; " " If Key = "A" Then Exit Do If Key >= 0 And Key <= 9 Then
'JIKA YANG DI TEKAN ANGKA 0 SAMPAI 9
Shift Menit , Left , 4 Menit = Menit Or Key End If Loop Menit = Makedec(menit) If Menit > 59 Then Menit = 59 Menit = Makebcd(menit) 'set detik Do Call Keypad Lowerline
'SETTING CRUSOR LCD KE BAWAH
Call Tampil_hari Lcd "," ; Bcd(jam) ; ":" ; Bcd(menit) ; ":"
If Sqw = 0 Then Lcd " " ; " " Else Lcd Bcd(detik) End If Lcd " " If Key = "A" Then Exit Do If Key >= 0 And Key <= 9 Then
'JIKA YANG DI TEKAN ANGKA 0 SAMPAI 9
Shift Detik , Left , 4 Detik = Detik Or Key End If Loop Detik = Makedec(detik) If Detik > 59 Then Detik = 59 Detik = Makebcd(detik) Call Tulis_rtcc Cls
'CLEAR LCD
End Sub '############################################################################### Sub Set_tanggal Cls
'CLEAR LCD
Call Baca_rtcc Upperline Lcd "SET TANGGAL" 'set tanggal
' SETING KRUSOR KE ATAS
Do Call Keypad Lowerline
'SETTING CRUSOR LCD KE BAWAH
If Sqw = 0 Then Lcd " " Else Lcd Bcd(tanggal) End If Lcd "/" ; Bcd(bulan) ; "/20" ; Bcd(tahun) If Key = "B" Then Exit Do If Key >= 0 And Key <= 9 Then
'JIKA YANG DI TEKAN ANGKA 0 SAMPAI 9
Shift Tanggal , Left , 4 Tanggal = Tanggal Or Key End If Loop Tanggal = Makedec(tanggal) If Tanggal > 31 Then Tanggal = 31 Tanggal = Makebcd(tanggal) 'set bulan Do Call Keypad Lowerline Lcd Bcd(tanggal) ; "/" If Sqw = 0 Then Lcd " "
'SETTING CRUSOR LCD KE BAWAH
Else Lcd Bcd(bulan) ; End If Lcd "/20" ; Bcd(tahun) If Key = "B" Then Exit Do If Key >= 0 And Key <= 9 Then
'JIKA YANG DI TEKAN ANGKA 0 SAMPAI 9
Shift Bulan , Left , 4 Bulan = Bulan Or Key End If Loop Bulan = Makedec(bulan) If Bulan > 12 Then Bulan = 12 Bulan = Makebcd(bulan) 'set tahun Do Call Keypad Lowerline
'SETTING CRUSOR LCD KE BAWAH
Lcd Bcd(tanggal) ; "/" ; Bcd(bulan) ; "/" If Sqw = 0 Then Lcd " " Else Lcd "20" ; Bcd(tahun) End If If Key = "B" Then Exit Do If Key >= 0 And Key <= 9 Then
'JIKA YANG DI TEKAN ANGKA 0 SAMPAI 9
Shift Tahun , Left , 4 Tahun = Tahun Or Key End If Loop Call Tulis_rtcc Cls
'TULIS SEMUA DATA YANG SUDAH DI SETTING KE RTC 'CLEAR LCD
End Sub '############################################################################### '-------------------------------------------------------------------------------