單片機(jī)液晶顯示代碼
本文引用地址:http://m.butianyuan.cn/article/171260.htm
//***************************************以下單片機(jī)液晶顯示****************************************************
void waitLcd() //just wait until 液晶不忙為止
{
char temp;
bit flag=1;
while(flag==1)
{
temp=XBYTE[rc];
if (temp>>7==0) flag=0;
P1=temp;
}
P1=0xff;
}
//just wait until 液晶不忙為止
void WriteCommand_Lcd(bit isCheck,char c)
{
if (isCheck==1) waitLcd();
XBYTE[wc]=c;
}
void writedata(char c)
{
waitLcd();
XBYTE[wd]=c;
}
void LcdInit()
{
delay5ms();
delay5ms();
delay5ms();
WriteCommand_Lcd(0,0x38); //三次顯示模式設(shè)置,不檢測忙信號(hào)
delay5ms();
WriteCommand_Lcd(0,0x38);
delay5ms();
WriteCommand_Lcd(0,0x38);
delay5ms();
WriteCommand_Lcd(1,0x38); //顯示模式設(shè)置,開始要求每次檢測忙信號(hào),8位2行5*7
WriteCommand_Lcd(1,0x08); //關(guān)閉顯示
WriteCommand_Lcd(1,0x01); //清顯示
WriteCommand_Lcd(1,0x06); // 文字不動(dòng),光標(biāo)右移
WriteCommand_Lcd(1,0x0C); // 顯示開及光標(biāo)設(shè)置
}
void displayListChar(unsigned char X, unsigned char Y, uchar DData)
{
Y = 0x1;
X = 0xF;
if (X = 0xF)
{
Y = 0x1;
X = 0xF;
if (Y) X = 0x40;
X = 0x80;
WriteCommand_Lcd(0,X);
writedata(dispbuf[DData]);
}
}
//****************************************以上單片機(jī)液晶顯示驅(qū)動(dòng)*****************************************************
//*************************************************
//**********************************以下顯示時(shí)間*****************************************************
void Show_Time(void)
{
displayListChar(0,0,hour/10);
displayListChar(1,0,hour%10);
displayListChar(2,0,10);
displayListChar(3,0,minute/10);
displayListChar(4,0,minute%10);
displayListChar(5,0,10);
displayListChar(6,0,second/10);
displayListChar(7,0,second%10);
}
//**********************************以上顯示時(shí)間*****************************************************
評(píng)論