#include <reg52.h>
#include"LCD.h"
#include"INIT.h"
sbit s2=P3^1;
sbit s3=P3^2;
uchar flag,sun;
char hour,minu,sec;
void keyscan();
void write_time(uchar add,uchar time)//写时间函数
{
uchar ge,shi;
write_com(0x80+0x40+add);
shi=time/10;
ge=time%10;
write_date(0x30+shi);
write_date(0x30+ge);
}
void main()
{
LCDinit();
init();
TR0=1;
while(1)
{
keyscan();
}
}
void time0() interrupt 1
{
TH0=(65536-20000)/256;
TL0=(65536-20000)%256;
flag++;
if(flag==100)
{
flag=0;
sec++;
if(sec==60)
{
sec=0;
minu++;
if(minu==60)
{
minu=0;
hour++;
if(hour==24)
{
hour=0;
}
write_time(3,hour) ;
}
write_time(6,minu) ;
}
write_time(9,sec) ;
}
}
void keyscan()
{
if(s1==0)
{
Delay(5);
if(s1==0)
{
while(!s1);
TR0=0;
sun++;
if(sun==4)
{
sun=0;
TR0=1;
write_com(0x0c);
}
}
}
if(sun!=0)
{
if(sun==1)
{
write_com(0x80+0x40+10);
write_com(0x0f);
if(s2==0)
Delay(5);
if(s2==0)
{
while(!s2);
sec++;
if(sec==60)
sec=0;
write_time(9,sec);
}
if(s3==0)
Delay(5);
if(s3==0)
{
while(!s3);
sec--;
if(sec==-1)
sec=59;
write_time(9,sec);
}
}
if(sun==2)
{
write_com(0x80+0x40+7);
if(s2==0)
Delay(5);
if(s2==0)
{
while(!s2);
minu++;
if(minu==60)
minu=0;
write_time(6,minu);
}
if(s3==0)
Delay(5);
if(s3==0)
{
while(!s3);
minu--;
if(minu==-1)
minu=59;
write_time(6,minu);
}
}
if(sun==3)
{
write_com(0x80+0x40+4);
if(s2==0)
Delay(5);
if(s2==0)
{
while(!s2);
hour++;
if(hour==24)
hour=0;
write_time(3,hour);
}
if(s3==0)
Delay(5);
if(s3==0)
{
while(!s3);
hour--;
if(hour==-1)
hour=23;
write_time(3,hour);
}
}
}
}
头文件在下面
——回复可见内容——