|
P0 8位为ABCDEFG DP
P3 为数码管
P1 为4*4键盘
P1.0
P1.1
P1.2
P1.3
P1.4 P1.5 P1.6 P1.7
P1.0~P1.3接键盘的行
P1.4~P1.7接键盘的列
ORG 00H
START:
MOV R4,#00H
CLR P3.7
L1:
MOV R3,#0F7H //P1.3 = 0
MOV R1,#00H
L2:
MOV A,R3
MOV P1,A
MOV A,P1 //假如这里P1输入的是`0EEH 那输出为什么是8EH也就是F
MOV R4,A
SETB C
MOV R5,#04H
L3:
RLC A
JNC KEY
INC R1
DJNZ R5,L3
MOV A,R3
SETB C
RRC A
MOV R3,A
JC L2
JMP L1
KEY:
ACALL DELAY
D1:
MOV A,P1
XRL A,R4
JZ D1
MOV A,R1
ACALL DISP
JMP L1
DISP:
MOV DPTR,#TABLE
MOVC A,@A+DPTR
MOV P0,A
RET
DELAY:
MOV R7,#60
DLY1: MOV R6,#248
DJNZ R6,$
DJNZ R7,DLY1
RET
TABLE:
DB 0C0H, 0F9H, 0A4H, 0B0H
DB 99H, 92H, 82H, 0F8H
DB 80H, 90H, 88H, 83H
DB 0C6H, 0A1H, 86H, 8EH
END
|
|