硬汉嵌入式论坛

 找回密码
 立即注册
查看: 1627|回复: 12
收起左侧

[其它] 分享个 二十四节气的计算方法

  [复制链接]

4

主题

160

回帖

172

积分

初级会员

积分
172
发表于 2022-4-12 12:45:44 | 显示全部楼层 |阅读模式
方法网上找的,公司网络不能上传文件。
就直接贴源码了。
#include "stdio.h"
#include "stdint.h"
#include "julian_day.h"

const int SLIGHT_COLD         = 0;   // 小寒

const int GREAT_COLD          = 1;   // 大寒

const int SPRING_BEGINS       = 2;   // 立春

const int THE_RAINS           = 3;   // 雨水

const int INSECTS_AWAKEN      = 4;   // 惊蛰

const int VERNAL_EQUINOX      = 5;    // 春分

const int CLEAR_AND_BRIGHT    = 6;    // 清明

const int GRAIN_RAIN          = 7;    // 谷雨

const int SUMMER_BEGINS       = 8;    // 立夏

const int GRAIN_BUDS          = 9;    // 小满

const int GRAIN_IN_EAR        = 10;    // 芒种

const int SUMMER_SOLSTICE     = 11;    // 夏至

const int SLIGHT_HEAT         = 12;    // 小暑

const int GREAT_HEAT          = 13;    // 大暑

const int AUTUMN_BEGINS       = 14;    // 立秋

const int STOPPING_THE_HEAT   = 15;   // 处暑

const int WHITE_DEWS          = 16;   // 白露

const int AUTUMN_EQUINOX      = 17;   // 秋分

const int COLD_DEWS           = 18;   // 寒露

const int HOAR_FROST_FALLS    = 19;   // 霜降

const int WINTER_BEGINS       = 20;   // 立冬

const int LIGHT_SNOW          = 21;   // 小雪

const int HEAVY_SNOW          = 22;   // 大雪

const int WINTER_SOLSTICE     = 23;   // 冬至


const char *jieqi_str[24] = {"小寒", "大寒", "立春", "雨水", "惊蛰", "春分", "清明", "谷雨", "立夏", "小满", "芒种", "夏至", "小暑", "大暑", "立秋", "处暑", "白露", "秋分", "寒露", "霜降", "立冬", "小雪", "大雪", "冬至"};

static double s_stAccInfo[] =

{

    0.00, 1272494.40, 2548020.60, 3830143.80, 5120226.60, 6420865.80,

    7732018.80, 9055272.60, 10388958.00, 11733065.40, 13084292.40,14441592.00,

    15800560.80, 17159347.20, 18513766.20, 19862002.20, 21201005.40,22529659.80,

    23846845.20, 25152606.00, 26447687.40, 27733451.40, 29011921.20,30285477.60

};


//已知1900年小寒时刻为1月6日02:05:00
const double base1900_SlightColdJD = 2415025.5868055555;

double CalculateSolarTermsByExp(int year, int st)

{

    if((st < 0) || (st > 24))

        return 0.0;



    double stJd = 365.24219878  * (year - 1900) + s_stAccInfo[st] / 86400.0;



    return base1900_SlightColdJD + stJd;

}

struct tm tm_time;
ln_date cdate1 = {0};
ln_date cdate2 = {0};
int main()
{
    int year;
    while(1)
    {
        printf("请输入一个年份,查询当年节气日期分布\r\n");
        scanf("%d", &year);
        
        for(int i=0; i < 24; i++)
        {
            double test = CalculateSolarTermsByExp(year, i);
            get_tm_from_julian(test, &tm_time);
            printf("当前节气 : %s  日期为: %d-%d-%d\r\n", jieqi_str, tm_time.tm_year + 1900, tm_time.tm_mon + 1, tm_time.tm_mday);        
        }   
    }
   
    return 0;
}







依赖的文件是儒略日的计算方法,从一个开源项目 抠出来的。

头文件:
/*
Copyright (C) 2000 Liam Girdwood <liam@nova-ioe.org>
Copyright (C) 2003 Fabien Ch閞eau

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/

#ifndef _JULIAN_DAY_H
#define _JULIAN_DAY_H

#ifdef __cplusplus
extern "C" {
#endif

#include <time.h>

#ifndef J2000
# define J2000 2451545.0
#endif

    // General Calendar Functions

    // Human readable (easy printf) date format
    typedef struct
    {
        int years;         /*!< Years. All values are valid */
        int months;        /*!< Months. Valid values : 1 (January) - 12 (December) */
        int days;         /*!< Days. Valid values 1 - 28,29,30,31 Depends on month.*/
        int hours;         /*!< Hours. Valid values 0 - 23. */
        int minutes;     /*!< Minutes. Valid values 0 - 59. */
        double seconds;    /*!< Seconds. Valid values 0 - 59.99999.... */
    }ln_date;


    /* Calculate the julian day from date.*/
    double get_julian_day(const ln_date * date);

    /* Calculate the date from the julian day. */
    void get_date(double JD, ln_date * date);

    /* Calculate day of the week. 0 = Sunday .. 6 = Saturday */
    unsigned int get_day_of_week (const ln_date *date);

    /* Calculate julian day from system time. */
    double get_julian_from_sys();

    /* Calculate gmt date from system date */
    void get_ln_date_from_sys(ln_date * date);

    // Obtains a ln_date from 2 strings s1 and s2 for date and time
    // with the form dd/mm/yyyy for s1 and hh:mm:ss.s for s2.
    // Returns NULL if s1 or s2 is not valid.
    // Uses the current date if s1 is "today" and current time if s2 is "now"
    const ln_date * str_to_date(const char * s1, const char * s2);

    // Calculate tm struct from julian day
    void get_tm_from_julian(double JD, struct tm * tm_time);

    // Calculate time_t from julian day
    time_t get_time_t_from_julian(double JD);

    // Return the number of hours to add to gmt time to get the local time
    // taking the parameters from system. This takes into account the daylight saving
    // time if there is.
    int get_gmt_shift_from_system(void);

    /* puts a large angle in the correct range 0 - 360 degrees */
    double range_degrees (double angle);

    /* puts a large angle in the correct range 0 - 2PI radians */
    double range_radians (double angle);


    /* Calculate mean sidereal time from date. */
    double get_mean_sidereal_time (double JD);

    /* Calculate apparent sidereal time from date.*/
    double get_apparent_sidereal_time (double JD);

    /* Input t is time in julian days.
     * Valid range is the years -8000 to +12000 (t = -100 to 100).
     * return mean obliquity (epsilon sub 0) in degrees.*/
    double get_mean_obliquity( double t );

    /* Calculate Earth globe centre distance. */
    void get_earth_centre_dist (float height, double latitude, double * p_sin_o, double * p_cos_o);


    /* Calculate the adjustment in altitude of a body due to atmospheric refraction. */
    double get_refraction_adj (double altitude, double atm_pres, double temp);


#ifdef __cplusplus
};
#endif


#endif /* _STELLASTRO_H */




源文件:
/*
Copyright (C) 2000 Liam Girdwood <liam@nova-ioe.org>
Copyright (C) 2003 Fabien Ch閞eau

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/

#include "julian_day.h"
#include <time.h>
#include <math.h>
#include <stdlib.h>

/* Calculate the julian day from a calendar day.
* Valid for positive and negative years but not for negative JD.
* Formula 7.1 on pg 61 */
// Code originally from libnova which appeared to be totally wrong... New code from celestia
double get_julian_day (const ln_date * cdate)
{
    ln_date date;
    int y, m, B;

    date = *cdate;

    y = date.years;
    m = date.months;
    if (date.months <= 2)
    {
        y = date.years - 1;
        m = date.months + 12;
    }

    // Correct for the lost days in Oct 1582 when the Gregorian calendar
    // replaced the Julian calendar.
    B = -2;
    if (date.years > 1582 || (date.years == 1582 && (date.months > 10 || (date.months == 10 && date.days >= 15))))
    {
        B = y / 400 - y / 100;
    }

    return (floor(365.25 * y) +
        floor(30.6001 * (m + 1)) + B + 1720996.5 +
        date.days + date.hours / 24.0 + date.minutes / 1440.0 + date.seconds / 86400.0);
}


/* Calculate the day of the week.
* Returns 0 = Sunday .. 6 = Saturday */
unsigned int get_day_of_week (const ln_date *date)
{
    double JD;
    /* get julian day */
    JD = get_julian_day(date) + 1.5;
    return (int)JD % 7;
}

// Calculate tm struct from julian day
void get_tm_from_julian(double JD, struct tm * tm_time)
{
    ln_date date;
    get_date(JD, &date);
    tm_time->tm_sec = (int)date.seconds;
    tm_time->tm_min = date.minutes;
    tm_time->tm_hour = date.hours;
    tm_time->tm_mday = date.days;
    tm_time->tm_mon = date.months - 1;
    tm_time->tm_year = date.years - 1900;
    tm_time->tm_isdst = -1;
}

/* Calculate the date from the Julian day
* params : JD Julian day, date Pointer to new calendar date. */
// Code originally from libnova which appeared to be totally wrong... New code from celestia
void get_date(double jd, ln_date * date)
{
    int a, d, e, f;
    double c, b;
    double dday, dhour, dminute;

    a = (int) (jd + 0.5);

    if (a < 2299161)
    {
        c = a + 1524;
    }
    else
    {
        b = (int) ((a - 1867216.25) / 36524.25);
        c = a + b - (int) (b / 4) + 1525;
    }

    d = (int) ((c - 122.1) / 365.25);
    e = (int) (365.25 * d);
    f = (int) ((c - e) / 30.6001);

    dday = c - e - (int) (30.6001 * f) + ((jd + 0.5) - (int) (jd + 0.5));

    /* This following used to be 14.0, but gcc was computing it incorrectly, so
    it was changed to 14 */
    date->months = f - 1 - 12 * (int) (f / 14);
    date->years = d - 4715 - (int) ((7.0 + date->months) / 10.0);
    date->days = (int) dday;

    dhour = (dday - date->days) * 24;
    date->hours = (int) dhour;

    dminute = (dhour - date->hours) * 60;
    date->minutes = (int) dminute;

    date->seconds = (dminute - date->minutes) * 60;
}


/* Calculate julian day from system time. */
double get_julian_from_sys(void)
{
    ln_date date;
    /* get sys date */
    get_ln_date_from_sys(&date);
    return get_julian_day(&date);
}


/* Calculate gmt date from system date.
* param : date Pointer to store date. */
void get_ln_date_from_sys(ln_date * date)
{
    time_t rawtime;
    struct tm * ptm;

    /* get current time */
    time ( &rawtime );

    /* convert to gmt time representation */
    ptm = gmtime ( &rawtime );

    /* fill in date struct */
    date->seconds = ptm->tm_sec;
    date->minutes = ptm->tm_min;
    date->hours = ptm->tm_hour;
    date->days = ptm->tm_mday;
    date->months = ptm->tm_mon + 1;
    date->years = ptm->tm_year + 1900;
}


// Calculate time_t from julian day
time_t get_time_t_from_julian(double JD)
{
    struct tm loctime;
    ln_date date;

    get_date(JD, &date);

    loctime.tm_sec = (int)date.seconds;
    loctime.tm_min = date.minutes;
    loctime.tm_hour = date.hours;
    loctime.tm_mday =date.days;
    loctime.tm_mon = date.months -1;
    loctime.tm_year = date.years - 1900;
    loctime.tm_isdst = -1;

    return mktime(&loctime);
}




评分

参与人数 1金币 +100 收起 理由
eric2013 + 100 很给力!

查看全部评分

回复

使用道具 举报

4

主题

160

回帖

172

积分

初级会员

积分
172
 楼主| 发表于 2022-4-12 12:47:40 | 显示全部楼层
1900年开的, 2100年之前 应该都是正确的。2222 年的 大雪貌似有可能不对,计算出来的是12月7日,网上搜的 有的是说7日,有的是说8日
回复

使用道具 举报

3

主题

110

回帖

119

积分

初级会员

积分
119
发表于 2022-4-12 15:25:13 | 显示全部楼层
直呼卧槽,学到了
回复

使用道具 举报

1万

主题

6万

回帖

10万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
106726
QQ
发表于 2022-4-12 15:39:19 | 显示全部楼层
谢谢分享,收藏路了
回复

使用道具 举报

4

主题

160

回帖

172

积分

初级会员

积分
172
 楼主| 发表于 2022-4-12 17:26:01 | 显示全部楼层
更换个以 2020年为基准的,这样基本保证 1950-2150年基本没问题,要是想更准确 可以再找一些数据 取平均。
测试,找个十几个年份比较了下,应该没问题。容易出错的就是那种:开始于23:00 - 00:30 之间的那种节气。
static double AccInfo_2020[24] =
{
        0.00,
        1272274.00,
        2547194.00,
        3828414.00,
        5117207.00,
        6416371.00,
        7726084.00,
        9047723.00,
        10380077.00,
        11722751.00,
        13073300.00,
        14429615.00,
        15788661.00,
        17147206.00,
        18502565.00,
        19851290.00,
        21191877.00,
        22521633.00,
        23840710.00,
        25147766.00,
        26444629.00,
        27731379.00,
        29011164.00,
        30285134.00       
};

//2020/01/06 05:30:04.41 小寒 太阳黄经285° 太阳赤纬-22°44′
const double base2020 = 2458854.729213;

double CalculateSolarTermsByExp(int year, int st)

{

        if((st < 0) || (st > 24))

                return 0.0;



        double stJd = 365.2422  * (year - 2020) + AccInfo_2020[st] / 86400.00;



        return base2020 + stJd;

}
回复

使用道具 举报

1

主题

66

回帖

69

积分

初级会员

积分
69
发表于 2022-4-13 09:24:39 | 显示全部楼层
我怎么感觉,节气的拼写,完全可以用拼音,英语翻译看着怪怪的
回复

使用道具 举报

41

主题

215

回帖

338

积分

高级会员

积分
338
发表于 2022-4-13 12:50:45 | 显示全部楼层
请问有没有公历的,以2020年开始的算法?
unix的时间从1970年开始,2038年到期。
回复

使用道具 举报

334

主题

2032

回帖

3039

积分

版主

Rank: 7Rank: 7Rank: 7

积分
3039
发表于 2022-4-13 13:46:54 | 显示全部楼层
很专业,牛!
回复

使用道具 举报

4

主题

160

回帖

172

积分

初级会员

积分
172
 楼主| 发表于 2022-4-13 15:10:49 | 显示全部楼层
snakeemail 发表于 2022-4-13 12:50
请问有没有公历的,以2020年开始的算法?
unix的时间从1970年开始,2038年到期。

就是阳历的,二十四节气是根据阳历算的。 1970年前也可以算
回复

使用道具 举报

56

主题

904

回帖

1072

积分

至尊会员

积分
1072
发表于 2022-4-16 21:50:37 | 显示全部楼层

/****************************************Copyright (c)**************************************************
**                              四川唐门高新技术开发有限公司
**                                     研    发    部
**                                独门暗器之孔雀翎研究室
**
**                                http://www.蜀中唐门.com
**
**                                   维护健康 信守诚诺
**
**--------------文件信息--------------------------------------------------------------------------------
**文   件   名: nongli.c
**创   建   人: 赖皮
**最后修改日期: 2011年10月
**描        述: 最强万年历   
**              支持所有的单片机、ARM、AVR、MSP430、PIC等(支持C开发)
**              可嵌入任何标准C编译器  BC++、VC、ADS、KEIL等
**用        法: 在ADS,Keil,BC++上可仿真
**
#include "nongli.c"
void main(void)
{
    unsigned char week;
    unsigned char NLyear[4];
    unsigned char JQdate;
             char str[15];

    while(1)
    {
        GetChinaCalendar   (2007,2,8,NLyear);  //NLyear={20,06,12,21}
        GetChinaCalendarStr(2007,2,8,str);     //str   ={"丙戌年腊月廿一"}
        GetWeek            (2007,2,8,&week);   //week  =4
        GetJieQi           (2007,2,8,&JQdate); //JQdate=4 意思为本月的4号是个节气
        GetJieQiStr        (2007,2,4,str);     //str   ={"立春"}
        GetJieQiStr        (2007,2,8,str);     //str   ={"离雨水还有11天"}
        GetShengXiaoStr    (2007,3,4,str);     //str   ={"猪"}
   }
}
**
**          LAI2005PI@126.com
********************************************************************************************************
**--------------历史版本信息----------------------------------------------------------------------------
** 创建人: 赖皮
** 版  本: v1.0
** 日 期: 2007年02月6日
** 描 述:
**          这是改写网友Campo的万年历C51。
**          原作使用了数组查表法,效率较高。
**          移植到ARM上,我改写了进入参数。返回采用指针传递
**          增加了天干地支转换              ★〓个人原创〓★
**          输入公历日期得到农历字符串       
**          非本人原创部分仅供研究与学习之用。如想商业使用,
**          请与原作者Campo联系——虽然我也不知道他的联系方式 ^o^
**                       
**★〓 仅以此献给我的宝贝女儿小涵,我的小狗狗要过第一个春节了 〓★
**★〓    任何人都可以发布和使用,希望保留本文件信息。谢谢    〓★
**         
**------------------------------------------------------------------------------------------------------
********************************************************************************************************
**--------------历史版本信息----------------------------------------------------------------------------
** 创建人: 赖皮
** 版  本: v2.0(情人节版)   我会在2月14日发布-->愿天下有情人终成眷属
**                                              愿和我一样已经进城的人幸福美满
** 日 期: 2007年02月8日
** 描 述:   
**          应网友的要求增加24节气的支持    ★〓个人原创〓★
**          为了节约空间我未采用复杂算法  而先把节气标志做了个表格(好累人哦)
**          一年的24个节气的日期只需要3个字节编码,每个bit对应一个节气 高->低
**          50年的节气表,只需要150个字节的存储空间
**          如果本月的节气日期等于基本日期 bit=0  else  bit=1
**
**★〓   仅以此献给我亲爱的刘筒, 我一定会给你种柚子和樱桃的   〓★
**★〓    任何人都可以发布和使用,希望保留本文件信息。谢谢    〓★
**         
**------------------------------------------------------------------------------------------------------
********************************************************************************************************
**--------------历史版本信息----------------------------------------------------------------------------
** 创建人: 赖皮
** 版  本: v3.0(元宵节版)   今天是元宵节
**                                         
** 日 期: 2007年03月04日
** 描 述:   
**          增加12生肖                       ★〓个人原创〓★
**          12生肖比较简单,只要知道12地支就可以了
**          子-->鼠,丑-->牛,寅-->虎 ...
**          鼠不分大小都喊老 (谁能对上)                  
**          增加移植选项,因为不同的平台要把常量表格定义到ROM段需要不同的关键字
**          目前只给出ARM、C51两种,用户可自己扩展
**
**★〓   仅以此献给我亲爱的妈老汉儿, 我一定会挣大钱的(未来)   〓★
**★〓    任何人都可以发布和使用,希望保留本文件信息。谢谢    〓★
**         
**------------------------------------------------------------------------------------------------------********************************************************************************************************
**--------------历史版本信息----------------------------------------------------------------------------
** 创建人: 赖皮
** 版  本: v3.1(2012版)   迎接2012
**                                         
** 日 期: 2011年10月
** 描 述:   
**         修正一些小bug
**
**★〓   仅以此献给我亲爱的妈妈, 希望你手术成功(肯定)         〓★
**★〓    任何人都可以发布和使用,希望保留本文件信息。谢谢    〓★
**         
**------------------------------------------------------------------------------------------------------
********************************************************************************************************
**--------------当前版本修订------------------------------------------------------------------------------
** 修改人:
** 版  本:
** 日 期:
** 描 述:   c++builder6.0  CPU_TYPE    可以用ARM      
**         
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/

/****************************************************************************
* 移植到不同平台需要改动的地方
* 可根据需要添加PIC、AVR等定义关键字
****************************************************************************/
#define     C51         0
#define     ARM         1  


#define     CPU_TYPE    ARM    // 用户根据不同平台指定 如果是51该处应改为 C51


#if CPU_TYPE ==  C51           
                   #define KeyWord        code   // 在C51下code 代码放到ROM段
#else
                #define KeyWord        const  // 在ARM下const代码放到ROM段
#endif
/* 剪裁相关不用的代码 */
#define JieQiEn             1  // 1:使能节气相关代码
#define ShengXiaoEn         1  // 1:使能生肖相关代码

static unsigned char KeyWord year_code[]={
0x04,0xAe,0x53, //1901 0
0x0A,0x57,0x48, //1902 3
0x55,0x26,0xBd, //1903 6
0x0d,0x26,0x50, //1904 9
0x0d,0x95,0x44, //1905 12
0x46,0xAA,0xB9, //1906 15
0x05,0x6A,0x4d, //1907 18
0x09,0xAd,0x42, //1908 21
0x24,0xAe,0xB6, //1909
0x04,0xAe,0x4A, //1910
0x6A,0x4d,0xBe, //1911
0x0A,0x4d,0x52, //1912
0x0d,0x25,0x46, //1913
0x5d,0x52,0xBA, //1914
0x0B,0x54,0x4e, //1915
0x0d,0x6A,0x43, //1916
0x29,0x6d,0x37, //1917
0x09,0x5B,0x4B, //1918
0x74,0x9B,0xC1, //1919
0x04,0x97,0x54, //1920
0x0A,0x4B,0x48, //1921
0x5B,0x25,0xBC, //1922
0x06,0xA5,0x50, //1923
0x06,0xd4,0x45, //1924
0x4A,0xdA,0xB8, //1925
0x02,0xB6,0x4d, //1926
0x09,0x57,0x42, //1927
0x24,0x97,0xB7, //1928
0x04,0x97,0x4A, //1929
0x66,0x4B,0x3e, //1930
0x0d,0x4A,0x51, //1931
0x0e,0xA5,0x46, //1932
0x56,0xd4,0xBA, //1933
0x05,0xAd,0x4e, //1934
0x02,0xB6,0x44, //1935
0x39,0x37,0x38, //1936
0x09,0x2e,0x4B, //1937
0x7C,0x96,0xBf, //1938
0x0C,0x95,0x53, //1939
0x0d,0x4A,0x48, //1940
0x6d,0xA5,0x3B, //1941
0x0B,0x55,0x4f, //1942
0x05,0x6A,0x45, //1943
0x4A,0xAd,0xB9, //1944
0x02,0x5d,0x4d, //1945
0x09,0x2d,0x42, //1946
0x2C,0x95,0xB6, //1947
0x0A,0x95,0x4A, //1948
0x7B,0x4A,0xBd, //1949
0x06,0xCA,0x51, //1950
0x0B,0x55,0x46, //1951
0x55,0x5A,0xBB, //1952
0x04,0xdA,0x4e, //1953
0x0A,0x5B,0x43, //1954
0x35,0x2B,0xB8, //1955
0x05,0x2B,0x4C, //1956
0x8A,0x95,0x3f, //1957
0x0e,0x95,0x52, //1958
0x06,0xAA,0x48, //1959
0x7A,0xd5,0x3C, //1960
0x0A,0xB5,0x4f, //1961
0x04,0xB6,0x45, //1962
0x4A,0x57,0x39, //1963
0x0A,0x57,0x4d, //1964
0x05,0x26,0x42, //1965
0x3e,0x93,0x35, //1966
0x0d,0x95,0x49, //1967
0x75,0xAA,0xBe, //1968
0x05,0x6A,0x51, //1969
0x09,0x6d,0x46, //1970
0x54,0xAe,0xBB, //1971
0x04,0xAd,0x4f, //1972
0x0A,0x4d,0x43, //1973
0x4d,0x26,0xB7, //1974
0x0d,0x25,0x4B, //1975
0x8d,0x52,0xBf, //1976
0x0B,0x54,0x52, //1977
0x0B,0x6A,0x47, //1978
0x69,0x6d,0x3C, //1979
0x09,0x5B,0x50, //1980
0x04,0x9B,0x45, //1981
0x4A,0x4B,0xB9, //1982
0x0A,0x4B,0x4d, //1983
0xAB,0x25,0xC2, //1984
0x06,0xA5,0x54, //1985
0x06,0xd4,0x49, //1986
0x6A,0xdA,0x3d, //1987
0x0A,0xB6,0x51, //1988
0x09,0x37,0x46, //1989
0x54,0x97,0xBB, //1990
0x04,0x97,0x4f, //1991
0x06,0x4B,0x44, //1992
0x36,0xA5,0x37, //1993
0x0e,0xA5,0x4A, //1994
0x86,0xB2,0xBf, //1995
0x05,0xAC,0x53, //1996
0x0A,0xB6,0x47, //1997
0x59,0x36,0xBC, //1998
0x09,0x2e,0x50, //1999 294
0x0C,0x96,0x45, //2000 297
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
};

/*月份数据表*/
static unsigned char  KeyWord day_code1[9]={0x0,0x1f,0x3b,0x5a,0x78,0x97,0xb5,0xd4,0xf3};
static unsigned short KeyWord day_code2[3]={0x111,0x130,0x14e};
/****************************************************************************
* 子函数,用于读取数据表中农历月的大月或小月,如果该月为大返回1,为小返回0
****************************************************************************/
static unsigned char GetMoonDay(unsigned char month_p,unsigned short 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);
        }
        return(0);
}

/*********************************************************************************************************
** 函数名称:GetChinaCalendar
** 功能描述:公农历转换(只允许1901-2099年)
** 输 入:  year        公历年
**          month       公历月
**          day         公历日
**          p           储存农历日期地址
** 输 出:  1           成功
**          0           失败
** 作 者:  Campo
** 修  改:  赖皮
** 日 期:  2007年02月06日
**-------------------------------------------------------------------------------------------------------
** 修改人:
** 日 期:
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
unsigned char GetChinaCalendar(
                                unsigned int  year,       
                                unsigned char month,
                                unsigned char day,
                                unsigned char *p)
{
        unsigned char temp1,temp2,temp3,month_p,yearH,yearL;       
        unsigned char flag_y;
        unsigned short temp4,table_addr;

        yearH=year/100;        yearL=year%100;
        if((yearH!=19)&&(yearH!=20))        return(0);
       
        /* 定位数据表地址 */
        table_addr=(int)(yearL-1)*3;
        if(yearH==20)        table_addr+=100*3;

        /* 取当年春节所在的公历月份 */
        temp1=year_code[table_addr+2]&0x60;       
        temp1>>=5;

        /* 取当年春节所在的公历日 */
        temp2=year_code[table_addr+2]&31;

        /* 计算当年春年离当年元旦的天数,春节只会在公历1月或2月 */
        if(temp1==1)         temp3=temp2-1;
        else                         temp3=temp2+31-1;

        /* 计算公历日离当年元旦的天数 */
        if (month<10)         temp4=day_code1[month-1]+day-1;
        else                          temp4=day_code2[month-10]+day-1;
        /* 如果公历月大于2月并且该年的2月为闰月,天数加1 */
        if ((month>2)&&(yearL%4==0))         temp4++;

        /* 判断公历日在春节前还是春节后 */
        if (temp4>=temp3)
        {                                                
                temp4-=temp3;
                month=1;
                month_p=1;
                                                       
                flag_y=0;
                if(GetMoonDay(month_p,table_addr)==0)        temp1=29; //小月29天
                else                                                                         temp1=30; //大小30天
                /* 从数据表中取该年的闰月月份,如为0则该年无闰月 */
                temp2=year_code[table_addr]/16;        
                while(temp4>=temp1)
                {
                        temp4-=temp1;
                        month_p++;
                        if(month==temp2)
                        {
                                flag_y=~flag_y;
                                if(flag_y==0)month++;
                        }
                        else month++;
                        if(GetMoonDay(month_p,table_addr)==0)        temp1=29;
                        else                                                                         temp1=30;
                }
                day=temp4+1;
        }
        /* 公历日在春节前使用下面代码进行运算 */
        else
        {                                                
                temp3-=temp4;
                if (yearL==0)
                {
                        yearL=100-1;
                        yearH=19;
                }
                else yearL--;
                table_addr-=3;
                month=12;
                temp2=year_code[table_addr]/16;        
                if (temp2==0)        month_p=12;
                else                         month_p=13;

                flag_y=0;
                if(GetMoonDay(month_p,table_addr)==0)        temp1=29;
                else                                                                         temp1=30;
                while(temp3>temp1)
                {
                        temp3-=temp1;
                        month_p--;
                        if(flag_y==0)                month--;
                        if(month==temp2)        flag_y=~flag_y;
                        if(GetMoonDay(month_p,table_addr)==0)        temp1=29;
                        else                                                                         temp1=30;
                }
                day=temp1-temp3+1;
        }

        *p++=yearH;
        *p++=yearL;
        *p++=month;
        *p=day;       
        return(1);
}

static unsigned char KeyWord table_week[12]={0,3,3,6,1,4,6,2,5,0,3,5}; //月修正数据表
/*********************************************************************************************************
** 函数名称:GetWeek
** 功能描述:输入公历日期得到星期(只允许1901-2099年)
** 输 入:  year        公历年
**          month       公历月
**          day                公历日
**          week        储存星期地址
** 输 出:  无
** 作 者:  Campo
** 修  改:  赖皮
** 日 期:  2007年02月06日
**-------------------------------------------------------------------------------------------------------
** 修改人:
** 日 期:
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
void GetWeek(
                        unsigned int year,
                        unsigned char month,
                        unsigned char day,
                        unsigned char *week)
{       
        unsigned int temp2;
        unsigned char yearH,yearL;
       
        yearH=year/100;        yearL=year%100;
       
        /* 如果为21世纪,年份数加100 */
        if (yearH>19)                 yearL+=100;
        /* 所过闰年数只算1900年之后的 */
        temp2=yearL+yearL/4;
        temp2=temp2%7;
        temp2=temp2+day+table_week[month-1];
        if (yearL%4==0&&month<3)        temp2--;
        *week=(temp2%7);
}

/*********************************************************************************************************
** 函数名称:GetSkyEarth
** 功能描述:输入公历日期得到一个甲子年(只允许1901-2099年)
** 输 入:  year        公历年
**          p           储存一个甲子年地址
** 输 出:  无
** 作 者:  赖皮        ★〓个人原创〓★
** 日 期:  2007年02月06日
**-------------------------------------------------------------------------------------------------------
** 修改人:
** 日 期:
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
static void GetSkyEarth(unsigned int year,unsigned char *p)
{
        unsigned char x;
       
        if(year>=1984)
        {
                year=year-1984;
                x=year%60;                               
        }
        else
        {
                year=1984-year;
                x=60-year%60;
        }
        *p=x;
}
static unsigned char KeyWord sky[][3]=  {"甲","乙","丙","丁","戊","己","庚","辛","壬","癸",};
static unsigned char KeyWord earth[][3]={"子","丑","寅","卯","辰","巳","午","未","申","酉","戌","亥",};
static unsigned char KeyWord monthcode[][3]={"一","二","三","四","五","六","七","八","九","十","冬","腊",};
static unsigned char KeyWord nongliday[][3]={"初","十","廿","三",};

#if CPU_TYPE == C51
static void StrCopy(char *target,unsigned char const *source,unsigned char no)
#else
static void StrCopy(char *target,unsigned char const *source,unsigned int no)
#endif
{
#if CPU_TYPE == C51
    unsigned char i;
#else
    unsigned int i;
#endif
       
        for(i = 0; i < no; i++)
        {
                *target++=*source++;
        }
}
/*********************************************************************************************************
** 函数名称:GetChinaCalendarStr
** 功能描述:输入公历日期得到农历字符串       
**          如:GetChinaCalendarStr(2007,02,06,str) 返回str="丙戌年腊月十九"
** 输 入:  year        公历年
**          month       公历月
**          day         公历日
**          str         储存农历日期字符串地址   15Byte
** 输 出:  无
** 作 者:  赖皮        ★〓个人原创〓★
** 日 期:  2007年02月06日
**-------------------------------------------------------------------------------------------------------
** 修改人:
** 日 期:
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
void GetChinaCalendarStr(
                        unsigned int  year,       
                        unsigned char month,
                        unsigned char day,
                                 char *str)
{
        unsigned char NLyear[4];
        unsigned char SEyear;
       
        StrCopy(&str[0],(unsigned char *)"甲子年正月初一",15);
        if(GetChinaCalendar(year,month,day,(unsigned char *)NLyear)==0)        return;
        GetSkyEarth(NLyear[0]*100+NLyear[1],&SEyear);
        StrCopy(&str[0],(unsigned char *)  sky[SEyear%10],2);        //  甲
        StrCopy(&str[2],(unsigned char *)earth[SEyear%12],2);        //  子       
       
        if(NLyear[2]==1)        StrCopy(&str[6],(unsigned char *)"正",2);
        else                                StrCopy(&str[6],(unsigned char *)monthcode[NLyear[2]-1],2);               
       
        if(NLyear[3]>10)         StrCopy(&str[10],(unsigned char *)nongliday[NLyear[3]/10],2);       
        else                                StrCopy(&str[10],(unsigned char *)"初",2);
        StrCopy(&str[12],(unsigned char *)monthcode[(NLyear[3]-1)%10],2);
}

/*********************************************************************************************************
**         以下为24节气计算相关程序
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/

#if  JieQiEn == 1
/*  
    每年24节气标志表   
    有兴趣的朋友可按照上面给的原理添加其它年份的表格
    不是很清楚的朋友可给我发EMAIL
*/
static unsigned char KeyWord YearMonthBit[]=
{
        0x4E,0xA6,0x99,                //2000
        0x9C,0xA2,0x98,                //2001
        0x80,0x00,0x18,                //2002
        0x00,0x10,0x24,                //2003
        0x4E,0xA6,0x99,                //2004
        0x9C,0xA2,0x98,                //2005
        0x80,0x82,0x18,                //2006
        0x00,0x10,0x24,                //2007
        0x4E,0xA6,0xD9,                //2008
        0x9E,0xA2,0x98,                //2009

        0x80,0x82,0x18,                //2010
        0x00,0x10,0x04,                //2011
        0x4E,0xE6,0xD9,                //2012
        0x9E,0xA6,0xA8,                //2013
        0x80,0x82,0x18,                //2014
        0x00,0x10,0x00,                //2015
        0x0F,0xE6,0xD9,                //2016
        0xBE,0xA6,0x98,                //2017
        0x88,0x82,0x18,                //2018
        0x80,0x00,0x00,                //2019

        0x0F,0xEF,0xD9,                //2020
        0xBE,0xA6,0x99,                //2021
        0x8C,0x82,0x98,                //2022
        0x80,0x00,0x00,                //2023
        0x0F,0xEF,0xDB,                //2024
        0xBE,0xA6,0x99,                //2025
        0x9C,0xA2,0x98,                //2026
        0x80,0x00,0x18,                //2027
        0x0F,0xEF,0xDB,                //2028
        0xBE,0xA6,0x99,                //2029

        0x9C,0xA2,0x98,                //2030
        0x80,0x00,0x18,                //2031
        0x0F,0xEF,0xDB,                //2032
        0xBE,0xA2,0x99,                //2033
        0x8C,0xA0,0x98,                //2034
        0x80,0x82,0x18,                //2035
        0x0B,0xEF,0xDB,                //2036
        0xBE,0xA6,0x99,                //2037
        0x8C,0xA2,0x98,                //2038
        0x80,0x82,0x18,                //2039

        0x0F,0xEF,0xDB,                //2040
        0xBE,0xE6,0xD9,                //2041
        0x9E,0xA2,0x98,                //2042
        0x80,0x82,0x18,                //2043
        0x0F,0xEF,0xFB,                //2044
        0xBF,0xE6,0xD9,                //2045
        0x9E,0xA6,0x98,                //2046
        0x80,0x82,0x18,                //2047
        0x0F,0xFF,0xFF,                //2048
        0xFC,0xEF,0xD9,                //2049
        0xBE,0xA6,0x18,                //2050
};
static unsigned char KeyWord days[]=
{
        6,20,4,19,6,21,         //一月到三月  的节气基本日期
        5,20,6,21,6,21,         //四月到六月  的节气基本日期
        7,23,8,23,8,23,         //七月到九月  的节气基本日期
        8,24,8,22,7,22,         //十月到十二月的节气基本日期
};
static char KeyWord JieQiStr[][5]=  //以公历日期先后排序
{
/*  名称        角度    公历日期     周期 */
        "小寒",     //285     1月 6日
        "大寒",     //300     1月20日    29.5天
        "立春",     //315     2月 4日
        "雨水",     //330     2月19日    29.8天
        "惊蛰",     //345     3月 6日
        "春分",     //  0     3月21日    30.2天
        "清明",     // 15     4月 5日
        "谷雨",     // 30     4月20日    30.7天
        "立夏",     // 45     5月 6日
        "夏满",     // 60     5月21日    31.2天
        "芒种",     // 75     6月 6日
        "夏至",     // 90     6月21日    31.4天
        "小暑",     //105     7月 7日
        "大暑",     //120     7月23日    31.4天
        "立秋",     //135     8月 8日
        "处暑",     //150     8月23日    31.1天
        "白露",     //165     9月 8日
        "秋分",     //180     9月23日    30.7天
        "寒露",     //195    10月 8日
        "霜降",     //210    10月24日    30.1天
        "立冬",     //225    11月 8日
        "小雪",     //240    11月22日    29.7天
        "大雪",     //255    12月 7日
        "冬至",     //270    12月22日    29.5天
};
/*********************************************************************************************************
** 函数名称:GetJieQi
** 功能描述:输入公历日期得到本月24节气日期 day<15返回上半月节气,反之返回下半月       
**          如:GetJieQiStr(2007,02,08,str) 返回str[0]=4
** 输 入:  year        公历年
**          month       公历月
**          day         公历日
**          str         储存对应本月节气日期地址   1Byte
** 输 出:  1           成功
**          0           失败
** 作 者:  赖皮        ★〓个人原创〓★
** 日 期:  2007年02月08日
**-------------------------------------------------------------------------------------------------------
** 修改人:
** 日 期:
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
unsigned char GetJieQi(
                        unsigned  int year,
                        unsigned char month,
                        unsigned char day,
                        unsigned char *JQdate)
{
        unsigned char bak1,value,JQ;

        if((year<2000)||(year>2050))     return 0;
        if((month==0) ||(month>12))      return 0;
        JQ = (month-1) *2 ;                                        //获得节气顺序标号(0~23
        if(day >= 15) JQ++;                                 //判断是否是上半月

        bak1=YearMonthBit[(year-2000)*3+JQ/8];          //获得节气日期相对值所在字节
        value =((bak1<<(JQ%8))&0x80);                   //获得节气日期相对值状态

        *JQdate=days[JQ];
        if( value != 0 )
        {
                //判断年份,以决定节气相对值1代表1,还是-1。
                if( (JQ== 1||JQ== 11||JQ== 18||JQ== 21)&&year< 2044)  (*JQdate)++;
                else                                                  (*JQdate)--;
        }
        return 1;
}
static unsigned char KeyWord MonthDayMax[]={31,28,31,30,31,30,31,31,30,31,30,31,};
/*********************************************************************************************************
** 函数名称:GetJieQiStr
** 功能描述:输入公历日期得到24节气字符串       
**          如:GetJieQiStr(2007,02,08,str) 返回str="离雨水还有11天"
** 输 入:  year        公历年
**          month       公历月
**          day         公历日
**          str         储存24节气字符串地址   15Byte
** 输 出:  1           成功
**          0           失败
** 作 者:  赖皮        ★〓个人原创〓★
** 日 期:  2007年02月08日
**-------------------------------------------------------------------------------------------------------
** 修改人:
** 日 期:
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
unsigned char GetJieQiStr(
                        unsigned int year,
                        unsigned char month,
                        unsigned char day,
                                 char *str)
{
        unsigned char JQdate,JQ,MaxDay;

        if(GetJieQi(year,month,day,&JQdate)==0)        return 0;

        JQ = (month-1) *2 ;                             //获得节气顺序标号(0~23
        if(day >= 15) JQ++;                             //判断是否是上半月

        if(day==JQdate)                                 //今天正是一个节气日
        {
                StrCopy(str,(unsigned char *)JieQiStr[JQ],5);
                return 1;
        }
                                                        //今天不是一个节气日
        StrCopy(str,(unsigned char *)"离小寒还有??天",15);
        if(day<JQdate)                                  //如果今天日期小于本月的节气日期
        {
                StrCopy(&str[2],(unsigned char *)JieQiStr[JQ],4);
                day=JQdate-day;
        }
        else                                            //如果今天日期大于本月的节气日期
        {
                StrCopy(&str[2],(unsigned char *)JieQiStr[(JQ+1)%24],4);   
                                                        //每年只有24个节气 此处需限定 冬至翻转会溢出
                if(day < 15)
                {
                        GetJieQi(year,month,15,&JQdate);
                        day=JQdate-day;
                }
                else                                        //翻月
                {
                        MaxDay=MonthDayMax[month-1];
                        if(month==2)                            //润月问题
                        {
                                if((year%4==0)&&((year%100!=0)||(year%400==0))) MaxDay++;
                        }
                        if(++month==13)        month=1;
                        GetJieQi(year,month,1,&JQdate);
                        day=MaxDay-day+JQdate;
                }
        }
        str[10]=day/10+'0';
        str[11]=day%10+'0';
        return 1;
}
#endif
/*********************************************************************************************************
**         以下为12生肖计算相关程序
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
#if  ShengXiaoEn == 1
static char KeyWord ShengXiao[][3]=
{
        "鼠","牛","虎","兔","龙","蛇",
        "马","羊","猴","鸡","狗","猪",
};
/*********************************************************************************************************
** 函数名称:GetShengXiaoStr
** 功能描述:输入公历日期得到12生肖字符串       
**          如:GetShengXiaoStr    (2007,3,4,str);     //str   ={"猪"}
** 输 入:  year        公历年
**          month       公历月
**          day         公历日
**          str         储存12生肖字符串地址   3Byte
** 输 出:  无
** 作 者:  赖皮        ★〓个人原创〓★
** 日 期:  2007年03月04日
**-------------------------------------------------------------------------------------------------------
** 修改人:
** 日 期:
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
void GetShengXiaoStr(
                        unsigned int  year,       
                        unsigned char month,
                        unsigned char day,
                                 char *str)
{
        unsigned char NLyear[4];
        unsigned char SEyear;
       
        if(GetChinaCalendar(year,month,day,(unsigned char *)NLyear)==0)        return;
        GetSkyEarth(NLyear[0]*100+NLyear[1],&SEyear);       
        StrCopy(str,(unsigned char *)ShengXiao[SEyear%12],3);
}
#endif
回复

使用道具 举报

56

主题

904

回帖

1072

积分

至尊会员

积分
1072
发表于 2022-4-16 21:51:01 | 显示全部楼层

/****************************************Copyright (c)**************************************************
**                              四川唐门高新技术开发有限公司
**                                     研    发    部
**                                独门暗器之孔雀翎研究室
**
**                                http://www.蜀中唐门.com
**
**                                   维护健康 信守诚诺
**
**--------------文件信息--------------------------------------------------------------------------------
**文   件   名: nongli.c
**创   建   人: 赖皮
**最后修改日期: 2011年10月
**描        述: 最强万年历   
**              支持所有的单片机、ARM、AVR、MSP430、PIC等(支持C开发)
**              可嵌入任何标准C编译器  BC++、VC、ADS、KEIL等
**用        法: 在ADS,Keil,BC++上可仿真
**
#include "nongli.c"
void main(void)
{
    unsigned char week;
    unsigned char NLyear[4];
    unsigned char JQdate;
             char str[15];

    while(1)
    {
        GetChinaCalendar   (2007,2,8,NLyear);  //NLyear={20,06,12,21}
        GetChinaCalendarStr(2007,2,8,str);     //str   ={"丙戌年腊月廿一"}
        GetWeek            (2007,2,8,&week);   //week  =4
        GetJieQi           (2007,2,8,&JQdate); //JQdate=4 意思为本月的4号是个节气
        GetJieQiStr        (2007,2,4,str);     //str   ={"立春"}
        GetJieQiStr        (2007,2,8,str);     //str   ={"离雨水还有11天"}
        GetShengXiaoStr    (2007,3,4,str);     //str   ={"猪"}
   }
}
**
**          LAI2005PI@126.com
********************************************************************************************************
**--------------历史版本信息----------------------------------------------------------------------------
** 创建人: 赖皮
** 版  本: v1.0
** 日 期: 2007年02月6日
** 描 述:
**          这是改写网友Campo的万年历C51。
**          原作使用了数组查表法,效率较高。
**          移植到ARM上,我改写了进入参数。返回采用指针传递
**          增加了天干地支转换              ★〓个人原创〓★
**          输入公历日期得到农历字符串       
**          非本人原创部分仅供研究与学习之用。如想商业使用,
**          请与原作者Campo联系——虽然我也不知道他的联系方式 ^o^
**                       
**★〓 仅以此献给我的宝贝女儿小涵,我的小狗狗要过第一个春节了 〓★
**★〓    任何人都可以发布和使用,希望保留本文件信息。谢谢    〓★
**         
**------------------------------------------------------------------------------------------------------
********************************************************************************************************
**--------------历史版本信息----------------------------------------------------------------------------
** 创建人: 赖皮
** 版  本: v2.0(情人节版)   我会在2月14日发布-->愿天下有情人终成眷属
**                                              愿和我一样已经进城的人幸福美满
** 日 期: 2007年02月8日
** 描 述:   
**          应网友的要求增加24节气的支持    ★〓个人原创〓★
**          为了节约空间我未采用复杂算法  而先把节气标志做了个表格(好累人哦)
**          一年的24个节气的日期只需要3个字节编码,每个bit对应一个节气 高->低
**          50年的节气表,只需要150个字节的存储空间
**          如果本月的节气日期等于基本日期 bit=0  else  bit=1
**
**★〓   仅以此献给我亲爱的刘筒, 我一定会给你种柚子和樱桃的   〓★
**★〓    任何人都可以发布和使用,希望保留本文件信息。谢谢    〓★
**         
**------------------------------------------------------------------------------------------------------
********************************************************************************************************
**--------------历史版本信息----------------------------------------------------------------------------
** 创建人: 赖皮
** 版  本: v3.0(元宵节版)   今天是元宵节
**                                         
** 日 期: 2007年03月04日
** 描 述:   
**          增加12生肖                       ★〓个人原创〓★
**          12生肖比较简单,只要知道12地支就可以了
**          子-->鼠,丑-->牛,寅-->虎 ...
**          鼠不分大小都喊老 (谁能对上)                  
**          增加移植选项,因为不同的平台要把常量表格定义到ROM段需要不同的关键字
**          目前只给出ARM、C51两种,用户可自己扩展
**
**★〓   仅以此献给我亲爱的妈老汉儿, 我一定会挣大钱的(未来)   〓★
**★〓    任何人都可以发布和使用,希望保留本文件信息。谢谢    〓★
**         
**------------------------------------------------------------------------------------------------------********************************************************************************************************
**--------------历史版本信息----------------------------------------------------------------------------
** 创建人: 赖皮
** 版  本: v3.1(2012版)   迎接2012
**                                         
** 日 期: 2011年10月
** 描 述:   
**         修正一些小bug
**
**★〓   仅以此献给我亲爱的妈妈, 希望你手术成功(肯定)         〓★
**★〓    任何人都可以发布和使用,希望保留本文件信息。谢谢    〓★
**         
**------------------------------------------------------------------------------------------------------
********************************************************************************************************
**--------------当前版本修订------------------------------------------------------------------------------
** 修改人:
** 版  本:
** 日 期:
** 描 述:  
**         
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/

/*********************************************************************************************************
** 函数名称:GetChinaCalendar
** 功能描述:公农历转换(只允许1901-2099年)
** 输 入:  year        公历年
**          month       公历月
**          day         公历日
**          p           储存农历日期地址
** 输 出:  1           成功
**          0           失败
** 作 者:  Campo
** 修  改:  赖皮
** 日 期:  2007年02月06日
**-------------------------------------------------------------------------------------------------------
** 修改人:
** 日 期:
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
extern unsigned char GetChinaCalendar(
                                unsigned int  year,       
                                unsigned char month,
                                unsigned char day,
                                unsigned char *p);
/*********************************************************************************************************
** 函数名称:GetWeek
** 功能描述:输入公历日期得到星期(只允许1901-2099年)
** 输 入:  year        公历年
**          month       公历月
**          day                公历日
**          week        储存星期地址
** 输 出:  无
** 作 者:  Campo
** 修  改:  赖皮
** 日 期:  2007年02月06日
**-------------------------------------------------------------------------------------------------------
** 修改人:
** 日 期:
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
extern void GetWeek(
                        unsigned int year,
                        unsigned char month,
                        unsigned char day,
                        unsigned char *week);
/*********************************************************************************************************
** 函数名称:GetChinaCalendarStr
** 功能描述:输入公历日期得到农历字符串       
**          如:GetChinaCalendarStr(2007,02,06,str) 返回str="丙戌年腊月十九"
** 输 入:  year        公历年
**          month       公历月
**          day         公历日
**          str         储存农历日期字符串地址   15Byte
** 输 出:  无
** 作 者:  赖皮        ★〓个人原创〓★
** 日 期:  2007年02月06日
**-------------------------------------------------------------------------------------------------------
** 修改人:
** 日 期:
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
extern void GetChinaCalendarStr(
                        unsigned int  year,       
                        unsigned char month,
                        unsigned char day,
                                 char *str);

/*********************************************************************************************************
** 函数名称:GetJieQi
** 功能描述:输入公历日期得到本月24节气日期 day<15返回上半月节气,反之返回下半月       
**          如:GetJieQiStr(2007,02,08,str) 返回str[0]=4
** 输 入:  year        公历年
**          month       公历月
**          day         公历日
**          str         储存对应本月节气日期地址   1Byte
** 输 出:  1           成功
**          0           失败
** 作 者:  赖皮        ★〓个人原创〓★
** 日 期:  2007年02月08日
**-------------------------------------------------------------------------------------------------------
** 修改人:
** 日 期:
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
extern unsigned char GetJieQi(
                        unsigned  int year,
                        unsigned char month,
                        unsigned char day,
                        unsigned char *JQdate);
/*********************************************************************************************************
** 函数名称:GetJieQiStr
** 功能描述:输入公历日期得到24节气字符串       
**          如:GetJieQiStr(2007,02,08,str) 返回str="离雨水还有11天"
** 输 入:  year        公历年
**          month       公历月
**          day         公历日
**          str         储存24节气字符串地址   15Byte
** 输 出:  1           成功
**          0           失败
** 作 者:  赖皮        ★〓个人原创〓★
** 日 期:  2007年02月08日
**-------------------------------------------------------------------------------------------------------
** 修改人:
** 日 期:
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
extern unsigned char GetJieQiStr(
                        unsigned int year,
                        unsigned char month,
                        unsigned char day,
                                 char *str);
/*********************************************************************************************************
** 函数名称:GetShengXiaoStr
** 功能描述:输入公历日期得到12生肖字符串       
**          如:GetShengXiaoStr    (2007,3,4,str);     //str   ={"猪"}
** 输 入:  year        公历年
**          month       公历月
**          day         公历日
**          str         储存12生肖字符串地址   3Byte
** 输 出:  无
** 作 者:  赖皮        ★〓个人原创〓★
** 日 期:  2007年03月04日
**-------------------------------------------------------------------------------------------------------
** 修改人:
** 日 期:
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
extern void GetShengXiaoStr(
                        unsigned int  year,       
                        unsigned char month,
                        unsigned char day,
                                 char *str);                          
回复

使用道具 举报

56

主题

904

回帖

1072

积分

至尊会员

积分
1072
发表于 2022-4-16 21:51:40 | 显示全部楼层
bcb测试ok
回复

使用道具 举报

6

主题

636

回帖

654

积分

金牌会员

积分
654
QQ
发表于 2022-4-29 23:22:24 | 显示全部楼层
感谢分享
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|Archiver|手机版|硬汉嵌入式论坛

GMT+8, 2024-5-2 11:08 , Processed in 0.358189 second(s), 38 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2023, Tencent Cloud.

快速回复 返回顶部 返回列表