Lcd1602不檢測忙狀態(tài)也是可以的。
#define LCD_DATA P0 //液晶看數(shù)據(jù)口定義
sbit LCD_RS=P3^2; //LCD1602數(shù)據(jù)/命令選擇引腳,H:數(shù)據(jù),L:命令
sbit LCD_RW=P3^3; //LCD1602讀寫引腳,H:數(shù)據(jù)寄存器,L:指令寄存器
sbit LCD_EN=P3^4; //LCD1602使能引腳,下降沿觸發(fā)
void Delay(uint i) //延時函數(shù)
{
while(i--);
}
void Delay_MS(uint z) //z*1MS延時函數(shù)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void Lcd_W_Com(uchar com) //液晶寫指令函數(shù)
{
LCD_RS=0;
LCD_RW=0;
LCD_DATA=com;
Delay(20);
LCD_EN=1;
Delay(20);
LCD_EN=0;
}
void Lcd_W_Dat(uchar dat) //液晶寫數(shù)據(jù)函數(shù)
{
LCD_RS=1;
LCD_RW=0;
LCD_DATA=dat;
Delay(20);
LCD_EN=1;
Delay(20);
LCD_EN=0;
}
void Lcd_Show_Str(uchar hang,add,uchar *p)//液晶寫字符串函數(shù)
{
if(hang==1) //液晶第一行
Lcd_W_Com(0x80+add);
else //液晶第二行
Lcd_W_Com(0x80+0x40+add);
while(1)
{
if(*p=='\0')
break;
Lcd_W_Dat(*p); //寫入數(shù)據(jù)
p++;
}
}
void Lcd_Init() //液晶初始化
{
Lcd_W_Com(0x38); //數(shù)據(jù)總線為8位,顯示2行,5x7點陣
Lcd_W_Com(0x0c); //開顯示,有光標,光標閃爍
Lcd_W_Com(0x06); //光標自動右移
Delay(1000); //等待設(shè)置完成
} |