;***********单片机按键扫描中断实现***********
;************2019-6-4 DXZ *******************
KEYNUM DATA 30H ;键值
LINENUM DATA 31H ;行数
COLUNMNUM DATA 32H ;列数
LINEINT DATA 33H ;行扫描初始化数值
KEYSTATE BIT 40H ;按键状态(中断请求标志)
ORG 0000H
LJMP MAIN
ORG 0003H
LJMP INT_EXIPT0
ORG 0030H
MAIN:CLR KEYSTATE
SETB IT0
SETB EX0
SETB EA
START:
MOV P0, #0F0H
JNB KEYSTATE, $
CLR KEYSTATE
MOV A, KEYNUM
MOV DPTR, #TABLE
MOVC A, @A+DPTR
MOV P2, #0FFH
MOV P2, A
SJMP START
INT_EXIPT0:
MOV KEYNUM, #00H
MOV LINENUM, #00H
MOV COLUNMNUM, #00H
MOV R7, #4
MOV R6, #4
MOV LINEINT, #0FEH
KEYSCAN:MOV P0, LINEINT
MOV A, P0
LINESCAN:JNB ACC.4, CALKEYNUM
INC COLUNMNUM
JNB ACC.5, CALKEYNUM
INC COLUNMNUM
JNB ACC.6, CALKEYNUM
INC COLUNMNUM
JNB ACC.7, CALKEYNUM
MOV COLUNMNUM, #00H
MOV A, LINEINT
RL A
MOV LINEINT, A
INC LINENUM
DJNZ R6, KEYSCAN
RETURNI:RETI
CALKEYNUM: LCALL DELAY
MOV A, P0
ORL A, #0FH
XRL A, #0F0H
JZ RETURNI
MOV A, LINENUM
RL A
RL A
ADD A, COLUNMNUM
MOV KEYNUM, A
SETB KEYSTATE
SJMP RETURNI
DELAY:
MOV R5, #10
MOV R4, #00H
LAY:DJNZ R4, $
DJNZ R5, LAY
RET
;**********段码表(共阳极)************
TABLE:
DB 0C0H, 0F9H, 0A4H, 0B0H, 99H, 92H, 82H, 0F8H ;0-7
DB 80H, 90H, 88H, 83H, 0C6H, 0A1H, 86H, 8EH ;8-15
END
51单片机汇编语言学习记录5
最新推荐文章于 2021-12-19 22:29:01 发布