程序如下:
//適合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();
//端口設(shè)置
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"};
//延時函數(shù)
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)//數(shù)據(jù)滿
flag=1;//標志位置1
else
flag=0;
LCD_EA=0;//關(guān)使能
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;//關(guān)使能
}
//寫數(shù)據(jù)
void LCD_write_wodata(uchar wodata)
{
while(LCD_busy());//等待空閑
LCD_RS=1;//寫數(shù)據(jù)
LCD_RW=0;//寫選擇
LCD_EA=1;
P0=wodata;
LCD_EA=0;
}
//LCD初始化
void LCD_Init()
{
LCD_write_cmdata(0x3c);//顯示設(shè)置
delay_nms(1);//延時
LCD_write_cmdata(0x0e);//顯示開關(guān)與光標設(shè)置
delay_nms(1);
LCD_write_cmdata(0x06);
delay_nms(1);
}
//主函數(shù)
void main()
{
uchar m;
LCD_Init();
delay_nms(10);
while(1)
{
LCD_write_cmdata(0x80);//光標位置初始化
m=0;
while(dis1[m]!='