AKSES KEYPAD MATRIK 4X4

ini adalah rangkaian keypad matrik 4x4 tapi blm sesempurna yang diharapakan. maklum ane baru blajar heheh
jika temen2 dah mumpuni ilmunya n cakranya bagi2 yooo :)



 source code:

$regfile = "m8535.dat"
$crystal = 12000000
$baud = 9600

Config Lcd = 20 * 4
Config Lcdpin = Pin , Db4 = Porta.4 , Db5 = Porta.5 , Db6 = Porta.6 , Db7 = Porta.7
Config Lcdpin = Pin , Rs = Porta.2 , E = Porta.3
Cursor Off
Const Debouncetime = 150
Config Pind.6 = Output
Config Pind.2 = Input

Config Int0 = Falling
Dim Garuda As String * 8
Dim Wtime As Byte
Dim Keycoderow As Byte
Dim Keycodecol As Byte
Dim Keycode As Byte
Dim Keychar As String * 1
Dim A As String * 2

On Int0 Button
'set upper nibble of portb to output, lower to input
Ddrb = &B11110000
Portb = &B00001111
Wtime = 255

Print "ready..."
Enable Interrupts
Enable Int0

Do
  Set Portd.6
  Waitms Wtime
  Reset Portd.6
  Waitms Wtime

Loop

Button:

'Disable Interrupts

  Waitms Debouncetime
  Keycoderow = Pinb
  Ddrb = &B11110000
  Portb = &B00001111
  Waitms 1
  Keycodecol = Pinb
  Ddrb = &B00001111
  Portb = &B11110000

Shift Keycoderow , Right , 4
Select Case Keycoderow
    Case 14 : Keycode = 1
    Case 13 : Keycode = 4
    Case 11 : Keycode = 7
    Case 7 : Keycode = 10
End Select

Select Case Keycodecol
    Case 14 : Keycode = Keycode + 0
    Case 13 : Keycode = Keycode + 1
    Case 11 : Keycode = Keycode + 2
    Case 7 : Keycode = Keycode + 20
End Select


If Keycode = 10 Then Goto A
If Keycode = 11 Then Goto B
'If Keycode = 24 Then Goto C
If Keycode = 12 Then Goto C
'If Keycode = 27 Then Goto D
If Keycode = 30 Then Goto D

  'illegal keycode from bounce effects

   Keychar = Lookupstr(keycode , Keycodes)
  Print Keychar

  Lcd Keychar
  Gifr = 64


'Enable Interrupts
Return
End


Keycodes:
Data "" , "1" , "4" , "7" , "2" , "5" , "8" , "3" , "6" ,
Data "9" , "A" , "B" , "C" , "R" , "0" , "E" , "D" , "*"


untuk cara pembacaan keypad ti posting berikutnya yooo... semoga bermanfaat.
Diberdayakan oleh Blogger.