代码:ORG 0000HLJMP START
ORG 000BH
LJMP INTT0
START:MOV R0,#70H
MOV R7,#0CH
INIT: MOV @R0,#00H
INC R0
DJNZ R7,INIT
MOV 72H,#10
MOV 75H,#10
MOV TMOD,#01H
MOV TL0,#0B0H
MOV TH0,#03CH
SETB EA
SETB ET0
SETB TR0
START1:LCALL SCAN
LCALL KEYSCAN
SJMP START1
DL1MS:MOV R6,#14H
DL1:MOV R7,#19H
DL2:DJNZ R7,DL2
DJNZ R6,DL1
RET
DL20MS:ACALL SCAN
ACALL SCAN
ACALL SCAN
RET
SCAN: MOV A,78H
MOV B,#0AH
DIV AB
MOV 71H,A
MOV 70H,B
MOV A,79H
MOV B,#0AH
DIV AB
MOV 74H,A
MOV 73H,B
MOV A,7AH
MOV B,#0AH
DIV AB
MOV 77H,A
MOV 76H,B
MOV R1,#70H
MOV R5,#80H
MOV R3,#08H
SCAN1:MOV A,R5
MOV P2,A
MOV A,@R1
MOV DPTR,#TAB
MOVC A,@A+DPTR
MOV P0,A
MOV A,R5
LCALL DL1MS
INC R1
MOV A,R5
RR A
MOV R5,A
DJNZ R3,SCAN1
MOV P2,#00H
MOV P0,#0FFH
RET
TAB:DB 0C0H,0F9H,0A4H,0B0H,99H,92H,82H,0F8H,80H,90H,0BFH
INTT0: PUSH ACC
PUSH PSW
CLR ET0
CLR TR0
MOV TL0,#0B0H
MOV TH0,#03CH
SETB TR0
INC 7BH
MOV A,7BH
CJNE A,#14H,OUTT0
MOV 7BH,#00
INC 78H
MOV A,78H
CJNE A,#3CH,OUTT0
MOV 78H,#00
INC 79H
MOV A,79H
CJNE A,#3CH,OUTT0
MOV 79H,#00
INC 7AH
MOV A,7AH
CJNE A,#18H,OUTT0
MOV 7AH,#00
OUTT0:
SETB ET0
POP PSW
POP ACC
RETI
KEYSCAN:CLR EA
JNB P1.0,KEYSCAN0
JNB P1.1,KEYSCAN1
JNB P1.2,KEYSCAN2
KEYOUT:SETB EA
RET
KEYSCAN0:LCALL DL20MS
JB P1.0,KEYOUT
WAIT0:JNB P1.0,WAIT0
INC 7CH
MOV A,7CH
CLR ET0
CLR TR0
CJNE A,#03H,KEYOUT
MOV 7CH,#00
SETB ET0
SETB TR0
SJMP KEYOUT
KEYSCAN1:LCALL DL20MS
JB P1.1,KEYOUT
WAIT1:JNB P1.1,WAIT1
MOV A,7CH
CJNE A,#02H,KSCAN11
INC 79H
MOV A,79H
CJNE A,#3CH,KEYOUT
MOV 79H,#00
SJMP KEYOUT
KSCAN11:INC 7AH
MOV A,7AH
CJNE A,#18H,KEYOUT
MOV 7AH,#00
SJMP KEYOUT
KEYSCAN2:LCALL DL20MS
JB P1.2,KEYOUT
WAIT2:JNB P1.2,WAIT2
MOV A,7CH
CJNE A,#02H,KSCAN21
DEC 79H
MOV A,79H
CJNE A,#0FFH,KEYOUT
MOV 79H,#3BH
SJMP KEYOUT
KSCAN21:DEC 7AH
MOV A,7AH
CJNE A,#0FFH,KEYOUT
MOV 7AH,#17H
SJMP KEYOUT
END
|