;====================================
;本程序使用反转扫描实现矩阵按键的键值显示0~f
;QQ 529404547
;2008.12.09
;=====================================
;=========开始处=====================
SC EQU P2
PX EQU P1
JS EQU 2AH
ORG 00H
AJMP MAIN
ORG 0030H
;===========初始化================
MAIN: MOV JS, #00H
MOV R0, #0FFH
MOV PX, #01H
MOV SC, #00H
MOV 30H, #00H
MOV 31H, #00H
MOV 32H, #00H
FF: ACALL KEY
AJMP FF
;---------------------------------
;按键处理子程序
;输入:P1
;输出:P1
;矩阵键盘扫描
;-----------------------------------
KEY: MOV P0, #0F0H ;反转扫描
MOV A, P0
ANL A, #0F0H
MOV 31H, A
MOV B, A
MOV P0, #0FH
MOV A, P0
ANL A, #0FH
MOV 32H, A
ORL A, B
MOV 30H, A
CJNE A, #0FFH, FEN ;与0FFH比较,没按键按下返回,有跳转FEN
AJMP KEYEND
FEN: CJNE R0, #16, LK
MOV R0, #0FFH
AJMP KEYEND
LK: MOV DPTR, #LAB
MOV A, R0
MOVC A, @A+DPTR
INC R0
CJNE A, 30H, FEN
MOV A, R0
ACALL DISPLAY
KEYEND: RET
;=====================================
;显示子程序
;输入JS
;输出:P2
;单个数码管从0到9的显示
;=====================================
DISPLAY:MOV DPTR, #TAB
MOVC A, @A+DPTR
MOV SC, A
MOV PX, #01H
RET
TAB: DB 00H,3FH,06H,5BH,4FH,66H,6DH,7DH,07H
DB 7FH,6FH,77H,7CH,39H,5EH,79H,71H ;共阴数码管代码
LAB: DB 77H,7BH,7DH,07EH,0B7H,0BBH,0BDH,0BEH
DB 0D7H,0DBH,0DDH,0DEH,0E7H,0EBH,0ECH,0EEH ;反转描码表
END
文章评论(0条评论)
登录后参与讨论