文档介绍:一、键盘
矩阵式键盘
判别是否有键按下:
JugeKeyPressed:
CLR A
MOV P1,#0FFH
ANL P1,#00001111B ;列线低电平,判断行线是否有低电平
MOV A,P1
ORL A,#11110000B
CPL A ;A=0说明无键按下,A≠0说明有键按下
RET
消抖判键:
JugekeyBoard: LCALL JugeKeyPressed
JZ JugeKeyEnd ;如果A不为0,有键按下
LCALL Delay10ms ;去抖动
LCALL JugeKeyPressed ;再次判断有无键按下
JZ JugeKeyEnd
SETB KeyPressed ;设置键盘按下标志
JugeKeyEnd: RET
识别键值:
JugeWhichKey: MOV ScanTimes,#04H
MOV A,#11101111B ;
ScanLoop: ORL P1,#11111111B
ANL P1,A ;
MOV WhichCol,A
MOV A,P1
MOV InputedKey,A ;存储输入键值
ORL A ,#11110000B
CPL A ;,则a≠0
JZ ScanNextRow ; ,继续下一列
LJMP Keycode
ScanNextRow: MOV A,WhichCol
RL A
MOV WhichCol,A ;逐列置低电平
DJNZ ScanTimes,ScanLoop
CLR KeyPressed ;四列循环完毕后认为没有键按下
LJMP JugeKeyOver
按键
键值
按键
键值
S1
7E
S9
7B
S2
BE
S10
BB
S3
DE
S11
DB
S4
EE
S12
EB
S5
7D
S13
77
S6
BD
S14
B7
S7
DD
S15
D7
S8
ED
S16
E7
Keycode:MOV A,InputedKey
CJNE A,#7EH,Not01
MOV InputedKey,#01H
LJMP JugeKeyOver
Not01: CJNE A,#0BEH,Not02
MOV InputedKey,#02H
LJMP JugeKeyOver
Not02: CJNE A,#0DEH,Not03
MOV InputedKey,#03H
LJMP JugeKeyOver
Not03: CJNE A,#0EEH,NotOrder
SETB OrderKeyPressed
LJMP JugeKeyOver
NotOrder: CJNE A,#7DH,Not04
MOV InputedKey,#04H
LJMP JugeKeyOver
Not04: CJNE A,#0BDH,Not05
MOV InputedKey,#05H
LJMP JugeKeyOver
Not05: CJNE A,#0DDH,Not06
MOV InputedKey,#06H
LJMP JugeKeyOver
Not06: CJNE A,#0EDH,NotFun
SETB FunKeyPressed
LJMP JugeKeyOver
NotFun: CJNE A,#7BH,Not07
MOV InputedKey,#07H
LJMP JugeKeyOver
Not07: CJNE A,#0BBH,Not08
MOV InputedKey,#08H
LJMP JugeKeyOver
Not08: CJNE A,#0DBH,Not09
MOV InputedKey,#09H
LJMP JugeKeyOver
Not09: CJNE A,#0EBH,NotEnter
SETB EnterKeyPressed
JMP JugeKeyOver
NotEnter:CJNE A,#77H,Not00
MOV InputedKey,#00H
LJMP JugeKeyOver
Not00: CJNE A,#0B7H,NotUp
SETB UpKeypressed
LJMP JugeKeyOver
NotUp: CJNE A,#0D7H,NotDown
SETB DownKeyPressed
LJMP JugeKeyOver
NotDown: CJNE A,#0E7H,InputFail
SETB ExitKeyPressed
LJMP JugeKeyOver
InputFail: SETB K