LCD12864写数据函数
合集下载
相关主题
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
}
else if(X == 2)
{
X = 0x88;
}
else if(X == 3)
{
X = 0x98;
}
pos = X + Y;
write_cmd(pos);
}
/*LCD初始化*/
void lcd_init()
{
LCD_PSB = 1;//设置并行方式
write_cmd(0x30);
delay_1ms(5);
lcd_pos(3,1);//第四行,第七列;//=write_cmd(0x99);
write_dat(j|0x30);//首地址已写,后续挨着写;
write_dat(q|0x30);
write_dat('.');
write_dat(p|0x30);
write_dat(k|0x30);
}
}
void lcd_pos(uchar X, uchar Y);//设定位置子程序
void lcd_init();//LCD初始化
uchar dis1[] = {"成功显示咯!"};
uchar dis2[] = {"迈出第一步!"};
uchar dis3[] = {"加油!加油!"};
//uchar dis4[] = {"赶着马车去北京"};
LCD_EN = 0;
P2 = cmd;
delay_1ms(5);
LCD_EN = 1;//高脉冲
delay_1ms(5);
LCD_EN = 0;
}
/*写数据子程序*/
void write_dat(uchar dat)
{
LCD_RS = 1;
LCபைடு நூலகம்_RW = 0;
LCD_EN = 0;
P2 = dat;
/*延时子程序*/
void delay_1ms(uint x)
{
uint i,j;
for(j = 0; j < x; j++)
{
for(i = 0; i < 110; i ++);
}
}
/*写指令子程序*/
void write_cmd(uchar cmd)
{
LCD_RS = 0;
LCD_RW = 0;
delay_1ms(5);
LCD_EN = 1;//高脉冲
delay_1ms(5);
LCD_EN = 0;
}
/*设定位置子程序*/
void lcd_pos(uchar X, uchar Y)
{
uchar pos;
if(X == 0)
{
X = 0x80;
}
else if(X == 1)
{
X = 0x90;
#include<reg52.h>
/*端口定义*/
#define LCD_data P0//数据口
#define uchar unsigned char
#define uint unsigned int
sbit LCD_RS = P0^7;//寄存器选择输入
sbit LCD_RW = P0^6;//寄存器读写控制
write_cmd(0x0C);//显示开,光标关
delay_1ms(5);
write_cmd(0x01);//清除LCD显示内容
delay_1ms(5);
}
/*主程序*/
void main()
{
uint M,j,q,p,k;
uchar i;
lcd_init();
while(1)
{
lcd_pos(0,0);//第一行
{
write_dat(dis3[i]);
i++;
}
/*lcd_pos(3,0);//第四行
i = 0;
while(dis4[i] != '\0')
{
write_dat(dis4[i]);
i++;
}*/
M=1024;
j=M/1000;
q=(M%1000)/100;
p=M%1000%100/10;
k=M%1000%100%10;
i = 0;
while(dis1[i] != '\0')
{
write_dat(dis1[i]);
i++;
}
lcd_pos(1,0);//第二行
i = 0;
while(dis2[i] != '\0')
{
write_dat(dis2[i]);
i++;
}
lcd_pos(2,0);//第三行
i = 0;
while(dis3[i] != '\0')
sbit LCD_EN = P0^5;//液晶使能控制
sbit LCD_PSB = P0^4;//串并方式控制
void delay_1ms(uint x);//延时子程序
void write_cmd(uchar cmd); //写指令子程序
void write_dat(uchar dat);//写数据子程序
else if(X == 2)
{
X = 0x88;
}
else if(X == 3)
{
X = 0x98;
}
pos = X + Y;
write_cmd(pos);
}
/*LCD初始化*/
void lcd_init()
{
LCD_PSB = 1;//设置并行方式
write_cmd(0x30);
delay_1ms(5);
lcd_pos(3,1);//第四行,第七列;//=write_cmd(0x99);
write_dat(j|0x30);//首地址已写,后续挨着写;
write_dat(q|0x30);
write_dat('.');
write_dat(p|0x30);
write_dat(k|0x30);
}
}
void lcd_pos(uchar X, uchar Y);//设定位置子程序
void lcd_init();//LCD初始化
uchar dis1[] = {"成功显示咯!"};
uchar dis2[] = {"迈出第一步!"};
uchar dis3[] = {"加油!加油!"};
//uchar dis4[] = {"赶着马车去北京"};
LCD_EN = 0;
P2 = cmd;
delay_1ms(5);
LCD_EN = 1;//高脉冲
delay_1ms(5);
LCD_EN = 0;
}
/*写数据子程序*/
void write_dat(uchar dat)
{
LCD_RS = 1;
LCபைடு நூலகம்_RW = 0;
LCD_EN = 0;
P2 = dat;
/*延时子程序*/
void delay_1ms(uint x)
{
uint i,j;
for(j = 0; j < x; j++)
{
for(i = 0; i < 110; i ++);
}
}
/*写指令子程序*/
void write_cmd(uchar cmd)
{
LCD_RS = 0;
LCD_RW = 0;
delay_1ms(5);
LCD_EN = 1;//高脉冲
delay_1ms(5);
LCD_EN = 0;
}
/*设定位置子程序*/
void lcd_pos(uchar X, uchar Y)
{
uchar pos;
if(X == 0)
{
X = 0x80;
}
else if(X == 1)
{
X = 0x90;
#include<reg52.h>
/*端口定义*/
#define LCD_data P0//数据口
#define uchar unsigned char
#define uint unsigned int
sbit LCD_RS = P0^7;//寄存器选择输入
sbit LCD_RW = P0^6;//寄存器读写控制
write_cmd(0x0C);//显示开,光标关
delay_1ms(5);
write_cmd(0x01);//清除LCD显示内容
delay_1ms(5);
}
/*主程序*/
void main()
{
uint M,j,q,p,k;
uchar i;
lcd_init();
while(1)
{
lcd_pos(0,0);//第一行
{
write_dat(dis3[i]);
i++;
}
/*lcd_pos(3,0);//第四行
i = 0;
while(dis4[i] != '\0')
{
write_dat(dis4[i]);
i++;
}*/
M=1024;
j=M/1000;
q=(M%1000)/100;
p=M%1000%100/10;
k=M%1000%100%10;
i = 0;
while(dis1[i] != '\0')
{
write_dat(dis1[i]);
i++;
}
lcd_pos(1,0);//第二行
i = 0;
while(dis2[i] != '\0')
{
write_dat(dis2[i]);
i++;
}
lcd_pos(2,0);//第三行
i = 0;
while(dis3[i] != '\0')
sbit LCD_EN = P0^5;//液晶使能控制
sbit LCD_PSB = P0^4;//串并方式控制
void delay_1ms(uint x);//延时子程序
void write_cmd(uchar cmd); //写指令子程序
void write_dat(uchar dat);//写数据子程序