⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 keyboard 4x3.bas

📁 Bascom 8051 program for matrix keyboard 4X3 keys
💻 BAS
字号:

' 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 otherprocessors
' 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 * 2
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 KeyRelease
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

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -