微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > 单片机汇编实验四: 扫描键盘及LED显示实验

单片机汇编实验四: 扫描键盘及LED显示实验

时间:12-01 来源:互联网 点击:
实验要求

利用P0口与行列式键盘接口,编写键盘扫描程序,把按键输入的键码,显示在数码管上
//This is the fourthprogramof the homework
//The date:2013/3/1 The author:WQ
ORG 0000H
SJMP MAIN
MAIN:
MOV DPTR,#TABLE
MOV R1,#00H
SETB P2.6
MOV P0,#00H
CLR P2.6
SETB P2.7
MOV P0,#0H;
CLR P2.7
SCAN: //检测第一行
MOV P3,#0FEH;
MOV A,P3
ANL A,#0F0H
XHPD0: CJNE A,#0F0H,OK0
CALL JIEDIAN
SJMP NO1
OK0: CALL DELAY
MOV A,P3
ANL A,#0F0H
CJNE A,#0F0H,MM0
SJMP XHPD0
MM0: CJNE A,#0E0H,MM1
MOV R1,#01H
CALL JIEDIAN
MM1: CJNE A,#0D0H,MM2
MOV R1,#02H
CALL JIEDIAN
MM2: CJNE A,#0B0H,MM3
MOV R1,#03H
CALL JIEDIAN
MM3: CJNE A,#070H,XHPD0
MOV R1,#04H
CALL JIEDIAN

//检测第二行
NO1: MOV P3,#0FDH;
MOV A,P3
ANL A,#0F0H
XHPD1: CJNE A,#0F0H,OK1
CALL JIEDIAN
SJMP NO2
OK1: CALL DELAY
MOV A,P3
ANL A,#0F0H
CJNE A,#0F0H,MM00
SJMP XHPD1
MM00: CJNE A,#0E0H,MM10
MOV R1,#05H
CALL JIEDIAN
MM10: CJNE A,#0D0H,MM20
MOV R1,#06H
CALL JIEDIAN
MM20: CJNE A,#0B0H,MM30
MOV R1,#07H
CALL JIEDIAN
MM30: CJNE A,#070H,XHPD1
MOV R1,#08H
CALL JIEDIAN
//检测第三行
NO2: MOV P3,#0FBH;
MOV A,P3
ANL A,#0F0H
XHPD2: CJNE A,#0F0H,OK2
CALL JIEDIAN
SJMP NO3
OK2: CALL DELAY
MOV A,P3
ANL A,#0F0H
CJNE A,#0F0H,MM01
SJMP XHPD2
MM01: CJNE A,#0E0H,MM11
MOV R1,#09H
CALL JIEDIAN
MM11: CJNE A,#0D0H,MM21
MOV R1,#0AH
CALL JIEDIAN
MM21: CJNE A,#0B0H,MM31
MOV R1,#0BH
CALL JIEDIAN
MM31: CJNE A,#070H,XHPD2
MOV R1,#0CH
CALL JIEDIAN

//检测第四行
NO3: MOV P3,#0F7H;
MOV A,P3
ANL A,#0F0H
XHPD3: CJNE A,#0F0H,OK3
CALL JIEDIAN
LJMP SCAN
OK3: CALL DELAY
MOV A,P3
ANL A,#0F0H
CJNE A,#0F0H,MM40
SJMP XHPD3
MM40: CJNE A,#0E0H,MM41
MOV R1,#0DH
CALL JIEDIAN
CALL DELAY
MM41: CJNE A,#0D0H,MM42
MOV R1,#0EH
MM42: CJNE A,#0B0H,MM43
MOV R1,#0FH
MM43: CJNE A,#070H,XHPD3
MOV R1,#10H
CALL JIEDIAN
LJMP scan
ORG 02f0h
DELAY: MOV R3,#012H
DELY1: MOV R4,#011H
DELY2: NOP
DJNZ R4,DELY2
DJNZ R3,DELY1
RET
JIEDIAN:
MOV A,R1
MOVC A,@A+DPTR
SETB P2.6
MOV P0,A
CLR P2.6
RET
org0250h
TABLE: DB
0H,3FH,06H,5BH,4FH,66H,6DH,7DH,07H,7FH,6FH,77H,7CH,39H,5EH,79
H,71H
END

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top