#include
#include"lcd1602.h"
#include"ds1302.h"
#include"ds18b20.h"
#define uint unsigned int
#define uchar unsigned char
uint b[6];
//年月日时分秒
uchar code row1[]={"2009-01-01"};
uchar code row2[]={"00:00:00"};
uchar year1[12]={31,28,31,30,31,30,31,31,30,31,30,31};//平年
uchar year2[12]={31,29,31,30,31,30,31,31,30,31,30,31};//润年
uchar j[6]={0x85,0x88,0x8b,0x84+0x40,0x87+0x40,0x8a+0x40};//LCD地址
uchar i,k,jj=0,w,clock=0,bigclock=0,c=0,num;
//i循环数 k温度缓存 jj地址位
uint temp;
sbit b1=P3^0;//设置
sbit b2=P3^1;//上调
sbit b3=P3^2;//下调
sbit b4=P3^3;//转换
sbit b5=P3^4;//闹钟
sbit speaker=P3^5;
lcdscan()
{
for(i=0;i<6;i++)
{
lcdwrite(j[i]);
lcdshuju(a[11-i*2]+0x30);
lcdwrite(j[i]+0x01);
lcdshuju(a[10-i*2]+0x30);
}
}
void key()
{
if(b1==0)
{
dsaddshuju(0x80,(a[1]<<4)+a[0]+0x80);
while(b1==0)
{
for(i=0;i<6;i++)
{
b[i]=a[11-i*2+clock]*10+a[10-i*2+clock];
}
if(b4==0)
{
delay(3);
jj++;
if(jj==6)
{
jj=0;
}
}
if(b2==0)
{
delay(3);
b[jj]++;
if(b[5]==60)b[5]=0;
if(b[4]==60)b[4]=0;
if(b[3]==24)b[3]=0;
if((b[0]%4==0 && b[0]%100!=0) || b[0]%400==0){if(b[2]>year2[b[1]-1])b[2]=1;}
else {if(b[2]>year1[b[1]-1])b[2]=1;}
if(b[1]==13)b[1]=1;
if(b[0]==100)b[0]=0;
}
if(b3==0)
{
delay(3);
b[jj]--;
if(b[5]==-1)b[5]=59;
if(b[4]==-1)b[4]=59;
if(b[3]==-1)b[3]=23;
if((b[0]%4==0 && b[0]%100!=0) || b[0]%400==0){if(b[2]<=0)b[2]=year2[b[1]-1];}
else {if(b[2]<=0)b[2]=year1[b[1]-1];}
if(b[1]==0)b[1]=12;
if(b[0]==-1)b[0]=99;
}
for(i=0;i<6;i++)
{
a[11-i*2+clock]=b[i]/10;
a[10-i*2+clock]=b[i]%10;
}
lcdwrite(j[jj]);
lcdshuju(0);
lcdwrite(j[jj]+1);
lcdshuju(0);
delay(200);
lcdwrite(j[jj]);
lcdshuju(a[11-2*jj+clock]+0x30);
lcdwrite(j[jj]+1);
lcdshuju(a[10-2*jj+clock]+0x30);
delay(200);
if(b1==1)
{
dsaddshuju(0x80,(a[1]<<4)+a[0]);
dson();
}
if(b5==0)clock=12;
}
}
}
void main()
{
speaker=0