这是以前自己完ucos时弄的一个程序,就是浪费点空间; 因为不是做产品,所以也没有对代码效率考虑太多,楼主自己取舍。
/************************************************************************************************************/ /*阳历日和农历节气的对应关系 */ /*压缩节气数据表: */ /*根据规律可以得到四个数据表(每个阳历月有两个节气,每个节气需要两个数据表): */ /************************************************************************************************************/ INT8U calendar_solar_term_table_01[12][33] = { {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 {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 {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,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,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 {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 {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 {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 {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 {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 {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 {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 }; //这个数据表表示了每个月第一个节气出现的规律
INT8U calendar_solar_term_year_01[12][9] = { {13,49,85,117,149,185,201,250,250}, //month 1 {13,45,81,117,149,185,201,250,250}, //2 {13,48,84,112,148,184,200,201,250}, //3 {13,45,76,108,140,172,200,201,250}, //4 {13,44,72,104,132,168,200,201,250}, //5 {5 ,33,68,96 ,124,152,188,200,201}, //6 {29,57,85,120,148,176,200,201,250}, //7 {13,48,76,104,132,168,196,200,201}, //8 {25,60,88,120,148,184,200,201,250}, //9 {16,44,76,108,144,172,200,201,250}, //10 {28,60,92,124,160,192,200,201,250}, //11 {17,53,85,124,156,188,200,201,250}, //12 }; //这个数据表表示了每个月第一个节气出现规律对应的阳历年份范围
INT8U calendar_solar_term_table_02[12][29] = { {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,20}, {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,18}, {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,20,20}, {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,20,20}, {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,21,21}, {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,21,21}, {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,22,23}, {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,23,23}, {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,23,23}, {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,23,23}, {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,22,22}, {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,21,22},
}; //这个数据表表示了每个月第二个节气出现的规律
INT8U calendar_solar_term_year_02[12][8] = { {13,45,81,113,149,185,201}, {21,57,93,125,161,193,201}, {21,56,88,120,152,188,200,201}, {21,49,81,116,144,176,200,201}, {17,49,77,112,140,168,200,201}, {28,60,88,116,148,180,200,201}, {25,53,84,112,144,172,200,201}, {29,57,89,120,148,180,200,201}, {17,45,73,108,140,168,200,201}, {28,60,92,124,160,192,200,201}, {16,44,80,112,148,180,200,201}, {17,53,88,120,156,188,200,201}, };//这个数据表表示了每个月第二个节气出现规律对应的阳历年份范围
/************************************************************************************************************/ /*函 数:calendar_calculate_solar_term_1 */ /*输 入:solar_year,solar_month */ /*输 出:第一个节气出现的日期; */ /*函数说明:本函数用于计算给定年和月的第一个农历节日出现的节气,输入的年按-1900给定 */ /* 这个算法采用条件规律算法.给定的年和月信息是阳历,返回的日期也为阳历 */ /************************************************************************************************************/ INT8U calendar_calculate_solar_term_1(INT8U solar_year, INT8U solar_month) { INT8U done_index; INT8U solar_term; done_index = 0; while(solar_year >= calendar_solar_term_year_01[solar_month - 1][done_index]) { done_index++; if(done_index>8) break; //以防设置的年不在数据表格范围内; } solar_term = calendar_solar_term_table_01[solar_month - 1][4*done_index + solar_year%4]; if((solar_year == 121)&&(solar_month == 4))solar_term = 5; if((solar_year == 132)&&(solar_month == 4))solar_term = 5; if((solar_year == 194)&&(solar_month == 6))solar_term = 6; return(solar_term); }
/************************************************************************************************************/ /*函 数:calendar_calculate_solar_term_2 */ /*输 入:solar_year,solar_month */ /*输 出:第二个节气出现的日期; */ /*函数说明:本函数用于计算给定年和月的第二个农历节日出现的节气,输入的年按-1900给定 */ /* 这个算法采用条件规律算法.给定的年和月信息是阳历,返回的日期也为阳历 */ /************************************************************************************************************/ INT8U calendar_calculate_solar_term_2(INT8U solar_year, INT8U solar_month) { INT8U done_index; INT8U solar_term; done_index = 0; while(solar_year >= calendar_solar_term_year_02[solar_month - 1][done_index]) { done_index++; if(done_index>8) break; //以防设置的年不在数据表格范围内; } solar_term = calendar_solar_term_table_02[solar_month - 1][4*done_index + solar_year%4]; if((solar_year == 171)&&(solar_month == 3))solar_term = 21; if((solar_year == 181)&&(solar_month == 5))solar_term = 21; return(solar_term); } |