Advertisement  

Wednesday, 24 July 2019
     
 
Main Menu
Home Home
Shop Shop
News News
BASCOM-AVR BASCOM-AVR
BASCOM-8051 BASCOM-8051
Products Products
Application Notes Application Notes
Publications Publications
Links Links
Support Center Support Center
Downloads Downloads
Forum Forum
Resellers Resellers
Contact Us Contact Us
Updates Updates
MCS Wiki MCS Wiki
Online Help
BASCOM-AVR Help BASCOM-AVR Help
BASCOM-8051 Help BASCOM-8051 Help
Contents in Cart
Show Cart
Your Cart is currently empty.
Search the Shop

Products Search

User Login
Username

Password

If you have problem after log in with disappeared login data, please press F5 in your browser

RSS News
 
     
 

 
   
     
 
AN #13 - Keyboard decoder Print
Keyboard decoder - by Mike Gill

Download source code in .ZIP file

' Reads a standard 3X4 keypad and assembles No in Digits variable, then displays
' Led used is just to show program running 2K2 from port pin via Led to +
' Setup for 89S8252. Use appropriate port assignments for other processors
' Uses Active Low, so no extra components needed. Chip internal tieups are utilised
' Mike Gill . B M Electronics UK 01422 839321

Startup
:
Config DeBounce = 40 ' Set Key Pad Debounce to 40 Ms
Config Lcd = 16 * 1
Cursor OFF
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'OUTPUTS All Active High
StatusLed
Alias P2.7 ' Operational Status
Col1
Alias P2.6 ' Keyboard Column Drivers
Col2
Alias P2.5
Col3
Alias P2.4 ' Add Another Col for 4X4 Kpad
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'INITIAL OUTPUT STATES
StatusLed
= 1
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'INPUTS All Active Low
Row1
Alias P2.0 ' Keyboard Rows (Read)
Row2
Alias P2.1
Row3
Alias P2.2
Row4
Alias P2.3
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'VARIABLES
Dim Check As Byte ' Detects Key Released
Dim KeyRead As Byte ' Actual Button Value
Dim Digits As Word ' Actual Dialled Number
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'INITIALISE VARIABLES
Digits
= 0
KeyRead
= 0
Check
= 0
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
KeyScan
: ' Keypad Read Routine (Assignments can be changed for different connections)
StatusLed
= 0 ' Status Led OFF
Col1
= 0 : Col2 = 1 : Col3 = 1 ' Turns Columns On (Low) 1 by 1
KeyRead
= 1 : DeBounce Row1,0,GotKey,Sub ' Gosub if Key Pressed
(Reads LOW Input)
KeyRead
= 4 : DeBounce Row2,0,GotKey,Sub
KeyRead
= 7 : DeBounce Row3,0,GotKey,Sub
KeyRead
= 11 : DeBounce Row4,0,GotKey,Sub ' CALL Button *
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Col1
= 1 : Col2 = 0 : Col3 = 1 ' Assign KeyRead to Any No You Like <256
KeyRead
= 2 : DeBounce Row1,0,GotKey,Sub
KeyRead
= 5 : DeBounce Row2,0,GotKey,Sub
KeyRead
= 8 : DeBounce Row3,0,GotKey,Sub
KeyRead
= 0 : DeBounce Row4,0,GotKey,Sub
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Col1
= 1 : Col2 = 1 : Col3 = 0 ' Add Another Section After this for 4X4 Kpad
KeyRead
= 3 : DeBounce Row1,0,GotKey,Sub
KeyRead
= 6 : DeBounce Row2,0,GotKey,Sub
KeyRead
= 9 : DeBounce Row3,0,GotKey,Sub
KeyRead
= 12 : DeBounce Row4,0,GotKey,Sub ' CANCEL Button #
WaitMs 50 ' Status Led OFF Time
StatusLed
= 1 ' Turns Status Led ON
WaitMs 15 ' Status Led ON Time (Only to show Program Running)
Goto KeyScan
End
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
GotKey
:
CheckAgain
: ' Reads P2 Directly and Waits for all Keys Released
Check
= P2 And 15 ' Appropriate Port
If Check <> 15 Then : Goto CheckAgain : End If ' Check for Key Release
If Keyread = 12 Then : Goto StartUp : End If ' CANCEL Button
If Keyread = 11 Then : Goto CallNumber : End If ' CALL Button
Digits
= Digits * 10 ' Assemble Dialling No in Digits Variable
Digits
= Digits + Keyread
Cls : Lcd Digits ' Display Accumulating Number
KeyRead
= 0 ' Clear Keypad Read Variables
Check
= 0
Return
End
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

CallNumber
: ' What You Like Here. When call key pressed
Goto StartUp