本文包含原理图、PCB、源代码、封装库、中英文PDF等资源
您需要 登录 才可以下载或查看,没有账号?注册会员
×
#include<reg52.h>
#include <intrins.h>
#include"LCD1602.h"
unsigned char week_value[2];
char hide_sec,hide_min,hide_hour,hide_day,hide_week,hide_month,hide_year;
#include"DS1302.h"
#include"ds18b20.h"
#define uint unsigned int
#define uchar unsigned char
sbit set=P2^0;
sbit up=P2^1;
sbit out=P2^2;
sbit bell=P3^7;
char done,count,temp,flag,up_flag,down_flag;
void show_time();
void beep();
void outkey();
void upkey();
void setkey();
void keydone();
void Delay1ms(uint count)
{
uint x,y;
for(x=count;x>0;x--)
for(y=110;y>0;y--);
}
void main()
{
LCD_Initial();
Initial_DS1302();
flag=1;
done=0;
up_flag=0;
down_flag=0;
GotoXY(10,1);
Print("T: ");
while(1)
{
while(done==1)
{
keydone();
}
while(done==0)
{
show_time();
flag=0;
setkey();
}
}
}
void beep()
{
unsigned char i;
for(i=0;i<10;i++)
{
bell=0;
Delay1ms(10);
bell=1;}
}
void outkey()
{
uchar Second;
if(out==0)
{
Delay1ms(10);
if(out==0)
{
count=0;
hide_sec=0;
hide_min=0;
hide_hour=0;
hide_week=0;
hide_day=0;
hide_month=0;
hide_year=0;
Second=Read1302(DS1302_SECOND);
Write1302(0x8e,0x00);
Write1302(0x80,Second&0x7f);
Write1302(0x8E,0x80);
done=0;
}
beep();
while(out==0);
}
}
void upkey()
{
up=1;
if(up==0)
{
Delay1ms(10);
if(up==0)
{
switch(count)
{
case 1:
temp=Read1302(DS1302_SECOND);
temp=temp+1;
up_flag=1;
if((temp&0x7f)>0x59)
temp=0;
break;
case 2:
temp=Read1302(DS1302_MINUTE);
temp=temp+1;
up_flag=1;
if(temp>0x59)
temp=0;
break;
case 3:
temp=Read1302(DS1302_HOUR);
temp=temp+1;
up_flag=1;
if(temp>0x23)
temp=0;
break;
case 4:
temp=Read1302(DS1302_WEEK);
temp=temp+1;
up_flag=1;
if(temp>0x7)
temp=1;
break;
case 5:
temp=Read1302(DS1302_DAY);
temp=temp+1;
up_flag=1;
if(temp>0x31)
temp=1;
break;
case 6:
temp=Read1302(DS1302_MONTH);
temp=temp+1;
up_flag=1;
if(temp>0x12)
temp=1;
break;
case 7:
temp=Read1302(DS1302_YEAR);
temp=temp+1;
up_flag=1;
if(temp>0x85)
temp=0;
break;
default:break;
}
}
beep();
while(up==0);
}
}
void setkey()
{
set=1;
if(set==0)
{
Delay1ms(10);
if(set==0)
{
count=count+1;
done=1;
}
beep();
while(set==0);
}
}
void keydone()
{
uchar Second;
if(flag==0)
{
Write1302(0x8e,0x00);
temp=Read1302(0x80);
Write1302(0x80,temp|0x80);
Write1302(0x8e,0x80);
flag=1;
}
setkey();
switch(count)
{
case 1:do{
outkey();
upkey();
if(up_flag==1||down_flag)
{
Write1302(0x8e,0x00);
Write1302(0x80,temp|0x80);
Write1302(0x8e,0x80);
up_flag=0;
down_flag=0;
}
hide_sec++;
if(hide_sec>3)
hide_sec=0;
show_time();
}
while(count==2);
break;
case 2:
do{
hide_sec=0;
outkey();
upkey();
if(temp>0x60)
temp=0;
if(up_flag==1||down_flag)
{
Write1302(0x8e,0x00);
Write1302(0x82,temp|0x80);
Write1302(0x8e,0x80);
up_flag=0;
down_flag=0;
}
hide_min++;
if(hide_min>3)
hide_min=0;
show_time();
} while(count==3);break;
case 3: do{
hide_min=0;
outkey();
upkey();
if(temp>60)
temp=0;
if(up_flag==1||down_flag)
{
Write1302(0x8e,0x00);
Write1302(0x84,temp|0x80);
Write1302(0x8e,0x80);
up_flag=0;
down_flag=0;
}
hide_hour++;
if(hide_hour>3)
hide_hour=0;
show_time();
} while(count==4);break;
case 4:
do{
hide_hour=0;
outkey();
upkey();
if(up_flag==1||down_flag)
{
Write1302(0x8e,0x00);
Write1302(0x8a,temp|0x80);
Write1302(0x8e,0x80);
up_flag=0;
down_flag=0;
}
hide_week++;
if(hide_week>3)
hide_week=0;
show_time();
} while(count==5);break;
case 5: do{
hide_week=0;
outkey();
upkey();
if(up_flag==1)
{
Write1302(0x8e,0x00);
Write1302(0x86,temp|0x80);
Write1302(0x8e,0x80);
up_flag=0;
down_flag=0;
} hide_day++;
if(hide_day>3)
hide_day=0;
show_time();
} while(count==6);break;
case 6: do{
hide_day=0;
outkey();
upkey();
if(up_flag==1||down_flag==1)
{
Write1302(0x8e,0x00);
Write1302(0x88,temp|0x80);
Write1302(0x8e,0x80);
up_flag=0;
down_flag=0;
} hide_month++;
if(hide_month>3)
hide_month=0;
show_time();
} while(count==7);break;
case 7: do{
hide_month=0;
outkey();
upkey();
if(up_flag==1||down_flag)
{
Write1302(0x8e,0x00);
Write1302(0x8c,temp|0x80);
Write1302(0x8e,0x80);
up_flag=0;
down_flag=0;
} hide_year++;
if(hide_year>3)
hide_year=0;
show_time();
}while(count=8);break;
case 8:count=0;hide_year=0;
Second=Read1302(DS1302_SECOND);
Write1302(0x8e,0x00);
Write1302(0x8e,Second&0x7f);
Write1302(0x8E,0x80);
done=0;
break;
default:break;
}
}
void show_time()
{
DS1302_GetTime(&CurrentTime); //获取时钟芯片的时间数据
TimeToStr(&CurrentTime); //时间数据转换液晶字符
DateToStr(&CurrentTime); //日期数据转换液晶字符
ReadTemp(); //开启温度采集程序
temp_to_str(); //温度数据转换成液晶字符
GotoXY(12,1); //液晶字符显示位置
Print(TempBuffer); //显示温度
GotoXY(0,1);
Print(CurrentTime.TimeString); //显示时间
GotoXY(0,0);
Print(CurrentTime.DateString); //显示日期
GotoXY(15,0);
Print(week_value); //显示星期
GotoXY(11,0);
Print("Week"); //在液晶上显示 字母 week
Delay1ms(400); //扫描延时
} |