Hi,
we all know matrix keyboard. Two types are most common: 3x4 and 4x4. The numbers indicate number of keypads on the keyboard. Most of them are connected as matrix.
I have attached keyboards from the photo directly to MiniPin dev. board (which is by the way Arduino compatible), no resistors were used.
In Bascom help you can find a nice command: Getkbd() and it's nicely documented but... Read more if interested..
But the problem with keyboard and the sample program is, that we get only one number when we press the keypad. In real life we'd need a series of numbers which would make our application alive.
I have made a small sample program, I think that it's simple enough and that all will understand it. Program accepts pressed numbers and makes out of them a "row of numbers" that can be used as an "entry code". On LCD you will see that typed code will be displayed in the second row and when we press #, then the typed code will be transfered to the Keyb1 variable. You can delete entire row of numbers (in case you made a mistake during typing) if you press * keypad. After you pressed # the set of numbers will appear on the LCD. In case you want to delete them, press *. It will clear LCD and set variable Keyb1 to 0.
'program that demonstrates inrterface to 3x4 and 4x4 matrix foil keyboard
'3x4 connects to the port with PortX.7 unconnected
'4x4 connects to the port so that PortX.0 is connected to 1st. keyboard connection
$regfile = "m32def.DAT"
$crystal = 8000000
Config Lcd = 16x2
Config Lcdpin = Pin , Db4 = Portb.4 , Db5 = Portb.5 , Db6 = Portb.6 , Db7 = Portb.7 , E = Portb.2 , Rs = Portb.1
Cursor Off
'#######################################################################
Dim Keyb1 As Long
Dim B As Byte
Dim X As Byte
Dim Num As Byte
'############################################################################################################
Config Kbd = Portc
'############################################################################################################
Cls
Keyb1 = 0
Do
B = Getkbd()
Upperline
Lcd "Keyb " ; Keyb1 ;
Gosub Keyboard_sub
Loop
End
'########################################################################
Keyboard_sub:
B = Getkbd()
If B = 11 Then Return
If B = 3 Then 'keypad * erases variable and LCD
Keyb1 = 0
Cls
Return
End If
If B < 16 Then
Do
X = Getkbd()
Num = Lookup(x , Dta)
If Num < 16 And Num <> 11 Then
If Num = 15 Then 'keypad * erases last digit
Keyb1 = Keyb1 / 10
Goto Tukaj
End If
Keyb1 = Keyb1 * 10
Keyb1 = Keyb1 + Num
Tukaj:
Locate 2 , 1
Lcd Keyb1 ; " " 'display of all numbers that were entered
Else
Select Case Num
Case 65 To 68 : Locate 2 , 7
Lcd Chr(num) 'display of A to D characters
End Select
End If
Waitms 300
Loop Until X = 11 'keypad # functions as ENTER
End If
Return
'########################################################################
Dta:
Data 1 , 4 , 7 , 15
Data 2 , 5 , 8 , 0
Data 3 , 6 , 9 , 11
Data 65 , 66 , 67 , 68