单片机/智能仪表显示与键盘设计

实验内容:键盘采用4X4键盘,每个数码管显示值可为0-F共16个数 。通过按键,求取键值0-F在R5寄存器中 。通过按键,编写程序扫描键盘输入,并将扫描结果送数码管显示 。实现对应不同按键在数码管上显示相应键值0-F的功能 。
 
参考程序:
ORG 0000H
LJMP MAIN
ORG 0030H
MAIN:
MOV R1,#7AH
MOV R2,#06H
MOV A,#00H
L01:MOV @R1,A
INC R1
DJNZ R2,L01
LCALL DIR6
MA1:LCALL KEY
MOV A,R5
MOV R1,#7AH
MOV R2,#06H
L02:MOV @R1,A
INC R1
DJNZ R2,L02
LCALL DIR6
NOP
SJMP MA1
KEY: MOV DPTR,#7F03H
MOV A,#81H
MOVX @DPTR,A
MOV R4,#00H
MOV R2,#0FEH
KEY1:MOV DPTR,#7F00H
MOV A,R2
MOVX @DPTR,A
MOV DPTR,#7F02H
MOVX A,@DPTR
【单片机/智能仪表显示与键盘设计】JB ACC.0,KEY2
MOV A,#00H
AJMP KEY5
KEY2:JB ACC.1,KEY3
MOV A,#01H
AJMP KEY5
KEY3:JB ACC.2,KEY4
MOV A,#02H
AJMP KEY5
KEY4:JB ACC.3,NEXT
MOV A,#03H
KEY5:ADD A,R4
MOV R4,A
MOV R5,A
RET
NEXT:MOV A,R4
ADD A,#04H
MOV R4,A
MOV A,R2
JNB ACC.3,NEXT1
RL A
MOV R2,A
AJMP KEY1
NEXT1:RET
DIR6:MOV R0,#7AH
MOV R3,#0FEH
MOV A,R3
DISP1:MOV DPTR,#7F00H
MOVX @DPTR,A
INC DPTR
MOV A,@R0
ADD A,#0DH
MOVC A,@A+PC
MOVX @DPTR,A
ACALL DELAY
INC R0
MOV A,R3
JNB ACC.5,DISP2
RL A
MOV R3,A
AJMP DISP1
DISP2:RET
SEGPT:DB3FH,06H,5BH,4FH,66H,6DH,7DH,07H,7FH,6FH,77H,7CH,39H,5EH,79H,71H,73H
DELAY:MOV R5,#08H
DELAY1:MOV R4,#0FFH
DELAY2:DJNZ R4,DELAY2
DJNZ R5,DELAY1
RET
END

    推荐阅读