C51液晶显示(LM016L)实验1
扫描二维码
随时随地手机看文章
程序如下:
//适合LM016L液晶显示器
#include
#include
#define uchar unsigned char
#define uint unsigned int
void delay_nms(int);
bit LCD_busy();
void LCD_write_cmdata(uchar);
void LCD_write_wodata(uchar);
void LCD_Init();
//端口设置
sbit LCD_RS=P1^2;
sbit LCD_RW=P1^1;
sbit LCD_EA=P1^0;
sbit LCD_BF=P0^7;
uchar dis1[]={" WELCOME TO "};
uchar dis2[]={" wo de cheng xu "};
uchar dis3[]={" WELCOME TO "};
uchar dis4[]={"zz tao xiao shou"};
//延时函数
void delay_nms(int ms)
{
uchar i;
while(ms--)
{
for(i=0;i<250;i++)
{
_nop_();
_nop_();
_nop_();
_nop_();
}
}
}
//检查LCD是否忙
bit LCD_busy()
{
bit flag;
LCD_RS=0;//写命令
LCD_RW=1;//读选择端
LCD_EA=1;//开使能
if(LCD_BF==1)//数据满
flag=1;//标志位置1
else
flag=0;
LCD_EA=0;//关使能
return flag;
}
//写命令
void LCD_write_cmdata(uchar cmdata)
{
while(LCD_busy());//等待空闲
LCD_RS=0;//写命令
LCD_RW=0;//写选择端
LCD_EA=1;//开使能
P0=cmdata;
LCD_EA=0;//关使能
}
//写数据
void LCD_write_wodata(uchar wodata)
{
while(LCD_busy());//等待空闲
LCD_RS=1;//写数据
LCD_RW=0;//写选择
LCD_EA=1;
P0=wodata;
LCD_EA=0;
}
//LCD初始化
void LCD_Init()
{
LCD_write_cmdata(0x3c);//显示设置
delay_nms(1);//延时
LCD_write_cmdata(0x0e);//显示开关与光标设置
delay_nms(1);
LCD_write_cmdata(0x06);
delay_nms(1);
}
//主函数
void main()
{
uchar m;
LCD_Init();
delay_nms(10);
while(1)
{
LCD_write_cmdata(0x80);//光标位置初始化
m=0;
while(dis1[m]!='