网站导航: 首页 > 设计参考 > 正文 文章搜索
51单片机万年历优化算法源程序
 
文章编号:
090106145808
文章分类: 单片机 51系列
点 击:
...
关 键 词: 万年历
文章来源:
网络
摘 要:
一、 阳历算法,具体算法见函数void get_solar_day_date(void),这样阳历日历的星期排法就确定了。二、 阴历算法,200年需要200 × 2 = 400个字节,构成阴历压缩数据表lunar_calendar_month_table[]如下...

 
  1. unsigned char calendar_calculate_lunar_month_total_day(void)   
  2. {   
  3.     unsigned char mc_tpumenus_temp_01;   
  4.     unsigned char mc_tpumenus_temp_02;   
  5.     if(gc_lunar_calendar_month < 9)   
  6.     {   
  7.         mc_tpumenus_temp_01 = lunar_calendar_month_table[2*gc_lunar_calendar_year];   
  8.         mc_tpumenus_temp_02 = gc_lunar_calendar_month - 1;   
  9.     }   
  10.     else  
  11.     {   
  12.         mc_tpumenus_temp_01 = lunar_calendar_month_table[2*gc_lunar_calendar_year + 1];   
  13.         mc_tpumenus_temp_02 = gc_lunar_calendar_month - 9;   
  14.     }   
  15.     if((mc_tpumenus_temp_01>> mc_tpumenus_temp_02)&0x01)   
  16.         return(29);   
  17.     else    
  18.         return(30);   
  19. }   

阳历日和农历节气的对应关系
压缩节气数据表:
根据规律可以得到四个数据表(每个阳历月有两个节气,每个节气需要两个数据表):

 

 
  1. const unsigned char calendar_solar_term_table_01[12][33] = {   
  2.     {7,6,6,6,6,6,6,6,6,5,6,6,6,5,5,6,6,5,5,5,5,5,5,5,5,4,5,5},          //month 1   
  3.     {5,4,5,5,5,4,4,5,5,4,4,4,4,4,4,4,4,3,4,4,4,3,3,4,4,3,3,3},          //2   
  4.     {6,6,6,7,6,6,6,6,5,6,6,6,5,5,6,6,5,5,5,6,5,5,5,5,4,5,5,5,5},        //3   
  5.     {5,5,6,6,5,5,5,6,5,5,5,5,4,5,5,5,4,4,5,5,4,4,4,5,4,4,4,4,5},        //4   
  6.     {6,6,6,7,6,6,6,6,5,6,6,6,5,5,6,6,5,5,5,6,5,5,5,5,4,5,5,5,5},        //5   
  7.     {6,6,7,7,6,6,6,7,6,6,6,6,5,6,6,6,5,5,6,6,5,5,5,6,5,5,5,5,4,5,5,5,5},//6   
  8.     {7,8,8,8,7,7,8,8,7,7,7,8,7,7,7,7,6,7,7,7,6,6,7,7,6,6,6,7,7},        //7   
  9.     {8,8,8,9,8,8,8,8,7,8,8,8,7,7,8,8,7,7,7,8,7,7,7,7,6,7,7,7,6,6,7,7,7},//8   
  10.     {8,8,8,9,8,8,8,8,7,8,8,8,7,7,8,8,7,7,7,8,7,7,7,7,6,7,7,7,7},        //9   
  11.     {9,9,9,9,8,9,9,9,8,8,9,9,8,8,8,9,8,8,8,8,7,8,8,8,7,7,8,8,8},        //10   
  12.     {8,8,8,8,7,8,8,8,7,7,8,8,7,7,7,8,7,7,7,7,6,7,7,7,6,6,7,7,7},        //11   
  13.     {7,8,8,8,7,7,8,8,7,7,7,8,7,7,7,7,6,7,7,7,6,6,7,7,6,6,6,7,7},        //12   
  14. }; //这个数据表表示了每个月第一个节气出现的规律   
  15. const unsigned char calendar_solar_term_year_01[12][9] = {   
  16.     {13,49,85,117,149,185,201,250,250}, //month 1   
  17.     {13,45,81,117,149,185,201,250,250}, //2   
  18.     {13,48,84,112,148,184,200,201,250}, //3   
  19.     {13,45,76,108,140,172,200,201,250}, //4   
  20.     {13,44,72,104,132,168,200,201,250}, //5   
  21.     {5 ,33,68,96 ,124,152,188,200,201}, //6   
  22.     {29,57,85,120,148,176,200,201,250}, //7   
  23.     {13,48,76,104,132,168,196,200,201}, //8   
  24.     {25,60,88,120,148,184,200,201,250}, //9   
  25.     {16,44,76,108,144,172,200,201,250}, //10   
  26.     {28,60,92,124,160,192,200,201,250}, //11   
  27.     {17,53,85,124,156,188,200,201,250}, //12   
  28. }; //这个数据表表示了每个月第一个节气出现规律对应的阳历年份范围   
  29. const unsigned char calendar_solar_term_table_02[12][29] = {   
  30.     {21,21,21,21,21,20,21,21,21,20,20,21,21,20,20,20,20,20,20,20,20,19,20,20,20,19,19},   
  31.     {20,19,19,20,20,19,19,19,19,19,19,19,19,18,19,19,19,18,18,19,19,18,18,18,18,18,18},   
  32.     {21,21,21,22,21,21,21,21,20,21,21,21,20,20,21,21,20,20,20,21,20,20,20,20,19,20,20},   
  33.     {20,21,21,21,20,20,21,21,20,20,20,21,20,20,20,20,19,20,20,20,19,19,20,20,19,19,19},   
  34.     {21,22,22,22,21,21,22,22,21,21,21,22,21,21,21,21,20,21,21,21,20,20,21,21,20,20,20},   
  35.     {22,22,22,22,21,22,22,22,21,21,22,22,21,21,21,22,21,21,21,21,20,21,21,21,20,20,21},   
  36.     {23,23,24,24,23,23,23,24,23,23,23,23,22,23,23,23,22,22,23,23,22,22,22,23,22,22,22},   
  37.     {23,24,24,24,23,23,24,24,23,23,23,24,23,23,23,23,22,23,23,23,22,22,23,23,22,22,22},   
  38.     {23,24,24,24,23,23,24,24,23,23,23,24,23,23,23,23,22,23,23,23,22,22,23,23,22,22,22},   
  39.     {24,24,24,24,23,24,24,24,23,23,24,24,23,23,23,24,23,23,23,23,22,23,23,23,22,22,23},   
  40.     {23,23,23,23,22,23,23,23,22,22,23,23,22,22,22,23,22,22,22,22,21,22,22,22,21,21,22},   
  41.     {22,22,23,23,22,22,22,23,22,22,22,22,21,22,22,22,21,21,22,22,21,21,21,22,21,21,21},   
  42. }; //这个数据表表示了每个月第二个节气出现的规律   
  43. const unsigned char calendar_solar_term_year_02[12][8] = {   
  44.     {13,45,81,113,149,185,201},{21,57,93,125,161,193,201},{21,56,88,120,152,188,200,20},   
  45.     {21,49,81,116,144,176,200,201},{17,49,77,112,140,168,200,201},   
  46.     {28,60,88,116,148,180,200,201},{25,53,84,112,144,172,200,201},   
  47.     {29,57,89,120,148,180,200,201},{17,45,73,108,140,168,200,201},   
  48.     {28,60,92,124,160,192,200,201},{16,44,80,112,148,180,200,201},   
  49.     {17,53,88,120,156,188,200,201},   
  50. };   
  51. //这个数据表表示了每个月第二个节气出现规律对应的阳历年份范围   

每个阳历月对应的两个农历节气出现的日期,可根据条件规律算法,分别由以下两个函数实现
 

 
  1. unsigned char calendar_calculate_solar_term_1(void)   
  2. {   
  3.     zpage unsigned char done_index;   
  4.     zpage unsigned char solar_term;   
  5.     done_index = 0;   
  6.     while(gc_solar_calendar_year >= calendar_solar_term_year_01[gc_solar_calendar_mon   
  7.         [done_index])    
  8.     {   
  9.         done_index++;   
  10.     }   
  11.     solar_term = calendar_solar_term_table_01[gc_solar_calendar_month - 1][4*done_ind   
  12.         gc_solar_calendar_year%4];   
  13.     if((gc_solar_calendar_year == 121)&&(gc_solar_calendar_month == 4))   
  14.         solar_term = 5;   
  15.     if((gc_solar_calendar_year == 132)&&(gc_solar_calendar_month == 4))   
  16.         solar_term = 5;   
  17.     if((gc_solar_calendar_year == 194)&&(gc_solar_calendar_month == 6))   
  18.         solar_term = 6;   
  19.     return(solar_term);   
  20. //计算阳历月对应的第一个节气   
  21. unsigned char calendar_calculate_solar_term_2(void)   
  22. {   
  23.     zpage unsigned char done_index;   
  24.     zpage unsigned char solar_term;   
  25.     done_index = 0;   
  26.     while(gc_solar_calendar_year >= calendar_solar_term_year_02[gc_solar_calendar_mon   
  27.         [done_index]){done_index++;}   
  28.     solar_term = calendar_solar_term_table_02[gc_solar_calendar_month - 1][4*done_ind   
  29.         gc_solar_calendar_year%4];   
  30.     if((gc_solar_calendar_year == 171)&&(gc_solar_calendar_month == 3))   
  31.         solar_term = 2;   
  32.     if((gc_solar_calendar_year == 181)&&(gc_solar_calendar_month == 5))   
  33.         solar_term = 2;   
  34.     return(solar_term);   
  35. //计算阳历月对应的第二个节气   

以上就是万年历的完整算法。它首先计算出对应阳历月第一天对应是星期几,然后根据数据压定,确定对应的阴历日期;而阴历节气,则有条件规律算法实现。

 
相关文章:

上一页 12
 
最新开源项目
 
 
  查看更多...  
 
本站相关产品   淘宝网店
 




 
  查看更多...  

 

本站程序由百合电子工作室开发和维护
Copyright @ baihe electric studio
渝ICP备09006681号-4