一、仿真原理图:
二、仿真效果:
三、相关代码:
1)、系统配置:
void SystemInit(void)
{
TMOD = 0x01;
TH0 = (65536 - 46083) / 256;
TL0 = (65536 - 46083) % 256;
EA = 1;
ET0 = 1;
TR0 = 1;
}
2)、LCD1602液晶相关驱动代码:
核查是否busy?
unsigned char BusyCheck(void)
{
bit result;
RS = 0;
RW = 1;
E = 1;
_nop_();
_nop_();
_nop_();
_nop_();
result = BF;
E = 0;
return result;
}
写入指令:
void WriteInstruct(unsigned char instruct)
{
while(BusyCheck() == 1);
RS = 0;
RW = 0;
E = 0;
_nop_();
_nop_();
_nop_();
_nop_();
P0 = instruct;
_nop_();
_nop_();
_nop_();
_nop_();
E = 1;
_nop_();
_nop_();
_nop_();
_nop_();
E = 0;
}
写入数据:
void WriteData(unsigned char datas)
{
while(BusyCheck() == 1);
RS = 1;
RW = 0;
E = 0;
P0 = datas;
_nop_();
_nop_();
_nop_();
_nop_();
E = 1;
_nop_();
_nop_();
_nop_();
_nop_();
E = 0;
}
LCD1602初始化:
显示时、分、秒:
void DisplayHour()
{
unsigned char i,j;
i = hour / 10;
j = hour % 10;
WriteAddress(0x44);
WriteData(digit[i]);
WriteData(digit[j]);
}
void DisplayMinute()
{
unsigned char i,j;
i = minute / 10;
j = minute % 10;
WriteAddress(0x47);
WriteData(digit[i]);
WriteData(digit[j]);
}
void DisplaySecond()
{
unsigned char i,j;
i = second / 10;
j = second % 10;
WriteAddress(0x4a);
WriteData(digit[i]);
WriteData(digit[j]);
}
3)、main函数: