永发信息网

跪求个利用51单片机1602显示屏DS1302做的万年历c编程序,带有公历,农历,星期,时间功能,一定要有农历

答案:1  悬赏:0  手机版
解决时间 2021-11-28 20:47
跪求个利用51单片机1602显示屏DS1302做的万年历c编程序,带有公历,农历,星期,时间功能,一定要有农历
最佳答案
农历计算方式,
///月份数据表
code uchar day_code1[9]={0x0,0x1f,0x3b,0x5a,0x78,0x97,0xb5,0xd4,0xf3};
code uint day_code2[3]={0x111,0x130,0x14e};

bit c_moon;
data uchar year_moon,month_moon,day_moon,week;

bit get_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 为19世纪 输入输出数据均为BCD数据
uchar temp1,temp2,temp3,month_p;
uint temp4,table_addr;
bit flag2,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;
}
// 计算当年春年离当年元旦的天数完成
//计算公历日离当年元旦的天数,为了减少运算,用了两个表
//day_code1[9],day_code2[3]
//如果公历月在九月或前,天数会少于0xff,用表day_code1[9],
//在九月后,天数大于0xff,用表day_code2[3]
//如输入公历日为8月10日,则公历日离元旦天数为day_code1[8-1]+10-1
//如输入公历日为11月10日,则公历日离元旦天数为day_code2[11-10]+10-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;
}

code uchar table_week[12]={0,3,3,6,1,4,6,2,5,0,3,5}; //月修正数据表

void Conver_week(bit c,uchar year,uchar month,uchar day)
{//c=0 为21世纪,c=1 为19世纪 输入输出数据均为BCD数据
uchar temp1,temp2;
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){year+=0x64;} //如果为21世纪,年份数加100
temp1=year/0x4; //所过闰年数只算1900年之后的
temp2=year+temp1;
temp2=temp2%0x7; //为节省资源,先进行一次取余,避免数大于0xff,避免使用整型数据
temp2=temp2+day+table_week[month-1];
if (year%0x4==0&&month<3)temp2-=1;
week=temp2%0x7;
}
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
三星为什么没有honm
是在过去的事情上过分纠结,该怎么办
李子昂最帅的藏头诗
新疆等于几个陕两
东莞清溪嘉龙海杰电子科技有限公司组长工资多
为什么钻石戒指写的主石/1和钻石/6是
桦南到七星峰的路线
关于如何卖球员的求助
光阴似箭,日月如梭。和 时光如水,岁月如梭
is主持人是什么意思
我要买欧曼6系牵引车310马力,后双桥的,多少
死神同人,男主白哉 记住 白她
纵横九州坐骑8升9需要多少丹
用CAD画图时,比如画一条长度是5的直线,但是
有一个质量为M,半径等于R的均匀圆周,在过圆
推荐资讯
我读文字的时候很困难,一个字在那里呆半天也
vivo y1怎么进去维修模式
win10磁盘自动优化怎么关闭
9块、10块、20、30、40、100等股价的止损价在
某反应的微观示意图如下,下列说法正确的A.反
哪些成语中含有暗和亮?
吃拉帕替尼好还是来那替尼好
单选题在十一届全国人大三次会议闭幕会上,表
苏轼是宋朝的什么,什么,什么?
卖废稿 有一本四十几万字的已发表未签约的废
单选题检查各句的文字,找出没有错别字的一项
剑灵西洛版本攻击防御属性点怎么加
正方形一边上任一点到这个正方形两条对角线的
阴历怎么看 ?