/*
简易万年历设计
guet.zyz
2017/06/25
*/
#include "reg52.h"
#include "sys.h"
#include "lcd1602.h"
#include "ds1302.h"
#include "keyscan.h"
uchar miao,shi,fen,ri,yue,nian,week,keynum,temp,flagtime;
uchar ledcount,count,alarmflag,lednum,flagT,year1,month1,day1;
void init()//定时器初始化函数
{
TMOD=0x11;//设置为定时器0和1的工作方式1
TH0=(65536-60000)/256;//60毫秒
TL0=(65536-60000)%256;
TH1=(65536-50000)/256;//设置定时器1的初值
TL1=(65536-50000)%256;
EA=1;
ET0=1;//允许T0中断
TR0=1;//启动中断
}
void main()
{
alarmflag=1;
lcdinit();//初始化液晶函数
ds1302_init();
init();//定时器初始化函数
beep=0;
delay(100);
beep=1;
while(1)
{
year1=(nian)/10*16+(nian)%10; //转换为bcd码
month1=(yue)/10*16+(yue)%10;
day1=(ri)/10*16+(ri)%10;
chushihua(); //初始化时间函数
timealarm(); //报时程序
keyscan(); //不断扫面按键函数
}
}
void timer0() interrupt 1//中断任务:取数据并显示
{
TH0=(65536-60000)/256;//重新赋初值
TL0=(65536-60000)%256;
miao=turnBCD(read_1302(0x81));//读出秒
fen=turnBCD(read_1302(0x83));//读出分
shi=turnBCD(read_1302(0x85));//读出时
ri=turnBCD(read_1302(0x87));//读出日
yue=turnBCD(read_1302(0x89));//读出月
nian=turnBCD(read_1302(0x8d));//读出年
week=turnBCD(read_1302(0x8b));//读出周
//显示数据
if(((0<=miao)&&(miao<15))||(((miao/10==2)||(miao/10==4))&&(miao%10<=5))||((54<=miao)&&(miao<60)))
{
print(0x80,"20 / / W < >");
writecom(h1+0x0c);
writedata(0x7e);//→右箭头
writeday(8,ri);//显示日
writeday(5,yue);//显示月
writeday(2,nian);//显示年
writeweek(week);//显示星期
print(0x40," : : (^_^) ");
writetime(6,miao);//显示出秒
writetime(3,fen);//显示出分
writetime(0,shi);//显示出时,第二行第一个开始
}
//if(15<=miao)/*当秒大于15时才显示*/
//{
if(((miao/10==1)||(miao/10==3))&&(miao%10>=5))
{
print(0x40," : : (^_^) ");
writetime(6,miao);//显示出秒
writetime(3,fen);//显示出分
writetime(0,shi);//显示出时,第二行第一个开始
}
if(((miao/10==2)||(miao/10==4))&&(miao%10>=5))/*25-30 45-50*/
{
if((5<=shi)&&(shi<=11)) flagT=1;//5-11时为早上
if((11<shi)&&(shi<=14)) flagT=2;//11-14为中午
if((14<shi)&&(shi<=18)) flagT=3;//14-18为下午
if((18<shi)||(shi<5)) flagT=4;//18-24或者0-5为晚上
switch(flagT)//分段时间
{
case 1:print(0x80," Good Morning! ");
break;
case 2:print(0x80," Good Noon! ");
break;
case 3:print(0x80,"Good afternoon! ");
break;
case 4:print(0x80," Good night! ");
break;
}
print(0x40," : : (^_^) ");
writetime(6,miao);//显示出秒
writetime(3,fen);//显示出分
writetime(0,shi);//显示出时,第二行第一个开始
}
if(((30<=miao)&&(miao<35))||((50<=miao)&&(miao<54)))//30-35 50-54
{
festival();//选择显示节日
}
}