#include<reg51.h>  
  
#define uchar unsigned char  
#define LCMdata P2  
#define Busy 0x80  
  
sbit RS=P0^7;   
sbit RW=P0^6;   
sbit E=P0^5;   
sbit REST=P0^3;  
  
void Display_String(uchar line,uchar *string);  
void Wr_Data(uchar wrdata); //写数据  
void Wr_Command(uchar wrcommand,busyc); //写指令  
void RDbf(void);//读忙状态  
void Lcm_Init(void);//液晶初始化  
void Delay5Ms(void);//延时 5ms  
  
uchar code string_1[] = {""};  
uchar code string_2[] = {""};  
uchar code string_3[] = {""};
uchar code string_4[] = {""};  
  
void main(void)  
{  
     Lcm_Init();        
     Display_String(1,string_1);  
     Display_String(2,string_2);    
     Display_String(3,string_3);    
     Display_String(4,string_4);    
    while(1);   
}  
  
void Display_String(uchar line,uchar *string) 
{   
     uchar addr,i;  
     if(line==1)  
       addr=0x80;  
     if(line==2)  
       addr=0x90;  
     if(line==3)  
       addr=0x88;    
     if(line==4)  
       addr=0x98; 

     Wr_Command(addr,1);  
     for(i=0;i<16;i++)  
     {  
       Wr_Data(*string++);  
     }   
}  
  
void Wr_Data(uchar wrdata) //写数据  
{  
     RDbf();  
     RS=1;  
     RW=0;  
     E=1;  
     LCMdata=wrdata;  
     E=0;   
}  
  
void Wr_Command(uchar wrcommand,busyc) //写指令  
{  
     if(busyc)  
       RDbf();  
     RS=0;  
     RW=0;  
     E=1;  
     LCMdata=wrcommand;  
     E=0;  
}  
  
void RDbf(void) //读忙状态  
{  
      while(1)  
     {  
       RS=0;
		 RW=1; 
		 E=0;  
       LCMdata=0xFF;           
       E=1;  
       if((LCMdata&Busy)==0)  
       break;  
     }  
}  
void Lcm_Init(void)  
{  
     Delay5Ms();  
     REST=1;  
     REST=0;  
     REST=1;   
     Wr_Command(0x30,0);  
     Delay5Ms();  
     Wr_Command(0x30,0); //2次显示模式设置，不用判忙  
     Delay5Ms();  
     Wr_Command(0x0C,1); //开显示及光标设置  
     Delay5Ms();  
     Wr_Command(0x01,1); //显示清屏  
     Delay5Ms();  
     Delay5Ms();  
     Wr_Command(0x06,1); //显示光标移动设置  
     Delay5Ms();  
}  
void Delay5Ms(void) //延时 5ms  
{  
     unsigned int TempCyc=5552;  
     while(TempCyc--);  
}