单片机汇编实验七:扫描键盘及液晶显示实验
时间:12-01
来源:互联网
点击:
实验要求:利用P1口与行列式键盘接口,编写键盘扫描程序,把按键输入的键码,显示在LCD液晶显示器上。
//This is the seventh program of the homework;
//Thisprogramis made by Wang Qi Date:2013/3/7
ORG 0000H
sjmp main
org 0050h
//
sbit lcdrs=P1^0; // 液晶数据/命令选择端口
sbit lcden=P2^5; //液晶使能端
sbitlcdrw=P1^1; //读写选择端口
sbit wei=P2^7;
sbit duan=P2^6;
//
MAIN:
CALL INTE
MOV DPTR,#TABLE
SCAN: //检测第一行
MOV P3,#0FEH;
MOV A,P3
ANL A,#0F0H
XHPD0: CJNE A,#0F0H,OK0
SJMP NO1
OK0: CALL DELAY0
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 DELAY0
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
SJMP NO3
OK2: CALL DELAY0
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
LJMP SCAN
OK3: CALL DELAY0
MOV A,P3
ANL A,#0F0H
CJNE A,#0F0H,MM40
SJMP XHPD3
MM40: CJNE A,#0E0H,MM41
MOV R1,#0DH
CALL JIEDIAN
MM41: CJNE A,#0D0H,MM42
MOV R1,#0EH
CALL JIEDIAN
MM42: CJNE A,#0B0H,MM43
MOV R1,#0FH
CALL JIEDIAN
MM43: CJNE A,#070H,XHPD3
MOV R1,#10H
CALL JIEDIAN
LJMP scan
JIEDIAN:
DEC R1
MOV A,R1
MOVC A,@A+DPTR
CALL WRITE_DATE
CALL DELAY
SETB P2.6
MOV P0,A
CLR P2.6
RET
////////////////////////////////////
//初始化液晶屏程序段
INTE: CLR P1.1 //读写选择端口清零
CLR P2.6 //关闭数码管
CLR P2.7
MOV A,#0X38
CALL WRITE_COM
CALL DELAY
MOV A,#0X0E
CALL WRITE_COM
CALL DELAY
CALL DELAY
MOV A,#0X06
CALL WRITE_COM
CALL DELAY
CALL DELAY
MOV A,#0X01
CALL WRITE_COM
CALL DELAY
CALL DELAY
MOV A,#0X80
CALL WRITE_COM
CALL DELAY0
RET
//10ms延时函数
DELAY:MOV R7,#0FFH
DELY1:MOV R6,#02AH
DELY2:NOP
DJNZ R6,DELY2
DJNZ R7,DELY1
RET
//5ms延时函数
DELAY0:MOV R7,#0FEH
DELY10:MOV R6,#02FH
DELY20:NOP
DJNZ R6,DELY2
DJNZ R7,DELY1
RET
//写命令函数
WRITE_COM:
MOV P0,A //暂定A为数据传输寄存器
CLR P1.0 //打开命令选择端口
CLR P1.1 //打开写选择端口
CLR P2.5 //液晶使能端
CALL DELAY //10MS
SETB P2.5 //液晶使能端
CALL DELAY //10MS
CLR P2.5 //液晶使能端
RET
// 写数据函数
WRITE_DATE:
MOV P0,A //暂定A为数据传输寄存器
SETB P1.0 //液晶数据/命令选择端口
CLR P1.1 //读写选择端口
CLR P2.5 //液晶使能端
CALL DELAY //10MS
SETB P2.5 //液晶使能端
CALL DELAY //10MS
CLR P2.5 //液晶使能端
RET
TABLE: DB 30H,31H,32H,33H,34H,35H,36H,37H,38H,39H,41H,42H,43H,44H,45H,46H,47H
END
//This is the seventh program of the homework;
//Thisprogramis made by Wang Qi Date:2013/3/7
ORG 0000H
sjmp main
org 0050h
//
sbit lcdrs=P1^0; // 液晶数据/命令选择端口
sbit lcden=P2^5; //液晶使能端
sbitlcdrw=P1^1; //读写选择端口
sbit wei=P2^7;
sbit duan=P2^6;
//
MAIN:
CALL INTE
MOV DPTR,#TABLE
SCAN: //检测第一行
MOV P3,#0FEH;
MOV A,P3
ANL A,#0F0H
XHPD0: CJNE A,#0F0H,OK0
SJMP NO1
OK0: CALL DELAY0
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 DELAY0
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
SJMP NO3
OK2: CALL DELAY0
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
LJMP SCAN
OK3: CALL DELAY0
MOV A,P3
ANL A,#0F0H
CJNE A,#0F0H,MM40
SJMP XHPD3
MM40: CJNE A,#0E0H,MM41
MOV R1,#0DH
CALL JIEDIAN
MM41: CJNE A,#0D0H,MM42
MOV R1,#0EH
CALL JIEDIAN
MM42: CJNE A,#0B0H,MM43
MOV R1,#0FH
CALL JIEDIAN
MM43: CJNE A,#070H,XHPD3
MOV R1,#10H
CALL JIEDIAN
LJMP scan
JIEDIAN:
DEC R1
MOV A,R1
MOVC A,@A+DPTR
CALL WRITE_DATE
CALL DELAY
SETB P2.6
MOV P0,A
CLR P2.6
RET
////////////////////////////////////
//初始化液晶屏程序段
INTE: CLR P1.1 //读写选择端口清零
CLR P2.6 //关闭数码管
CLR P2.7
MOV A,#0X38
CALL WRITE_COM
CALL DELAY
MOV A,#0X0E
CALL WRITE_COM
CALL DELAY
CALL DELAY
MOV A,#0X06
CALL WRITE_COM
CALL DELAY
CALL DELAY
MOV A,#0X01
CALL WRITE_COM
CALL DELAY
CALL DELAY
MOV A,#0X80
CALL WRITE_COM
CALL DELAY0
RET
//10ms延时函数
DELAY:MOV R7,#0FFH
DELY1:MOV R6,#02AH
DELY2:NOP
DJNZ R6,DELY2
DJNZ R7,DELY1
RET
//5ms延时函数
DELAY0:MOV R7,#0FEH
DELY10:MOV R6,#02FH
DELY20:NOP
DJNZ R6,DELY2
DJNZ R7,DELY1
RET
//写命令函数
WRITE_COM:
MOV P0,A //暂定A为数据传输寄存器
CLR P1.0 //打开命令选择端口
CLR P1.1 //打开写选择端口
CLR P2.5 //液晶使能端
CALL DELAY //10MS
SETB P2.5 //液晶使能端
CALL DELAY //10MS
CLR P2.5 //液晶使能端
RET
// 写数据函数
WRITE_DATE:
MOV P0,A //暂定A为数据传输寄存器
SETB P1.0 //液晶数据/命令选择端口
CLR P1.1 //读写选择端口
CLR P2.5 //液晶使能端
CALL DELAY //10MS
SETB P2.5 //液晶使能端
CALL DELAY //10MS
CLR P2.5 //液晶使能端
RET
TABLE: DB 30H,31H,32H,33H,34H,35H,36H,37H,38H,39H,41H,42H,43H,44H,45H,46H,47H
END
单片机汇编实验扫描键盘液晶显 相关文章:
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)
- Windows CE 进程、线程和内存管理(二)(11-09)