NOKEY2: MOV P3,#0FFH
CLR P3.4
MOV A,P1
ANL A,#0FH
XRL A,#0FH
JZ NOKEY3
LCALL DL10MS
MOV A,P1
ANL A,#0FH
XRL A,#0FH
JZ NOKEY3
MOV A,P1
ANL A,#0FH
CJNE A,#0EH,KB10
MOV KEYBUF,#8
LJMP KEYWORK
KB10: CJNE A,#0DH,KB11
MOV KEYBUF,#9
LJMP KEYWORK
KB11: CJNE A,#0BH,KB12
MOV KEYBUF,#10
LJMP KEYWORK
KB12: CJNE A,#07H,KB13
MOV KEYBUF,#11
LJMP KEYWORK
KB13: NOP
;
NOKEY3: MOV P3,#0FFH
CLR P3.5
MOV A,P1
ANL A,#0FH
XRL A,#0FH
JZ NOKEY4
LCALL DL10MS
MOV A,P1
ANL A,#0FH
XRL A,#0FH
JZ NOKEY4
MOV A,P1
ANL A,#0FH
CJNE A,#0EH,KB14
MOV KEYBUF,#12
LJMP KEYWORK
KB14: CJNE A,#0DH,KB15
MOV KEYBUF,#13
LJMP KEYWORK
KB15: CJNE A,#0BH,KB16
MOV KEYBUF,#14
LJMP KEYWORK
KB16: CJNE A,#07H,KB17
MOV KEYBUF,#15
LJMP KEYWORK
KB17: NOP
;
NOKEY4: MOV P3,#0FFH
CLR P3.7
MOV A,P1
ANL A,#0FH
XRL A,#0FH
JZ NOKEY5
LCALL DL10MS
MOV A,P1
ANL A,#0FH
XRL A,#0FH
JZ NOKEY5
MOV A,P1
ANL A,#0FH
CJNE A,#0EH,KB18
MOV KEYBUF,#16
LJMP KEYWORK
KB18: CJNE A,#0DH,KB19
MOV KEYBUF,#17
LJMP KEYWORK
KB19: CJNE A,#0BH,KB20
MOV KEYBUF,#18
LJMP KEYWORK
KB20: CJNE A,#07H,KB21
MOV KEYBUF,#19
LJMP KEYWORK
KB21: NOP
;
NOKEY5: LJMP MAIN
;
KEYWORK:MOV A,KEYBUF ;得到键值
MOV DPTR,#TABLE
MOVC A,@A+DPTR ;查行键值送ACC
MOV P0,A
;
WAITFREE:
MOV A,P1 ;以下程序等待键释放
MOV KEYBUF,#00H
ANL A,#0FH
XRL A,#0FH
JNZ WAITFREE
RET
;
;*************************************
;* *
;* 延时513 us *
;* *
;*************************************
;
;513微秒延时程序
DELAY: MOV R2,#0FEH
DELAY1: DJNZ R2,DELAY1
RET
;
;*************************************
;* *
;* 延时10ms *
;* *
;*************************************
;
;10毫秒延时程序
DL10MS: MOV R3,#14H
DL10MS1:LCALL DELAY
DJNZ R3,DL10MS1
RET
;
TABLE: ;七段显示器数据定义
DB 0C0H, 0F9H, 0A4H, 0B0H, 99H ; 01234
DB 92H, 82H, 0F8H, 80H, 90H ; 56789
DB 88H, 83H, 0C6H, 0A1H, 86H; ABCDE
DB 8EH ; F
;
END ;程序结束
KEYBUF EQU 30H
ORG 00H
START: MOV KEYBUF,#2
WAIT:
MOV P3,#0FFH
CLR P3.4
MOV A,P3
ANL A,#0FH
XRL A,#0FH
JZ NOKEY1
LCALL DELY10MS
MOV A,P3
ANL A,#0FH
XRL A,#0FH
JZ NOKEY1
MOV A,P3
ANL A,#0FH
CJNE A,#0EH,NK1
MOV KEYBUF,#0
LJMP DK1
NK1: CJNE A,#0DH,NK2
MOV KEYBUF,#1
LJMP DK1
NK2: CJNE A,#0BH,NK3
MOV KEYBUF,#2
LJMP DK1
NK3: CJNE A,#07H,NK4
MOV KEYBUF,#3
LJMP DK1
NK4: NOP
DK1:
MOV A,KEYBUF
MOV DPTR,#TABLE
MOVC A,@A+DPTR
MOV P0,A
DK1A: MOV A,P3
ANL A,#0FH
XRL A,#0FH
JNZ DK1A
NOKEY1:
MOV P3,#0FFH
CLR P3.5
MOV A,P3
ANL A,#0FH
XRL A,#0FH
JZ NOKEY2
LCALL DELY10MS
MOV A,P3
ANL A,#0FH
XRL A,#0FH
JZ NOKEY2
MOV A,P3
ANL A,#0FH
CJNE A,#0EH,NK5
MOV KEYBUF,#4
LJMP DK2
NK5: CJNE A,#0DH,NK6
MOV KEYBUF,#5
LJMP DK2
NK6: CJNE A,#0BH,NK7
MOV KEYBUF,#6
LJMP DK2
NK7: CJNE A,#07H,NK8
MOV KEYBUF,#7
LJMP DK2
NK8: NOP
DK2:
MOV A,KEYBUF
MOV DPTR,#TABLE
MOVC A,@A+DPTR
MOV P0,A
DK2A: MOV A,P3
ANL A,#0FH
XRL A,#0FH
JNZ DK2A