想用LCD显示两行英文,显示不了,求教
时间:10-02
整理:3721RD
点击:
# include <reg52.h>
# define uchar unsigned char
# define uint usigned int
char code display1[]={" zhongguoliang "};
char code display2[]={"you are the best"};
sbit rs=P2^0;
sbit rw=P2^1;
sbit en=P2^2;
void delay(uchar x)
{
uchar a,b;
for(a=x;a>0;a--)
for(b=110;b>0;b--);
}
void write_com(uchar date) //写指令
{
en=0;
rs=0;
rw=0;
P1=date;
delay(5);
en=1;
delay(5);
en=0;
delay(5);
}
void write_date(uchar datea) //写数据
{
en=0;
rs=1;
rw=0;
P0=datea;
delay(10);
en=1;
delay(5);
en=0;
delay(5);
}
void init() //初始化函数
{
en=0;
write_com(0x38);
delay(5);
write_com(0x38);
delay(5);
write_com(0x0f);
delay(5);
write_com(0x06);
delay(5);
write_com(0x01);
delay(5);
}
uchar num;
void main()
{
//init();
while(1)
{ init();
write_com(0x01);
write_com(0x80); //显示第一行
for(num=0;num<16;num++)
{
write_date(display1[num]);
delay(50);
}
write_com(0x80+0x40);
for(num=0;num<16;num++)
{
write_date(display2[num]);
delay(50);
}
}
}
# define uchar unsigned char
# define uint usigned int
char code display1[]={" zhongguoliang "};
char code display2[]={"you are the best"};
sbit rs=P2^0;
sbit rw=P2^1;
sbit en=P2^2;
void delay(uchar x)
{
uchar a,b;
for(a=x;a>0;a--)
for(b=110;b>0;b--);
}
void write_com(uchar date) //写指令
{
en=0;
rs=0;
rw=0;
P1=date;
delay(5);
en=1;
delay(5);
en=0;
delay(5);
}
void write_date(uchar datea) //写数据
{
en=0;
rs=1;
rw=0;
P0=datea;
delay(10);
en=1;
delay(5);
en=0;
delay(5);
}
void init() //初始化函数
{
en=0;
write_com(0x38);
delay(5);
write_com(0x38);
delay(5);
write_com(0x0f);
delay(5);
write_com(0x06);
delay(5);
write_com(0x01);
delay(5);
}
uchar num;
void main()
{
//init();
while(1)
{ init();
write_com(0x01);
write_com(0x80); //显示第一行
for(num=0;num<16;num++)
{
write_date(display1[num]);
delay(50);
}
write_com(0x80+0x40);
for(num=0;num<16;num++)
{
write_date(display2[num]);
delay(50);
}
}
}
这个咱论坛里面有人做过,你看看他们的程序,你试试能行不
write_com(0x01);
和write_com(0x80);
之间加个write_com(0x07);