各位,高人,本人最近用DP-51+调试汇编写的键盘扫描程序,始终无法实现不同按键显示不同数字的功能,请指点,谢谢!
汇编程序如下:
KD_DAT EQU P1.0
KD_CLK EQU P1.1
KD_KEY EQU P1.2
ORG 0000H
LJMP MAIN
ORG 4000H
MAIN:MOV SP,#60H
KEY_S: MOV R1,#00H ;赋初值
MOV R2,#00H
MOV A,#00H
LCALL TXDBYTE
JB KD_KEY,KEY_S
LCALL DELAY
SETB KD_KEY
MOV A,#0FEH
KEYZHI:LCALL TXDBYTE
JNB KD_KEY,KEYRET
RL A
INC R2
CJNE A,#7FH,KEYZHI
KEYRET: CLR P1.3
MOV DPTR,#LEDDUAN
MOV A,R2
MOVC A,@A+DPTR
MOV R4,#08H
LCALL TXDUP0
LCALL DELAY
LCALL DELAY
LCALL DELAY
LCALL DELAY
SETB P1.3
MOV A,#00H
LCALL TXDBYTE
WAIT: JB KD_KEY,WAIT
MOV A,#0FEH
LJMP KEYZHI
TXDBYTE:PUSH PSW
PUSH ACC
MOV A,R1
MOV R4,#08H
TXDUP: RLC A
MOV KD_DAT,C
CLR KD_CLK
SETB KD_CLK
DJNZ R4,TXDUP
POP ACC
POP PSW
RET
TXDUP0: PUSH PSW
PUSH ACC
RLC A
MOV KD_DAT,C
CLR KD_CLK
SETB KD_CLK
DJNZ R4,TXDUP
POP ACC
POP PSW
RET
DELAY: MOV R7,#0B0H
DELAY0: MOV R6,#0F0H
DELAY1: DJNZ R6,DELAY1
DJNZ R7,DELAY0
RET
LEDDUAN:
DB 0F9H,0A4H,0B0H,99H
DB 92H,082H,0F8H,80H
END
本人的QQ是858204759
|
|