您好,欢迎访问三七文档
公历转农历C程序收藏注意只能到2049年!#defineucharunsignedchar#defineuintunsignedint#includeintrins.h/*公历年对应的农历数据,每年三字节,格式第一字节BIT7-4位表示闰月月份,值为0为无闰月,BIT3-0对应农历第1-4月的大小第二字节BIT7-0对应农历第5-12月大小,第三字节BIT7表示农历第13个月大小月份对应的位为1表示本农历月大(30天),为0表示小(29天)第三字节BIT6-5表示春节的公历月份,BIT4-0表示春节的公历日期*/codeucharyear_code[597]={0x04,0xAe,0x53,//190100x0A,0x57,0x48,//190230x55,0x26,0xBd,//190360x0d,0x26,0x50,//190490x0d,0x95,0x44,//1905120x46,0xAA,0xB9,//1906150x05,0x6A,0x4d,//1907180x09,0xAd,0x42,//1908210x24,0xAe,0xB6,//19090x04,0xAe,0x4A,//19100x6A,0x4d,0xBe,//19110x0A,0x4d,0x52,//19120x0d,0x25,0x46,//19130x5d,0x52,0xBA,//19140x0B,0x54,0x4e,//19150x0d,0x6A,0x43,//19160x29,0x6d,0x37,//19170x09,0x5B,0x4B,//19180x74,0x9B,0xC1,//19190x04,0x97,0x54,//19200x0A,0x4B,0x48,//19210x5B,0x25,0xBC,//19220x06,0xA5,0x50,//19230x06,0xd4,0x45,//19240x4A,0xdA,0xB8,//19250x02,0xB6,0x4d,//19260x09,0x57,0x42,//19270x24,0x97,0xB7,//19280x04,0x97,0x4A,//19290x66,0x4B,0x3e,//19300x0d,0x4A,0x51,//19310x0e,0xA5,0x46,//19320x56,0xd4,0xBA,//19330x05,0xAd,0x4e,//19340x02,0xB6,0x44,//19350x39,0x37,0x38,//19360x09,0x2e,0x4B,//19370x7C,0x96,0xBf,//19380x0C,0x95,0x53,//19390x0d,0x4A,0x48,//19400x6d,0xA5,0x3B,//19410x0B,0x55,0x4f,//19420x05,0x6A,0x45,//19430x4A,0xAd,0xB9,//19440x02,0x5d,0x4d,//19450x09,0x2d,0x42,//19460x2C,0x95,0xB6,//19470x0A,0x95,0x4A,//19480x7B,0x4A,0xBd,//19490x06,0xCA,0x51,//1***0x0B,0x55,0x46,//19510x55,0x5A,0xBB,//19520x04,0xdA,0x4e,//19530x0A,0x5B,0x43,//19540x35,0x2B,0xB8,//19550x05,0x2B,0x4C,//19560x8A,0x95,0x3f,//19570x0e,0x95,0x52,//19580x06,0xAA,0x48,//19590x7A,0xd5,0x3C,//19600x0A,0xB5,0x4f,//19610x04,0xB6,0x45,//19620x4A,0x57,0x39,//19630x0A,0x57,0x4d,//19640x05,0x26,0x42,//19650x3e,0x93,0x35,//19660x0d,0x95,0x49,//19670x75,0xAA,0xBe,//19680x05,0x6A,0x51,//19690x09,0x6d,0x46,//19700x54,0xAe,0xBB,//19710x04,0xAd,0x4f,//19720x0A,0x4d,0x43,//19730x4d,0x26,0xB7,//19740x0d,0x25,0x4B,//19750x8d,0x52,0xBf,//19760x0B,0x54,0x52,//19770x0B,0x6A,0x47,//19780x69,0x6d,0x3C,//19790x09,0x5B,0x50,//19800x04,0x9B,0x45,//19810x4A,0x4B,0xB9,//19820x0A,0x4B,0x4d,//19830xAB,0x25,0xC2,//19840x06,0xA5,0x54,//19850x06,0xd4,0x49,//19860x6A,0xdA,0x3d,//19870x0A,0xB6,0x51,//19880x09,0x37,0x46,//19890x54,0x97,0xBB,//19900x04,0x97,0x4f,//19910x06,0x4B,0x44,//19920x36,0xA5,0x37,//19930x0e,0xA5,0x4A,//19940x86,0xB2,0xBf,//19950x05,0xAC,0x53,//19960x0A,0xB6,0x47,//19970x59,0x36,0xBC,//19980x09,0x2e,0x50,//19992940x0C,0x96,0x45,//20002970x4d,0x4A,0xB8,//20010x0d,0x4A,0x4C,//20020x0d,0xA5,0x41,//20030x25,0xAA,0xB6,//20040x05,0x6A,0x49,//20050x7A,0xAd,0xBd,//20060x02,0x5d,0x52,//20070x09,0x2d,0x47,//20080x5C,0x95,0xBA,//20090x0A,0x95,0x4e,//20100x0B,0x4A,0x43,//20110x4B,0x55,0x37,//20120x0A,0xd5,0x4A,//20130x95,0x5A,0xBf,//20140x04,0xBA,0x53,//20150x0A,0x5B,0x48,//20160x65,0x2B,0xBC,//20170x05,0x2B,0x50,//20180x0A,0x93,0x45,//20190x47,0x4A,0xB9,//20200x06,0xAA,0x4C,//20210x0A,0xd5,0x41,//20220x24,0xdA,0xB6,//20230x04,0xB6,0x4A,//20240x69,0x57,0x3d,//20250x0A,0x4e,0x51,//20260x0d,0x26,0x46,//20270x5e,0x93,0x3A,//20280x0d,0x53,0x4d,//20290x05,0xAA,0x43,//20300x36,0xB5,0x37,//20310x09,0x6d,0x4B,//20320xB4,0xAe,0xBf,//20330x04,0xAd,0x53,//20340x0A,0x4d,0x48,//20350x6d,0x25,0xBC,//20360x0d,0x25,0x4f,//20370x0d,0x52,0x44,//20380x5d,0xAA,0x38,//20390x0B,0x5A,0x4C,//20400x05,0x6d,0x41,//20410x24,0xAd,0xB6,//20420x04,0x9B,0x4A,//20430x7A,0x4B,0xBe,//20440x0A,0x4B,0x51,//20450x0A,0xA5,0x46,//20460x5B,0x52,0xBA,//20470x06,0xd2,0x4e,//20480x0A,0xdA,0x42,//2049};///月份数据表codeucharday_code1[9]={0x0,0x1f,0x3b,0x5a,0x78,0x97,0xb5,0xd4,0xf3};codeuintday_code2[3]={0x111,0x130,0x14e};/*函数功能:输入BCD阳历数据,输出BCD阴历数据(只允许1901-2099年)调用函数示例:Conversion(c_sun,year_sun,month_sun,day_sun)如:计算2004年10月16日Conversion(0,0x4,0x10,0x16);c_sun,year_sun,month_sun,day_sun均为BCD数据,c_sun为世纪标志位,c_sun=0为21世纪,c_sun=1为19世纪调用函数后,原有数据不变,读c_moon,year_moon,month_moon,day_moon得出阴历BCD数据*/bitc_moon;dataucharyear_moon,month_moon,day_moon,week;/*子函数,用于读取数据表中农历月的大月或小月,如果该月为大返回1,为小返回0*/bitget_moon_day(ucharmonth_p,uinttable_addr){uchartemp;switch(month_p){case1:{temp=year_code[table_addr]&0x08;if(temp==0)return(0);elsereturn(1);}case2:{temp=year_code[table_addr]&0x04;if(temp==0)return(0);elsereturn(1);}case3:{temp=year_code[table_addr]&0x02;if(temp==0)return(0);elsereturn(1);}case4:{temp=year_code[table_addr]&0x01;if(temp==0)return(0);elsereturn(1);}case5:{temp=year_code[table_addr+1]&0x80;if(temp==0)return(0);elsereturn(1);}case6:{temp=year_code[table_addr+1]&0x40;if(temp==0)return(0);elsereturn(1);}case7:{temp=year_code[table_addr+1]&0x20;if(temp==0)return(0);elsereturn(1);}case8:{temp=year_code[table_addr+1]&0x10;if(temp==0)return(0);elsereturn(1);}case9:{temp=year_code[table_addr+1]&0x08;if(temp==0)return(0);elsereturn(1);}case10:{temp=year_code[table_addr+1]&0x04;if(temp==0)return(0);elsereturn(1);}case11:{temp=year_code[table_addr+1]&0x02;if(temp==0)return(0);elsereturn(1);}case12:{temp=year_code[table_addr+1]&0x01;if(temp==0)return(0);elsereturn(1);}case13:{temp=year_code[table_addr+2]&0x80;if(temp==0)return(0);elsereturn(1);}}}/*函数功能:输入B
本文标题:公历转农历C程序
链接地址:https://www.777doc.com/doc-1661357 .html