blueprince 发布于 2007-8-6 19:39:00
阳历转阴历算法程序: /************************** FileName: Calendar.C Author : Wyl Date : 2007.6.10 Function:SolarCal to LunarCal Conversion.2001-2099. ****************************/ /*************************** // //Function maybe called: uint Conversion (uchar year,uchar month,uchar day);//bit[15-9]--year,bit[8-5]--month,bit[4-0]--day uchar Converweek (uchar year,uchar month,uchar day); //(dat format: Binary.) ****************************/ #i nclude<_REG52_.h> uchar code year_code[]= { 0x4d,0x4A,0xB8, //2001 0x0d,0x4A,0x4C, //2002 0x0d,0xA5,0x41, //2003 0x25,0xAA,0xB6, //2004 0x05,0x6A,0x49, //2005 0x7A,0xAd,0xBd, //2006 0x02,0x5d,0x52, //2007 0x09,0x2d,0x47, //2008 0x5C,0x95,0xBA, //2009 0x0A,0x95,0x4e, //2010 0x0B,0x4A,0x43, //2011 0x4B,0x55,0x37, //2012 0x0A,0xd5,0x4A, //2013 0x95,0x5A,0xBf, //2014 0x04,0xBA,0x53, //2015 0x0A,0x5B,0x48, //2016 0x65,0x2B,0xBC, //2017 0x05,0x2B,0x50, //2018 0x0A,0x93,0x45, //2019 0x47,0x4A,0xB9, //2020 0x06,0xAA,0x4C, //2021 0x0A,0xd5,0x41, //2022 0x24,0xdA,0xB6, //2023 0x04,0xB6,0x4A, //2024 0x69,0x57,0x3d, //2025 0x0A,0x4e,0x51, //2026 0x0d,0x26,0x46, //2027 0x5e,0x93,0x3A, //2028 0x0d,0x53,0x4d, //2029 0x05,0xAA,0x43, //2030 0x36,0xB5,0x37, //2031 0x09,0x6d,0x4B, //2032 0xB4,0xAe,0xBf, //2033 0x04,0xAd,0x53, //2034 0x0A,0x4d,0x48, //2035 0x6d,0x25,0xBC, //2036 0x0d,0x25,0x4f, //2037 0x0d,0x52,0x44, //2038 0x5d,0xAA,0x38, //2039 0x0B,0x5A,0x4C, //2040 0x05,0x6d,0x41, //2041 0x24,0xAd,0xB6, //2042 0x04,0x9B,0x4A, //2043 0x7A,0x4B,0xBe, //2044 0x0A,0x4B,0x51, //2045 0x0A,0xA5,0x46, //2046 0x5B,0x52,0xBA, //2047 0x06,0xd2,0x4e, //2048 0x0A,0xdA,0x42, //2049 0x35,0x5B,0x37, //2050 0x09,0x37,0x4B, //2051 0x84,0x97,0xC1, //2052 0x04,0x97,0x53, //2053 0x06,0x4B,0x48, //2054 0x66,0xA5,0x3C, //2055 0x0e,0xA5,0x4f, //2056 0x06,0xB2,0x44, //2057 0x4A,0xB6,0x38, //2058 0x0A,0xAe,0x4C, //2059 0x09,0x2e,0x42, //2060 0x3C,0x97,0x35, //2061 0x0C,0x96,0x49, //2062 0x7d,0x4A,0xBd, //2063 0x0d,0x4A,0x51, //2064 0x0d,0xA5,0x45, //2065 0x55,0xAA,0xBA, //2066 0x05,0x6A,0x4e, //2067 0x0A,0x6d,0x43, //2068 0x45,0x2e,0xB7, //2069 0x05,0x2d,0x4B, //2070 0x8A,0x95,0xBf, //2071 0x0A,0x95,0x53, //2072 0x0B,0x4A,0x47, //2073 0x6B,0x55,0x3B, //2074 0x0A,0xd5,0x4f, //2075 0x05,0x5A,0x45, //2076 0x4A,0x5d,0x38, //2077 0x0A,0x5B,0x4C, //2078 0x05,0x2B,0x42, //2079 0x3A,0x93,0xB6, //2080 0x06,0x93,0x49, //2081 0x77,0x29,0xBd, //2082 0x06,0xAA,0x51, //2083 0x0A,0xd5,0x46, //2084 0x54,0xdA,0xBA, //2085 0x04,0xB6,0x4e, //2086 0x0A,0x57,0x43, //2087 0x45,0x27,0x38, //2088 0x0d,0x26,0x4A, //2089 0x8e,0x93,0x3e, //2090 0x0d,0x52,0x52, //2091 0x0d,0xAA,0x47, //2092 0x66,0xB5,0x3B, //2093 0x05,0x6d,0x4f, //2094 0x04,0xAe,0x45, //2095 0x4A,0x4e,0xB9, //2096 0x0A,0x4d,0x4C, //2097 0x0d,0x15,0x41, //2098 0x2d,0x92,0xB5, //2099 }; uchar code day_code1[9]={0x0,0x1f,0x3b,0x5a,0x78,0x97,0xb5,0xd4,0xf3}; uint code day_code2[3]={0x111,0x130,0x14e}; bit get_moon_day(uchar month_p,uint table_addr) { switch (month_p){ case 1: {if((year_code[table_addr]&0x08)==0) return(0);else return(1);} case 2: {if((year_code[table_addr]&0x04)==0) return(0);else return(1);} case 3: {if((year_code[table_addr]&0x02)==0) return(0);else return(1);} case 4: {if((year_code[table_addr]&0x01)==0) return(0);else return(1);} case 5: {if((year_code[table_addr+1]&0x80)==0) return(0);else return(1);} case 6: {if((year_code[table_addr+1]&0x40)==0) return(0);else return(1);} case 7: {if((year_code[table_addr+1]&0x20)==0) return(0);else return(1);} case 8: {if((year_code[table_addr+1]&0x10)==0) return(0);else return(1);} case 9: {if((year_code[table_addr+1]&0x08)==0) return(0);else return(1);} case 10: {if((year_code[table_addr+1]&0x04)==0) return(0);else return(1);} case 11: {if((year_code[table_addr+1]&0x02)==0) return(0);else return(1);} case 12: {if((year_code[table_addr+1]&0x01)==0) return(0);else return(1);} case 13: {if((year_code[table_addr+2]&0x80)==0) return(0);else return(1);} } } uint Conversion(uchar year,uchar month,uchar day) { uchar temp1,temp2,temp3,month_p; uint temp4,table_addr; uint dat_return,dat_buffer; bit flag_y; table_addr=(year-1)*3; temp1=year_code[table_addr+2]&0x60; temp1=_cror_(temp1,5); temp2=year_code[table_addr+2]&0x1f; 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)) { temp4+=1; } if (temp4>=temp3) { temp4-=temp3; month=0x1; month_p=0x1; flag_y=0; if(get_moon_day(month_p,table_addr)==0)temp1=0x1d; else temp1=0x1e; temp2=year_code[table_addr]/16; while(temp4>=temp1) { temp4-=temp1; month_p+=1; if(month==temp2) { flag_y=~flag_y; if(flag_y==0)month+=1; } else month+=1; if(get_moon_day(month_p,table_addr)==0)temp1=0x1d; else temp1=0x1e; } day=temp4+1; } else { temp3-=temp4; year-=1; table_addr-=0x3; month=0xc; temp2=year_code[table_addr]/16; if (temp2==0)month_p=0xc; else month_p=0xd; flag_y=0; if(get_moon_day(month_p,table_addr)==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; if(get_moon_day(month_p,table_addr)==0)temp1=0x1d; else temp1=0x1e; } day=temp1-temp3+1; } dat_buffer=0; dat_return=0; dat_buffer=(uint)year; dat_buffer<<=9; dat_return|=dat_buffer; dat_buffer=(uint)month; dat_buffer<<=5; dat_return|=dat_buffer; dat_return|=(uint)day; return dat_return; } uchar code table_week[12]={0,3,3,6,1,4,6,2,5,0,3,5}; //月修正数据表
uchar Converweek(uchar year,uchar month,uchar day) { uchar temp2; uchar week_dat; year+=100; temp2=year+year/0x4; temp2=temp2%0x7; temp2=temp2+day+table_week[month-1]; if (year%0x4==0&&month<3)temp2-=1; week_dat=temp2%0x7; return week_dat; }  记住该记住的,忘记该忘记的。 |