本帖最后由 sysharon 于 2020-4-16 10:16 编辑
楼主我来更新了,上面那个问题已经解决,是因为我把芯片型号设置错了。。。。。
附上我自己写的代码,造福更多人
ORG 0000H
JMP START
ORG 0100H
START: ACALL INIT
MAIN: MOV A,#0C0H
MOV P1,A
ACALL ENABLE
ACALL KEYSCAN
MOV A,30H;
MOV DPTR,#TABLE
MOVC A,@A+DPTR
MOV P2,A
MOV A,30H
MOV DPTR,#TABLE2
MOVC A,@A+DPTR
MOV P1,A
SETB P0.7
CLR P0.6
CLR P0.5
ACALL DELAY2
SETB P0.5
ACALL DELAY1
LJMP MAIN
INIT: MOV A,#00000001B
MOV P1,A
ACALL ENABLE
MOV A,#00111000B
MOV P1,A
ACALL ENABLE
MOV A,#00001111B
MOV P1,A
ACALL ENABLE
MOV A,#00000110B
MOV P1,A
ACALL ENABLE
KEYSCAN:MOV P3,#0F0H
MOV A,P3
ANL A,#0F0H
MOV R3,A
MOV P3,#0FH
MOV A,P3
ANL A,#0FH
ORL A,R3
CJNE A,#0FFH,KEYPRO
RET
KEYPRO: MOV R3,A
MOV DPTR,#KEYVALUE
MOV R4,#0FFH
KEY1: INC R4
MOV A,R4
MOVC A,@A+DPTR
CJNE A,03H,KEY1
MOV A,R4
MOV 30H,A
DELAY1: MOV R6,#20H
DE2: MOV R7,#100H
DJNZ R7,$
DJNZ R6,DE2
RET
ENABLE: CLR P0.7
CLR P0.6
CLR P0.5
ACALL DELAY2
SETB P0.5
RET
DELAY2: MOV P1,#0FFH
CLR P0.7
SETB P0.6
CLR P0.5
NOP
SETB P0.5
JB P1.7,DELAY2
RET
KEYVALUE:DB 0E7H,0D7H,0B7H,077H,0EBH,0DBH,0BBH,07BH,0EDH,0DDH,0BDH,07DH,0EEH,0DEH,0BEH,07EH
TABLE: DB 0C0H,0F9H,0A4H,0B0H,99H,92H,82H,0F8H,80H,90H,88H,83H,0C6H,0A1H,86H,8EH
TABLE2: DB 30H,31H,32H,33H,34H,35H,36H,37H,38H,39H,41H,42H,43H,44H,45H,46H
END
|