做了一个矩阵键盘程序,要求是当按下对应的键时数码管显示对应的数值0到F,问题在按下按键时数码管无反应
ORG 0000H
AJMP MAIN
NOP
MAIN: LCALL KEY
LCALL DIS
AJMP MAIN
KEY: LCALL KEYY //调扫描键盘
JNZ KEY1 //有键按下转KEY1
LCALL DEL
AJMP MAIN
KEY1: LCALL DEL //去抖
LCALL KEYY //再检测
JZ MAIN //无键按下转回主程序
KEY0: JNZ KEY0 //等待释放按键
CPL A
MOV R3,A
LCALL KEY2
KEYY: MOV P1,#0FH
MOV A,P1
MOV 30H,A
MOV P1,#0F0H
MOV A,P1
MOV 31H,A
ANL 30H,#0FH
MOV A,30H
ANL 31H,#0F0H
ADD A,31H
CPL A
RET
KEY2: CJNE R3,#0EEH,KEY3
MOV R2,#00H
AJMP DIS
KEY3: CJNE R3,#0EDH,KEY4
MOV R2,#01H
AJMP DIS
KEY4: CJNE R3,#0EBH,KEY5
MOV R2,#02H
AJMP DIS
KEY5: CJNE R3,#0E7H,KEY6
MOV R2,#03H
AJMP DIS
KEY6: CJNE R3,#0DEH,KEY7
MOV R2,#04H
AJMP DIS
KEY7: CJNE R3,#0DEH,KEY8
MOV R2,#05H
AJMP DIS
KEY8: CJNE R3,#0DEH,KEY9
MOV R2,#06H
AJMP DIS
KEY18: AJMP MAIN
KEY9: CJNE R3,#0DEH,KEY10
MOV R2,#07H
AJMP DIS
KEY10: CJNE R3,#0DEH,KEY11
MOV R2,#08H
AJMP DIS
KEY11: CJNE R3,#0DEH,KEY12
MOV R2,#09H
AJMP DIS
KEY12: CJNE R3,#0DEH,KEY13
MOV R2,#0AH
AJMP DIS
KEY13: CJNE R3,#0DEH,KEY14
MOV R2,#0BH
AJMP DIS
KEY14: CJNE R3,#0DEH,KEY15
MOV R2,#0CH
AJMP DIS
KEY15: CJNE R3,#0DEH,KEY16
MOV R2,#0DH
AJMP DIS
KEY16: CJNE R3,#0DEH,KEY17
MOV R2,#0EH
AJMP DIS
KEY17: CJNE R3,#0DEH,KEY18
MOV R2,#0FH
AJMP DIS
DIS: MOV A,R2
MOV DPTR,#DUAN
MOVC A,@A+DPTR
MOV P0,A
SETB P2.3
CLR P2.3
MOV P0,#0FEH
SETB P2.2
LCALL DEL
CLR P2.2
RET
DEL: MOV R7,#50
DEL2: MOV R6,#100
DJNZ R6,$
DJNZ R7,DEL2
RET
DUAN: DB 3Fh,06h,5Bh,4Fh,66h,6Dh,7Dh,07h,7Fh,6Fh,77h,7Ch,39h,5Eh,79h,71h
END
|