Source Code BASCOM For DI-Smart KEY4X4 Input (KEYPAD 4X4)

‘Dalam bentuk PDF download di sini

$regfile = “m16def.dat”
$crystal = 11059200

‘Inisialisasi Port LCD:
$lib “lcd4busy.lbx”
Const _lcdport = Portb
Const _lcdddr = Ddrb
Const _lcdin = Pinb
Const _lcd_e = 2
Const _lcd_rw = 1
Const _lcd_rs = 0
Config Lcd = 16 * 2

Cursor Off
Cursor Noblink
Cls

‘Inisialisasi Port Keypad:
Port_keypad Alias Portc
Pin_keypad Alias Pinc
Ddr_keypad Alias Ddrc

Port_keypad = 255
Ddr_keypad = &B1111_0000

K0 Alias Pin_keypad.0
K1 Alias Pin_keypad.1
K2 Alias Pin_keypad.2
K3 Alias Pin_keypad.3
B0 Alias Port_keypad.4
B1 Alias Port_keypad.5
B2 Alias Port_keypad.6
B3 Alias Port_keypad.7

Declare Sub Keyup
Declare Function Getkey() As Byte
Dim Digit As Byte

Cls

Lcd “tes key”
Do
Keyup
Do
Digit = Getkey();
If Digit <> “$” Then
‘==================================================
‘==================================================
‘Di sini letak program utamanya:
If Digit = “#” Then
Cls
Exit Do
Else

Lcd Chr(digit)
Exit Do
End If

‘==================================================
‘==================================================

End If
Loop
Loop

Sub Keyup
B0 = 0
B1 = 0
B2 = 0
B3 = 0

Do
Waitms 10
If K1 = 1 And K2 = 1 And K3 = 1 And K0 = 1 Then Exit Do
Loop
End Sub
Function Getkey() As Byte
B0 = 1 : B1 = 1 : B2 = 1 : B3 = 1
Getkey = “$”
B0 = 0
If K0 = 0 Then
Getkey = “1”
Elseif K1 = 0 Then
Getkey = “2”
Elseif K2 = 0 Then
Getkey = “3”
Elseif K3 = 0 Then
Getkey = “A”
End If

B0 = 1

B1 = 0
If K0 = 0 Then
Getkey = “4”
Elseif K1 = 0 Then
Getkey = “5”
Elseif K2 = 0 Then
Getkey = “6”
Elseif K3 = 0 Then
Getkey = “B”
End If

B1 = 1

B2 = 0
If K0 = 0 Then
Getkey = “7”
Elseif K1 = 0 Then
Getkey = “8”
Elseif K2 = 0 Then
Getkey = “9”
Elseif K3 = 0 Then
Getkey = “C”
End If

B2 = 1

B3 = 0
If K0 = 0 Then
Getkey = “*”
Elseif K1 = 0 Then
Getkey = “0”
Elseif K2 = 0 Then
Getkey = “#”
Elseif K3 = 0 Then
Getkey = “D”
End If

B3 = 1

End Function

Iklan

Tinggalkan Balasan

Please log in using one of these methods to post your comment:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s