单片机的1602液晶显示
2019-04-15 18:02发布
生成海报
以上是我认为控制1602液晶比较重要的,必须要我们懂的
下面是我写得到一个程序
#include
#define uchar unsigned char
#define uint unsigned int
uchar code table1[]={"I LOVE MCU !"};
uchar code table2[]={"who you name?"};
sbit lcdrs=P2^0; //RS
sbit lcdrw=P2^1; //R/w
sbit lcden=P2^2; //EN
uchar num,num1,num2;
void delay(uint z)
{
int x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void write_com(uchar com) //写状态命令函数
{
lcdrs=0;
lcdrw=0;
P0=com;
delay(5);
lcden=1;
delay(5);
lcden=0;
}
void write_data(uchar date)//发送数据函数
{
lcdrs=1;
P0=date;
delay(5);
lcden=1;
delay(5);
lcden=0;
}
void init()
{
lcden=0;
write_com(0x38);
delay(1);
write_com(0x0c);
delay(1);
write_com(0x06);
delay(1);
// write_com(0x01);
delay(1);
write_com(0x80+0x12);
delay(1);
}
void main()
{
init();
for (num=0;num<12;num++)
{
write_data(table1[num]);
delay(20);
}
// write_com(0x01); //清屏
write_com(0x80+0x53);
for (num=0;num<13;num++)
{
write_data(table2[num]);
delay(20);
}
for(num=0;num<16;num++)
{
write_com(0x1c);//整屏左移16格 (0x18)右移
delay(200);
}
while(1);
}
这是仿真后的结果
打开微信“扫一扫”,打开网页后点击屏幕右上角分享按钮