Berikut ini saya beri contoh program untuk entri data menggunakan keypad 4x4 dengan tampilan LCD, contohnya adalah untuk memasukkan password, kemudian data password yang telah di inputkan dari keypad disimpan pada EEPROM internal mikrokontroler yang merupakan media penyimpanan non-volatile, sehingga meskipun power supply dimatikan data tetap tersimpan.
Simulasinya dengan Proteus:
Jika ingin mencobanya dengan proteus, tanda (+) pada keypad adalah sebagai input data password.
Listing programnya dengan Bascom AVR:
'=========================================================
'Programmer: Wahyu Rahmaniar
'Company : Technologination
'
'LCD dan Keypad 4x4
'=========================================================
'Company : Technologination
'
'LCD dan Keypad 4x4
'=========================================================
$regfile = "m8535.dat"
$crystal = 8000000
Config Lcdpin = Pin , Db4 = Portc.4 , Db5 = Portc.5 , Db6 = Portc.6 , Db7 = Portc.7 , E = Portd.3 , Rs = Portd.2
Config Lcd = 16 * 2
Declare Sub Keypad
Declare Sub Entri_data
Dim Urut As Byte
Dim Kode As Byte
Dim Flag As Bit
Dim I As Word
Dim Nilai As Long
Dim Angka As Integer
Dim Pass As Integer
Dim Simpan_pass As Eram Integer 'variabel untuk EEPROM
Config Portc = Output
Ddrb = &B11110000
Portb = &HFF
Cls
Cursor Off
Locate 1 , 2
Lcd "LCD dan Keypad"
Locate 2 , 3
Lcd "Tekan Tombol"
Waitms 200
Gosub Keypad
Pass = 0
Mulai:
Pass = Simpan_pass
Do
Lcd "Password(+)= ";
Lowerline
Lcd Pass
Wait 1
Cls
Loop
End
'Baca Keypad
$crystal = 8000000
Config Lcdpin = Pin , Db4 = Portc.4 , Db5 = Portc.5 , Db6 = Portc.6 , Db7 = Portc.7 , E = Portd.3 , Rs = Portd.2
Config Lcd = 16 * 2
Declare Sub Keypad
Declare Sub Entri_data
Dim Urut As Byte
Dim Kode As Byte
Dim Flag As Bit
Dim I As Word
Dim Nilai As Long
Dim Angka As Integer
Dim Pass As Integer
Dim Simpan_pass As Eram Integer 'variabel untuk EEPROM
Config Portc = Output
Ddrb = &B11110000
Portb = &HFF
Cls
Cursor Off
Locate 1 , 2
Lcd "LCD dan Keypad"
Locate 2 , 3
Lcd "Tekan Tombol"
Waitms 200
Gosub Keypad
Pass = 0
Mulai:
Pass = Simpan_pass
Do
Lcd "Password(+)= ";
Lowerline
Lcd Pass
Wait 1
Cls
Loop
End
'Baca Keypad
Sub Keypad()
Kode = 0
Urut = 0
Flag = 0
I = 0
Do
For I = 0 To 20000
'KOLOM 1
Portb = &B11101111
If Pinb.0 = 0 Then
Angka = 1
Gosub Entri_data
Waitms 200
Elseif Pinb.1 = 0 Then
Angka = 4
Gosub Entri_data
Waitms 200
Elseif Pinb.2 = 0 Then
Angka = 7
Gosub Entri_data
Waitms 200
Elseif Pinb.3 = 0 Then
Cls
Waitms 200
End If
'KOLOM 2
Portb = &B11011111
If Pinb.0 = 0 Then
Angka = 2
Gosub Entri_data
Waitms 200
Elseif Pinb.1 = 0 Then
Angka = 5
Gosub Entri_data
Waitms 200
Elseif Pinb.2 = 0 Then
Angka = 8
Gosub Entri_data
Waitms 200
Elseif Pinb.3 = 0 Then
Angka = 0
Gosub Entri_data
Waitms 200
End If
'KOLOM 3
Portb = &B10111111
If Pinb.0 = 0 Then
Angka = 3
Gosub Entri_data
Waitms 200
Elseif Pinb.1 = 0 Then
Angka = 6
Gosub Entri_data
Waitms 200
Elseif Pinb.2 = 0 Then
Angka = 9
Gosub Entri_data
Waitms 200
Elseif Pinb.3 = 0 Then
Flag = 0
I = 19000
Kode = 0
Goto Mulai
Waitms 200
Cursor Blink
End If
'KOLOM 4
Portb = &B01111111
If Pinb.0 = 0 Then
Waitms 200
Elseif Pinb.1 = 0 Then
Waitms 200
Elseif Pinb.2 = 0 Then
Waitms 200
Elseif Pinb.3 = 0 Then
Kode = 1
Flag = 1
Cls
Cursor Blink
Cursor On
Locate 1 , 1
Lcd "Data Password:"
Locate 2 , 1
Cursor Blink
Cursor On
Waitms 200
End If
Waitus 200
Next
Loop Until Flag = 0
End Sub
'Entri Data
Kode = 0
Urut = 0
Flag = 0
I = 0
Do
For I = 0 To 20000
'KOLOM 1
Portb = &B11101111
If Pinb.0 = 0 Then
Angka = 1
Gosub Entri_data
Waitms 200
Elseif Pinb.1 = 0 Then
Angka = 4
Gosub Entri_data
Waitms 200
Elseif Pinb.2 = 0 Then
Angka = 7
Gosub Entri_data
Waitms 200
Elseif Pinb.3 = 0 Then
Cls
Waitms 200
End If
'KOLOM 2
Portb = &B11011111
If Pinb.0 = 0 Then
Angka = 2
Gosub Entri_data
Waitms 200
Elseif Pinb.1 = 0 Then
Angka = 5
Gosub Entri_data
Waitms 200
Elseif Pinb.2 = 0 Then
Angka = 8
Gosub Entri_data
Waitms 200
Elseif Pinb.3 = 0 Then
Angka = 0
Gosub Entri_data
Waitms 200
End If
'KOLOM 3
Portb = &B10111111
If Pinb.0 = 0 Then
Angka = 3
Gosub Entri_data
Waitms 200
Elseif Pinb.1 = 0 Then
Angka = 6
Gosub Entri_data
Waitms 200
Elseif Pinb.2 = 0 Then
Angka = 9
Gosub Entri_data
Waitms 200
Elseif Pinb.3 = 0 Then
Flag = 0
I = 19000
Kode = 0
Goto Mulai
Waitms 200
Cursor Blink
End If
'KOLOM 4
Portb = &B01111111
If Pinb.0 = 0 Then
Waitms 200
Elseif Pinb.1 = 0 Then
Waitms 200
Elseif Pinb.2 = 0 Then
Waitms 200
Elseif Pinb.3 = 0 Then
Kode = 1
Flag = 1
Cls
Cursor Blink
Cursor On
Locate 1 , 1
Lcd "Data Password:"
Locate 2 , 1
Cursor Blink
Cursor On
Waitms 200
End If
Waitus 200
Next
Loop Until Flag = 0
End Sub
'Entri Data
Sub Entri_data()
Incr Urut
Select Case Urut
Case 1 : Nilai = Angka
Lcd Angka
Case 2 : Nilai = Nilai * 10
Nilai = Nilai + Angka
Lcd Angka
Pass = Nilai
Case 3 : Nilai = Nilai * 10
Nilai = Nilai + Angka
Lcd Angka
Pass = Nilai
Case 4 : Nilai = Nilai * 10
Nilai = Nilai + Angka
Lcd Angka
Pass = Nilai
Case 5 : Nilai = Nilai * 10
Nilai = Nilai + Angka
Lcd Angka
Urut = 0
Locate 2 , 1
Pass = Nilai
Simpan_pass = Pass
End Select
End Sub
Incr Urut
Select Case Urut
Case 1 : Nilai = Angka
Lcd Angka
Case 2 : Nilai = Nilai * 10
Nilai = Nilai + Angka
Lcd Angka
Pass = Nilai
Case 3 : Nilai = Nilai * 10
Nilai = Nilai + Angka
Lcd Angka
Pass = Nilai
Case 4 : Nilai = Nilai * 10
Nilai = Nilai + Angka
Lcd Angka
Pass = Nilai
Case 5 : Nilai = Nilai * 10
Nilai = Nilai + Angka
Lcd Angka
Urut = 0
Locate 2 , 1
Pass = Nilai
Simpan_pass = Pass
End Select
End Sub
atau download simulasi LCD dan Keypad 4x4 dan source code nya.
Tempat Jual Komponen dan Elektronik.
-ayuchan-