微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > 51单片机+1602液晶万年历程序

51单片机+1602液晶万年历程序

时间:11-30 来源:互联网 点击:

bitget_moon_day(uchar month_p,uint table_addr)
{
uchar temp;
switch(month_p){
case 1:{temp=year_code[table_addr]&0x08;
if (temp==0)return(0);else return(1);}
case 2:{temp=year_code[table_addr]&0x04;
if (temp==0)return(0);else return(1);}
case 3:{temp=year_code[table_addr]&0x02;
if (temp==0)return(0);else return(1);}
case 4:{temp=year_code[table_addr]&0x01;
if (temp==0)return(0);else return(1);}
case 5:{temp=year_code[table_addr+1]&0x80;
if (temp==0) return(0);else return(1);}
case 6:{temp=year_code[table_addr+1]&0x40;
if (temp==0)return(0);else return(1);}
case 7:{temp=year_code[table_addr+1]&0x20;
if (temp==0)return(0);else return(1);}
case 8:{temp=year_code[table_addr+1]&0x10;
if (temp==0)return(0);else return(1);}
case 9:{temp=year_code[table_addr+1]&0x08;
if (temp==0)return(0);else return(1);}
case 10:{temp=year_code[table_addr+1]&0x04;
if (temp==0)return(0);else return(1);}
case 11:{temp=year_code[table_addr+1]&0x02;
if (temp==0)return(0);else return(1);}
case 12:{temp=year_code[table_addr+1]&0x01;
if (temp==0)return(0);else return(1);}
case 13:{temp=year_code[table_addr+2]&0x80;
if (temp==0)return(0);else return(1);}
}
}
void Conversion(bit c,uchar year,uchar month,uchar day)
{ //c=0 为21世纪,c=1 为20世纪 输入输出数据均为BCD数据
uchar temp1,temp2,temp3,month_p;
uint temp4,table_addr;
bitflag2,flag_y;
temp1=year/16; //BCD->hex 先把数据转换为十六进制
temp2=year%16;
year=temp1*10+temp2;
temp1=month/16;
temp2=month%16;
month=temp1*10+temp2;
temp1=day/16;
temp2=day%16;
day=temp1*10+temp2;
//定位数据表地址
if(c==0){
table_addr=(year+0x64-1)*0x3;
}
else {
table_addr=(year-1)*0x3;
}
//定位数据表地址完成
//取当年春节所在的公历月份
temp1=year_code[table_addr+2]&0x60;
temp1=_cror_(temp1,5);
//取当年春节所在的公历月份完成
//取当年春节所在的公历日
temp2=year_code[table_addr+2]&0x1f;
//取当年春节所在的公历日完成
// 计算当年春年离当年元旦的天数,春节只会在公历1月或2月
if(temp1==0x1){
temp3=temp2-1;
}
else{
temp3=temp2+0x1f-1;
}
if (month<10){
temp4=day_code1[month-1]+day-1;
}
else{
temp4=day_code2[month-10]+day-1;
}
if ((month>0x2)&&(year%0x4==0)){ //如果公历月大于2月并且该年的2月为闰月,天数加1
temp4+=1;
}
//计算公历日离当年元旦的天数完成
//判断公历日在春节前还是春节后
if (temp4>=temp3){ //公历日在春节后或就是春节当日使用下面代码进行运算
temp4-=temp3;
month=0x1;
month_p=0x1; //month_p为月份指向,公历日在春节前或就是春节当日month_p指向首月
flag2=get_moon_day(month_p,table_addr); //检查该农历月为大小还是小月,大月返回1,小月返回0
flag_y=0;
if(flag2==0)temp1=0x1d; //小月29天
else temp1=0x1e; //大小30天
temp2=year_code[table_addr]&0xf0;
temp2=_cror_(temp2,4); //从数据表中取该年的闰月月份,如为0则该年无闰月
while(temp4>=temp1){
temp4-=temp1;
month_p+=1;
if(month==temp2){
flag_y=~flag_y;
if(flag_y==0)month+=1;
}
else month+=1;
flag2=get_moon_day(month_p,table_addr);
if(flag2==0)temp1=0x1d;
else temp1=0x1e;
}
day=temp4+1;
}
else{ //公历日在春节前使用下面代码进行运算
temp3-=temp4;
if (year==0x0){year=0x63;c=1;}
else year-=1;
table_addr-=0x3;
month=0xc;
temp2=year_code[table_addr]&0xf0;
temp2=_cror_(temp2,4);
if (temp2==0)month_p=0xc;
else month_p=0xd; //
flag_y=0;
flag2=get_moon_day(month_p,table_addr);
if(flag2==0)temp1=0x1d;
else temp1=0x1e;
while(temp3>temp1){
temp3-=temp1;
month_p-=1;
if(flag_y==0)month-=1;
if(month==temp2)flag_y=~flag_y;
flag2=get_moon_day(month_p,table_addr);
if(flag2==0)temp1=0x1d;
else temp1=0x1e;
}
day=temp1-temp3+1;
}
c_moon=c; //HEX->BCD ,运算结束后,把数据转换为BCD数据
temp1=year/10;
temp1=_crol_(temp1,4);
temp2=year%10;
year_moon=temp1|temp2;
temp1=month/10;
temp1=_crol_(temp1,4);
temp2=month%10;
month_moon=temp1|temp2;
temp1=day/10;
temp1=_crol_(temp1,4);
temp2=day%10;
day_moon=temp1|temp2;
}

/*///////////农历转换分界线 */

void festival()//显示节日函数
{
if ( yue == 1 && ri == 1 ){ print(0x80," New Years Day ");print(0x40,"Happy New Year!!"); }//1月
else if (month_moon== 0x01 && day_moon == 0x01 ){print(0x80,"Happy New Year!!");print(0x40,"Spring Festival!"); }
else if (month_moon== 0x01 && day_moon == 0x15 ){print(0x80," yuan xiao jie: ");print(0x40,"Lantern Festival"); }//元宵节

else if ( yue == 2 && ri == 2 ){ print(0x80," World Wetlands ");print(0x40," Day "); }//2月
else if ( yue == 2 && ri == 14 ){ print(0x80," Today is: ");print(0x40,"Valentines Day!"); }

else if ( yue == 3 && ri == 8 ){ print(0x80," International ");print(0x40," Women Day "); }
else if ( yue == 3 && ri == 12 ){ print(0x80," Today is: ");print(0x40,"China Arbor Day "); }
//else if ( yue == 3 && ri == 14 ){ print(0x80," Today is: ");print(0x40," White Day "); }
else if ( yue == 3 && ri == 15 ){ print(0x80," World Consumer ");print(0x40," Right Day "); }
else if ( yue == 3 && ri == 17 ){ print(0x80," International ");print(0x40," sailing day "); }
else if ( yue == 3 && ri == 21 ){ print(0x80," Today is: ");print(0x40,"World Forest Day"); }
else if ( yue == 3 && ri == 22 ){ print(0x80," Today is: ");print(0x40,"World Water Day "); }
//if ( yue == 3 && ri == 23 ){ print(0x80,"World Meteorolo-");print(0x40," gical Day "); }
//if ( yue == 3 && ri == 24 ){ print(0x80,"World Tubercul-");print(0x40," osis Day "); }

else if ( yue == 4 && ri == 1 ){ print(0x80," Today is: ");print(0x40,"April Fools Day"); }//4
else if ( yue == 4 && ri == 5 ){ print(0x80," Ching Ming ");print(0x40," Festival ");}
else if ( yue == 4 && ri == 7 ){ print(0x80," Today is: ");print(0x40,"World Health Day"); }
else if ( yue == 4 && ri == 8 ){ print(0x80," Today is: ");print(0x40," Easter Day "); }

else if (month_moon== 0x05 && day_moon == 0x05 ){print(0x80,"the Dragon-Boat ");print(0x40," Festival "); }
else if ( yue == 5 && ri == 1 ){ print(0x80," International ");print(0x40," Labour Day "); }//5
else if ( yue == 5 && ri == 4 ){ print(0x80," Chinese Youth ");print(0x40," Day "); }
else if ( yue == 5 && ri == 8 ){ print(0x80,"World Red-Cross ");print(0x40," Day "); }
else if ( yue == 5 && ri == 12 ){ print(0x80," International ");print(0x40," Nurse Day "); }
else if ( yue == 5 && ri == 5 ){ print(0x80," Mothers Day ");print(0x40," is coming! "); }
else if ( yue == 5 && ri == 15 ){ print(0x80," International ");print(0x40," Family Day "); }
else if ( yue == 5 && ri == 31 ){ print(0x80,"World No-Smoking");print(0x40," Day "); }

else if ( yue == 6 && ri == 1 ){ print(0x80," International ");print(0x40," Childrens Day "); }//6
else if ( yue == 6 && ri == 5 ){ print(0x80," International ");print(0x40,"Environment Day "); }
else if ( yue == 6 && ri == 26 ){ print(0x80," International ");print(0x40,"Against Drug Day"); }
//else if ( yue == 6 && ri == 6 ){ print(0x80," National Eyes "); print(0x40," Caring Day "); }
else if ( yue == 6 && ri == 13 ){ print(0x80," Fathers Day ");print(0x40," is coming! "); }

else if (month_moon== 0x07 && day_moon == 0x07 ){ print(0x80," Double-Seventh ");print(0x40," Day! "); }

else if ( yue == 7 && ri == 1 ){ print(0x80," The return of ");print(0x40," Hong Kong Day "); }//7
else if ( yue == 7 && ri == 7 ){ print(0x80," Anti-Japanese ");print(0x40,"War memorial day"); }
else if ( yue == 7 && ri == 11 ){ print(0x80,"World Population");print(0x40," Day "); }

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top