单片机液晶显示代码
本文引用地址:https://www.eepw.com.cn/article/171260.htm
//***************************************以下单片机液晶显示****************************************************
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); //三次显示模式设置,不检测忙信号
delay5ms();
WriteCommand_Lcd(0,0x38);
delay5ms();
WriteCommand_Lcd(0,0x38);
delay5ms();
WriteCommand_Lcd(1,0x38); //显示模式设置,开始要求每次检测忙信号,8位2行5*7
WriteCommand_Lcd(1,0x08); //关闭显示
WriteCommand_Lcd(1,0x01); //清显示
WriteCommand_Lcd(1,0x06); // 文字不动,光标右移
WriteCommand_Lcd(1,0x0C); // 显示开及光标设置
}
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]);
}
}
//****************************************以上单片机液晶显示驱动*****************************************************
//*************************************************
//**********************************以下显示时间*****************************************************
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);
}
//**********************************以上显示时间*****************************************************
评论