本文为大家分享一个可通过按键来调节时间的1602液晶显示的数字时钟程序。
详细程序/***************************************
程序功能:
LCD液晶显示屏显示时钟并且可以修改时间
***************************************/
#include《reg52.h》
#define uint unsigned int
#define uchar unsigned char
sbit K1=P1^0;//设置三个独立键盘
sbit K2=P1^3;
sbit K3=P1^5;
sbit lcdwrite=P2^5;
sbit lcddatecommand=P2^6;
sbit lcde=P2^7;
uchar code firstline[]=“2013-06-03”;
uchar code secondline[]=“00-00-00”;
uchar i;
uchar hour,minutes,seconds;
uchar count,num;
uchar cnt;
void delay(uint z)
{
uint x,y;
for(x=z;x》0;x--)
{
for(y=0;y《=112;y++)
{
}
}
}
void write_command(uchar command)
{
lcddatecommand=0;
lcdwrite=0;
P0=command;
delay(1);
lcde=1;
delay(1);
lcde=0;
}
void write_date(uchar date)
{
lcddatecommand=1;
lcdwrite=0;
P0=date;
delay(1);
lcde=1;
delay(1);
lcde=0;
}
void LCDinit()
{
lcde=0;
write_command(0x38);//设置16*2显示,5*7点阵,8位数据接口
write_command(0x0f);//设置开显示,不显示光标
write_command(0x06);// 写一个字符后地址指针加1
write_command(0x80);
for(i=0;i《10;i++)
{
write_date(firstline[i]);
delay(1);
}
write_command(0x80+0x40);
for(i=0;i《8;i++)
{
write_date(secondline[i]);
delay(1);
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)