请高手帮我看看,我不知道错在那里,谢谢!!!!!!!!
[复制链接]
SWEI EQU 20H
GWEI EQU 21H
FZHI EQU 30H
XHUAN EQU 80H
START:
MOV FZHI,#00H
HERE:
MOV XHUAN,#05H
LOOP1:MOV R1,#0AH
LOOP2:MOV A,FZHI
MOV B,#0AH
DIV AB
MOV SWEI,A
MOV GWEI,B
MOV DPTR,#LEDMAP
MOV A,SWEI
MOVC A,@A+DPTR
MOV P1,A
SETB P3.0
CALL DELAY
CLR P3.0
MOV A,GWEI
MOVC A,@A+DPTR
MOV P1,A
SETB P3.1
CALL DELAY
CLR P3.1
DJNZ R1,LOOP2
DJNZ XHUAN,LOOP1
CALL TestKey
CJNE A,#0FH,DDONG ;不相等,可能有键按下
SJMP START ;相等,返回重新赋值,等待可能有键按下
DDONG:
ACALL DELAY ; 延时去键抖
ACALL TESTKEY
CJNE A,#0FH,HAVE
SJMP START
HAVE:
MOV R2,#04H
MOV R4,#0EFH
KEYLOOP:
MOV A,R4
JNB ACC.0,PP0
JNB ACC.1,PP1
JNB ACC.2,PP2
JNB ACC.3,PP3
RL A
DJNZ R2,KEYLOOP
PP0:
MOV R0,#00H
SJMP KEYNO
PP1:
MOV R0,#01H
SJMP KEYNO
PP2:
MOV R0,#02H
SJMP KEYNO
PP3:
MOV R0,#03H
SJMP KEYNO
KEYNO:
DEC R2
MOV A,R2
RL A
RL A
ADD A,R0
MOV R0,A
KEYLOOP2:
CALL TestKey
CJNE A,#0FH,KEYLOOP2 ;没有释放,循环等待
MOV A,R0 ;取出扫描码
;MOV DPTR,#KEYTABLE
;MOVC A,@A+DPTR
;MOV DPTR, #LEDMap
;MOVC A, @A+DPTR
MOV FZHI, A
SJMP HERE
TESTKEY:
MOV P2,#0Fh ;P2.0-3输出1,作为输入位
MOV A,P2
ANL A,#0FH
RET
KeyTable: ; 数字键码定义
db 00h, 01h, 04h, 07h
db 0fh, 02h, 05h, 08h
db 0eh, 03h, 06h, 09h
db 0dh, 0ch, 0bh, 0ah
db 10H,10H,10H,10H,10H
db 10H,10H,10H,10H,10H
LEDMAP:
DB 0C0H,0F9H,0A4H,0B0H,099H,092H,082H,0F8H,080H,090H
DELAY:
MOV R5,#01H
DELAY1:
MOV R6,#0FH
DELAY2:
MOV R7,#04H
DELAY3:
DJNZ R7,DELAY3
DJNZ R6,DELAY2
DJNZ R5,DELAY1
RET
END
|