#include
#define uchar unsigned char
#define uint unsigned int
sbit LCD_RS=P2^0;
sbit LCD_RW=P2^1;
sbit EN=P2^2;
sbit BUSY=P3^7;
uchar code word1[]={"Microcontroller"};//这里可以修改改成你第一行需要输出的字符串
uchar code word2[]={"LCD1602 Test ok!"};//这里是第二行
void Delay()
{
uint i,j;
for(i=0;i<200;i++)
for(j=0;j<200;j++);
}
void LCD_CheckBusy()
{
P3=0xff;
do
{
LCD_RS=0;
LCD_RW=1;
EN=0;
EN=1;
}while(BUSY==1);
EN=0;
}
void LCD_WriteData(uchar dat)
{
LCD_CheckBusy();
EN=0;
P3=dat;
LCD_RS=1;
LCD_RW=0;
EN=1;
EN=0;
}
void LCD_WriteCommand(uchar cmd)
{
LCD_CheckBusy();
EN=0;
P3=cmd;
LCD_RS=0;
LCD_RW=0;
EN=1;
EN=0;
}
void LCD_Init()
{
LCD_WriteCommand(0x38);
LCD_WriteCommand(0x0f);
LCD_WriteCommand(0x06);
LCD_WriteCommand(0x01);
}
void LCD_WriteString(uchar addr_start,uchar*p)
{
LCD_WriteCommand(addr_start);
while(*p!='\0')
{
LCD_WriteData(*p++);
Delay();
}
}
main()
{
LCD_Init();
LCD_WriteString(0x80,word1);
LCD_WriteString(0xc0,word2);
LCD_WriteCommand(0x0c);
while(1);
}