/*这是一种2*20字符LCD显示屏的C51子程序*/ sbit E=P3^4; sbit RW=P3^5; sbit RS=P3^2; //============================================= void Delay(int t) { t>>=3; for(;t!=0;t--) ; } //============================================= void InitLcd() { char code buf[]={0x38,0x0c,0x01,0x06}; P1=0x38; E=0; Delay(20000); RS=0; RW=0; P1=0x38; /*Send 30h*/ E=1; E=0; Delay(5000); E=1; E=0; Delay(100); E=1; E=0; for(i=0;i<4;i++) { Delay(100); P1=buf[i]; E=1; E=0; } Delay(100); } //============================================= void DisplayCodeMsg1(char code *p) //显示在第一行 { char i; SendCommandByte(0x80); while(1) { i=*p++; if(i==0) break; SendDataByte(i); } } //============================================= void DisplayCodeMsg2(char code *p) //显示在第二行 { char i; SendCommandByte(0xc0); while(1) { i=*p++; if(i==0) break; SendDataByte(i); } }