TEMP DATA 32H
ORG 0000H
AJMP START
START:
MOV SP,60H
MOV P2,#00H
MAIN:
LCALL KEYBOARD
LJMP MAIN
KEYBOARD:
ROW1:
MOV P1,#0EFH
MOV TEMP,P1
ANL TEMP,#0F0H
MOV A,TEMP
CJNE A,0F0H,L100
LJMP ROW2
L100:
LCALL DELAY10MS
MOV TEMP,P1
ANL TEMP,#0F0H
MOV A,TEMP
CJNE A,#0F0H,COLUMN1_1
LJMP ROW2
COLUMN1_1:
MOV TEMP,P1
MOV A,TEMP
CJNE A,#0E7H,COLUMN1_2
MUM0:
MOV DPTR,#NUM_TABLE
MOV R0,#68
MOV A,#68
LOOP1:
SUBB A,R0
MOVC A,@A+DPTR
MOV P2,A
RET
COLUMN1_2:
CJNE A,#0EBH,COLUMN1_3
MUM1:
MOV DPTR,#NUM_TABLE
MOV R0,#68
MOV A,#69
LOOP2:
SUBB A,R0
MOVC A,@A+DPTR
MOV P2,A
RET
COLUMN1_3:
CJNE A,#0EDH,COLUMN1_4
MUM2:
MOV DPTR,#NUM_TABLE
MOV R0,#68
MOV A,#70
LOOP3:
SUBB A,R0
MOVC A,@A+DPTR
MOV P2,A
RET
COLUMN1_4:
CJNE A,#0EEH,ROW2
MUM3:
MOV DPTR,#NUM_TABLE
MOV R0,#68
MOV A,#71
LOOP4:
SUBB A,R0
MOVC A,@A+DPTR
MOV P2,A
RET
ROW2:
MOV P1,#0DFH
MOV TEMP,P1
ANL TEMP,#0F0H
MOV A,TEMP
CJNE A,0F0H,L200
LJMP KEYBOARD
L200:
LCALL DELAY10MS
MOV TEMP,P1
ANL TEMP,#0F0H
MOV A,TEMP
CJNE A,#0F0H,COLUMN2_1
LJMP KEYBOARD
COLUMN2_1:
MOV TEMP,P1
MOV A,TEMP
CJNE A,#0D7H,COLUMN2_2
MUM4:
MOV DPTR,#NUM_TABLE
MOV R0,#68
MOV A,#72
LOOP5:
SUBB A,R0
MOVC A,@A+DPTR
MOV P2,A
RET
COLUMN2_2:
CJNE A,#0DBH,COLUMN2_3
MUM5:
MOV DPTR,#NUM_TABLE
MOV R0,#68
MOV A,#73
LOOP6:
SUBB A,R0
MOVC A,@A+DPTR
MOV P2,A
RET
COLUMN2_3:
CJNE A,#0DDH,COLUMN2_4
MUM6:
MOV DPTR,#NUM_TABLE
MOV R0,#68
MOV A,#74
LOOP7:
SUBB A,R0
MOVC A,@A+DPTR
MOV P2,A
RET
COLUMN2_4:
CJNE A,#0DEH,COLSCANEND
MUM7:
MOV DPTR,#NUM_TABLE
MOV R0,#68
MOV A,#75
LOOP8:
SUBB A,R0
MOVC A,@A+DPTR
MOV P2,A
RET
COLSCANEND:
RET
DELAY10MS:
PUSH 30H
PUSH 30H
MOV 30H,#173
MOV 31H,#27
NEXT:
DJNZ 31H,NEXT
DJNZ 30H,NEXT
POP 31H
POP 30H
RET
NUM_TABLE:
DB 7FH,0BFH,0DFH,0EFH,0F7H
DB 0FBH,0FDH,0FEH
END
按键控制相应的LED灯点亮硬件调试结果: