单片机c语言电子万年历完整程序.docx
《单片机c语言电子万年历完整程序.docx》由会员分享,可在线阅读,更多相关《单片机c语言电子万年历完整程序.docx(9页珍藏版)》请在冰豆网上搜索。
单片机c语言电子万年历完整程序
该程序为51单片机c语言电子万年历
#include""
;
//delayms(5);
write_com(0x80+0x4c);
write_data(table[n3]);
//delayms(5);
write_com(0x80+0x4d);
write_data('^');
//delayms(5);
write_com(0x80+0x4e);
write_data('C');
//delayms(5);
DisSecond(second);////秒显示
}
/*********************液晶显示*****************/
voidwarn(uints,ucharled)
{
uchari;i=s;
//beep=0;
P1=~(led);
while(i--)
{
dis_temp(get_temp());
}
//beep=1;
P1=0xff;
i=s;
while(i--)
{
dis_temp(get_temp());
}
}
voiddeal(uintt)
{
uchari;
if((t>warn_l2)&&(t<=warn_l1))
{
warn(40,0x01);
}
elseif(t<=warn_l2)
{
warn(10,0x03);
}
elseif((t=warn_h1))
{
warn(40,0x04);
}
elseif(t>=warn_h2)
{
warn(10,0x0c);
}
else
{
i=40;
while(i--)
{dis_temp(get_temp());
DisSecond(second);}
}
}
///////////////////////////////////////
voidmain()
{
init();
Init_DS1302();
while
(1)
{
tempchange();
read_date();
deal(temp);
key_scan();
}
}
////*******************************************
voidkey_scan(void)
{//ucharmiao,s1num=0;
uchars1num=0;
if(menu==0)
{
delayms(5);
if(menu==0)
{
while(!
menu);
s1num++;
while
(1)
{
if(menu==0)
{
delayms(5);
if(menu==0)
{
while(!
menu);
s1num++;
}
}
//miao=ReadSet1302(0x81);
//second=miao;
//WriteSet1302(0x80,miao|0x80);
write_com(0x0f);//光标闪射
if(s1num==1)
{//year=ReadSet1302(0x8d);
write_com(0x80+4);//年光标
if(add==0)
{
delayms(3);
if(add==0)
{while(!
add);
turn_val(year,1,0x8d,1);
}
}
if(dec==0)
{
delayms(3);
if(dec==0)
{while(!
dec);
turn_val(year,0,0x8d,1);
}
}
}
if(s1num==2)
{
//month=ReadSet1302(0x89);
write_com(0x80+7);//月光标
if(add==0)
{
delayms(3);
if(add==0)
{while(!
add);
turn_val(month,1,0x89,2);
}
}
if(dec==0)
{
delayms(3);
if(dec==0)
{while(!
dec);
turn_val(month,0,0x89,2);
}
}
}
if(s1num==3)
{//day=ReadSet1302(0x87);
write_com(0x80+10);//日光标
if(add==0)
{
delayms(3);
if(add==0)
{while(!
add);
turn_val(day,1,0x87,3);
}
}
if(dec==0)
{
delayms(3);
if(dec==0)
{while(!
dec);
turn_val(day,0,0x87,3);//写入日寄存器
}
}
}
if(s1num==4)
{//week=ReadSet1302(0x8b);
write_com(0x80+14);//星期光标
if(add==0)
{
delayms(3);
if(add==0)
{while(!
add);
turn_val(week,1,0x8b,4);
}
}
if(dec==0)
{
delayms(3);
if(dec==0)
{while(!
dec);
turn_val(week,0,0x8b,4);
}
}
}
if(s1num==5)
{//hour=ReadSet1302(0x85)
write_com(0x80+0x40+1);//时光标
if(add==0)
{
delayms(3);
if(add==0)
{while(!
add);
turn_val(hour,1,0x85,5);
}
}
if(dec==0)
{
delayms(3);
if(dec==0)
{while(!
dec);
turn_val(hour,0,0x85,5);
}
}
}
if(s1num==6)//调时间分
{//minute=ReadSet1302(0x83);
write_com(0x80+0x40+4);
if(add==0)
{
delayms(5);
if(add==0)
{while(!
add);
turn_val(minute,1,0x83,6);//写入分寄存器
}
}
if(dec==0)
{
delayms(3);
if(dec==0)
{while(!
dec);
turn_val(minute,0,0x83,6);//写入分寄存器
}
}
}
if(s1num==7)//调时间秒
{//second=ReadSet1302(0x81);
write_com(0x80+0x40+7);//秒光标
if(add==0)
{
delayms(3);
if(add==0)
{while(!
add);
if(second==0x60)
second=0x00;
turn_val(second,1,0x81,7);
}
}
if(dec==0)
{
delayms(3);
if(dec==0)
{while(!
dec);
turn_val(second,0,0x81,7);
}
}
}
if(s1num==8)
{//miao=ReadSet1302(0x81);
//second=miao;
//WriteSet1302(0x80,second&0x7f);
s1num=0;//s1num清零//
write_com(0x0c);//光标不闪烁//
break;
}
}
}
}
}