农历阳历之间转换和节气节日查询C语言编程

合集下载

C 万年历及公历农历转换源代码1

C  万年历及公历农历转换源代码1

scanf("%d.%d.%d",&gyear,&gmonth,&gday); if(gyear%4==0 && gyear%100!=0 || gyear%400==0) months[2]=29; else months[2]=28; /*以下是计算在该公历年的第几天*/
whatday=gPastday[gmonth]+gday; if((gyear%4==0 && gyear%100!=0 || gyear%400==0) && (gmonth>2)) whatday++; /*上如果是闰年和月份大于二则在该公历年的第几天数+1*/ /*计算该年春节在公历年的第几天*/
clrscr();
}
}
getch();
}
/*公历每月前面的天数*/ const int gPastday[13]={0,0,31,59,90,120,151,181,212,243,273,304,334};
months[13]={0,31,0,31,30,31,30,31,31,30,31,30,31};
{case 1:printf("
* 1 * "); break;
case 3:printf("
* 3 * "); break;
case 5:printf("
* 5 * "); break;
case 7:printf("
* 7 * "); break;
case 9:printf("
* 9 * ");break;
{

公历转换成农历c语言函数

公历转换成农历c语言函数

公历转换成农历c语言函数在进行农历与公历的转换时,使用C语言编写一个函数可以很方便地实现这一功能。

本文将为您介绍一个简单而有效的公历转换成农历的C语言函数。

函数名称:solarToLunar功能:将公历日期转换成农历日期输入参数:int year(公历年份),int month(公历月份),int day (公历日)返回值:char*(农历日期)```c#include<stdio.h>#include<stdlib.h>// 农历数据结构体typedef struct LunarDate {int year;int month;int day;} LunarDate;// 公历转换成农历函数char* solarToLunar(int year, int month, int day) {/* 在这里编写您的代码 */}int main() {int year, month, day;printf("请输入公历年份:");scanf("%d", &year);printf("请输入公历月份:");scanf("%d", &month);printf("请输入公历日期:");scanf("%d", &day);char* lunarDate = solarToLunar(year, month, day); printf("农历日期:%s\n", lunarDate);free(lunarDate); // 释放内存return 0;}```在程序中,我们使用了一个结构体LunarDate来表示农历日期,它包含了年、月、日三个变量。

函数solarToLunar负责将公历日期转换成农历日期,并以字符串形式返回。

接下来,我们需要在函数solarToLunar中编写转换逻辑。

用c语言编写万年历思路

用c语言编写万年历思路

用c语言编写万年历思路摘要:一、万年历的概念及用途1.万年历的定义2.万年历的用途二、用C语言编写万年历的思路1.确定编写目标2.分析万年历的组成结构3.编写C语言程序实现万年历功能4.测试与优化三、万年历编写的具体步骤1.定义数据结构2.计算天数3.生成日历4.输出结果四、编写万年历的注意事项1.闰年的处理2.月份与星期的转换3.输出的格式正文:一、万年历的概念及用途万年历,又称历书,是一种历法书籍。

它详细地记录了每一年的阳历、阴历、节气、朔望等天文数据,方便人们查询和对照。

在我国,万年历有着悠久的历史,被广泛用于农业、民俗、天文观测等领域。

二、用C语言编写万年历的思路1.确定编写目标:使用C语言编写一个具有查询功能的万年历程序,方便用户查询日历、节日等信息。

2.分析万年历的组成结构:万年历主要包括阳历、阴历、节气、朔望等部分。

首先需要确定各个部分的数据结构,然后计算相关数据。

3.编写C语言程序实现万年历功能:根据分析结果,编写C语言程序,计算并生成万年历。

4.测试与优化:对编写好的程序进行测试,确保其正确性。

在测试过程中,针对发现的问题进行优化,提高程序的性能。

三、万年历编写的具体步骤1.定义数据结构:为了便于编写程序,需要先定义相关的数据结构。

例如,可以用数组表示年份的闰年情况,用结构体表示日历等。

2.计算天数:根据公历、农历的计算方法,计算某一年或某一个月的天数。

这涉及到闰年的判断、月份与星期的转换等计算。

3.生成日历:根据计算出的天数,生成日历。

这一步需要将日历按照一定的格式输出,例如,按照周或月为单位进行分组。

4.输出结果:将生成的日历输出到屏幕或文件中,供用户查看。

四、编写万年历的注意事项1.闰年的处理:闰年的判断方法有多种,需要根据实际情况选择合适的算法。

在C语言程序中,可以使用if语句进行闰年的判断。

2.月份与星期的转换:在计算天数的过程中,需要将月份与星期进行转换。

例如,某个月的1号可能是上一年的最后一天,也可能是这一年的第一天。

c语言公历转农历算法

c语言公历转农历算法

c语言公历转农历算法
公历和农历是两种不同的历法系统,公历是以太阳运行为基础的历法,而农历则是以月亮运行为基础的历法。

在一些特殊的场合,我们
可能需要将公历日期转换为农历日期,这就需要用到C语言编写的公
历转农历算法。

公历转农历的算法可以分为两个步骤:首先是计算公历日期到农历
起始点(即农历1900年1月31日)的天数差,然后根据这个天数差计算出对应的农历日期。

首先,我们需要定义一个结构体来表示农历日期,包括年、月、日
和是否闰月等信息。

然后,我们可以编写一个函数来计算公历日期到
农历起始点的天数差。

这个函数可以使用公历日期的年、月、日作为
参数,然后通过一系列的计算来得到天数差。

接下来,我们可以编写另一个函数来根据天数差计算出对应的农历
日期。

这个函数可以使用一个数组来存储每个农历年的天数,然后根
据天数差逐步减去每个农历年的天数,直到找到对应的农历年份。

然后,再根据剩余的天数计算出对应的农历月份和日期。

最后,我们可以在主函数中调用这两个函数来完成公历日期到农历
日期的转换。

我们可以输入一个公历日期,然后调用第一个函数计算
出天数差,再调用第二个函数计算出对应的农历日期,并将结果输出。

需要注意的是,由于农历的特殊性,每个农历年的天数和月份都是不固定的,而且还有闰月的情况。

因此,在编写算法时需要考虑到这些特殊情况,并进行相应的处理。

总之,C语言公历转农历算法是一个比较复杂的问题,需要考虑到公历和农历的差异以及农历的特殊性。

通过合理的算法设计和编程实现,我们可以实现公历日期到农历日期的转换,从而满足一些特殊场合的需求。

C#转换农历的简单方法

C#转换农历的简单方法

C#转换农历的简单方法AD:C#转换农历原来还准备自己写算法,并研究农历规则。

发现那太难和麻烦了,光是农历的推算那就我等专门研究历法的人一下搞懂的。

后来发现.NET类库也提供一些基础的农历类System.Globalization.ChineseLunisolarCalendar。

改装了一下如DateTime时间形式,实现了公历农历转换的功能,但是只能算到1900~2100年之间的。

基本够日常使用了。

C#转换农历代码如下:1usingSystem;2usingSystem.Collections.Generic;3usingSystem.Text;45namespaceSystem6...{7/**////<summary>8///中国常用农历日期时间类9///zj53hao@/zj53hao10///</summary>11classChinaDateTime12...{13privateintyear,month,dayOfMonth;14privateboolisLeap;15publicDateTimetime;1617/**////<summary>18///获取当前日期的农历年19///</summary>20publicintYear21...{22get...{returnyear;}23}2425/**////<summary>26///获取当前日期的农历月份27///</summary>28publicintMonth29...{30get...{returnmonth;}31}3233/**////<summary>34///获取当前日期的农历月中天数35///</summary>36publicintDayOfMonth37...{38get...{returndayOfMonth;}39}4041/**////<summary>42///获取当前日期是否为闰月中的日期43///</summary>44publicboolIsLeap45...{46get...{returnisLeap;}47}4849System.Globalization.ChineseLunisolarCalendarcc;50/**////<summary>51///返回指定公历日期的阴历时间52///</summary>53///<paramname paramname="time"></param>54publicChinaDateTime(DateTimetime)55...{56cc=newSystem.Globalization.ChineseLunisolarCalendar();5758if(time>cc.MaxSupportedDateTime||time<cc.MinSupportedDateTime) 59thrownewException("参数日期时间不在支持的范围内,支持范围:"+cc.MinSupportedDateTime.ToShortDateString()+"到"+cc.MaxSupportedDateTime.ToShortDateString());60year=cc.GetYear(time);61month=cc.GetMonth(time);62dayOfMonth=cc.GetDayOfMonth(time);63isLeap=cc.IsLeapMonth(year,month);64if(isLeap)month-=1;65this.time=time;6667}。

c 农历年月日程序设计

c 农历年月日程序设计

c 农历年月日程序设计C语言是一种广泛应用于计算机科学和软件开发领域的编程语言,其强大的功能和灵活的语法使其成为许多程序员的首选。

在C语言中,我们可以通过编写程序来实现农历年月日的计算和转换。

下面我们就以C语言编写农历年月日程序为例,来介绍一下具体的实现方法。

我们需要了解农历的基本知识。

农历是一种以月亮的运行周期为基础的历法,与阳历有所不同。

农历的年份通常由十二个动物的名称来表示,而月份和日期则采用数字来表示。

农历的计算涉及到一些复杂的算法和规则,但是我们可以利用已有的算法库来简化这一过程。

在C语言中,我们可以使用time.h头文件中的函数来获取当前的日期和时间。

具体的操作步骤如下:1. 引入头文件:首先,我们需要在程序中引入time.h头文件,以便使用其中的日期和时间相关函数。

```c#include <time.h>```2. 获取当前的日期和时间:我们可以使用time函数来获取当前的日期和时间,并将其保存在一个time_t类型的变量中。

```ctime_t t = time(NULL);```3. 将日期和时间转换为本地时间:由于time函数返回的是UTC时间(世界标准时间),我们需要将其转换为本地时间。

可以使用localtime函数来实现这一转换。

```cstruct tm *local = localtime(&t);```4. 获取年月日信息:通过local结构体中的成员变量,我们可以获取当前的年份、月份和日期。

```cint year = local->tm_year + 1900;int month = local->tm_mon + 1;int day = local->tm_mday;```5. 将日期转换为农历日期:最后,我们可以使用算法库或自定义的算法将公历日期转换为农历日期。

这里我们以调用算法库为例。

```c// 假设已经定义了一个函数lunar_calendar,用于将公历日期转换为农历日期int lunar_year, lunar_month, lunar_day;lunar_calendar(year, month, day, &lunar_year, &lunar_month, &lunar_day);```通过以上的步骤,我们就可以在C语言中实现农历年月日的计算和转换了。

(2023)C语言万年历设计报告(一)

(2023)C语言万年历设计报告(一)

(2023)C语言万年历设计报告(一)C语言万年历设计报告这份报告是针对 2023 年度 C 语言万年历设计而准备的。

设计目的该万年历的设计目的是为了让用户能够快速地查看任意公历年份的日历,同时还能够显示节气、万年历和日历信息。

设计思路该万年历的主要思路是通过用户输入任意公历年份,在程序中计算并显示该年的日历信息。

具体实现思路如下:1.用户输入年份信息。

2.程序判断该年份是否为闰年,并计算该年的总天数。

3.根据该年第一天是星期几,排列该年每个月的天数。

4.标记国历节日,如元旦、劳动节等。

5.计算并标记该年的节气,如立春、清明等。

6.计算并标记该年的重要万年历信息,如“三伏”、“四季”等。

设计要点在实现该万年历的过程中需要注意以下几个要点:1.为了代码的可维护性,尽量将每个功能模块拆分成函数的形式。

2.程序中需要处理日期的加减运算,可以使用标准库中的<time.h>。

3.节气和万年历的计算应该基于一些公式而不是硬编码。

设计结果经过实现,该万年历已经能够正常运行,并能够正确地显示各种信息。

用户输入任意公历年份后,程序可以迅速计算并展示该年的万年历、节气和重要节日信息。

结论通过本次 C 语言万年历的设计,我们不仅深入地了解了日期处理等相关知识,还提升了编码的能力。

在日常开发中,我们也可以根据这些基础知识,设计更为实用的应用程序。

可改进之处尽管该万年历已经能够满足基本的需求,但仍有一些改进空间。

例如:1.目前仅支持公历,可以添加其他历法的支持,如农历、阴阳历等。

2.界面可以进一步美化,增加更多交互性的组件,如按钮、下拉菜单等。

3.可以添加更多的功能,如查询特定日期的天气、星座运势等。

总结本次 C 语言万年历设计,使我们更好地理解了日期处理的相关知识,提高了我们的编码水平。

同时,我们也意识到在实际项目中,需要更多的功能和优化,才能更好地服务于用户的需求。

通过持续不断的学习和实践,我们可以不断提升自己的编程技能。

二十四节气的C语言算法

二十四节气的C语言算法

【算法】二十四节气的C语言算法2009-05-27 23:12二十四节气是我国劳动人民创造的辉煌文化,它能反映季节的变化,指导农事活动,影响着千家万户的衣食住行。

有人认为二十四节气从属农历,其实,它是根据阳历划定的。

即根据太阳在黄道上的位置,把一年划分为24个彼此相等的段落。

也就是把黄道分成24个等份,每等份各占黄经15°。

由于太阳通过每等份所需的时间几乎相等,二十四节气的公历日期每年大致相同:上半年在6日、21日前后,下半年在8日、23日前后。

节气需要存表,没有固定规律,数据来源别人的VB程序,查询程序是自己写的。

如下:/******************************************************************** ********************************************************函数功能:二十四节气数据库入口参数: unsigned char(yy,mo,dd) 对应年月日出口参数: unsigned char(0-24) 1-24对应二十四节气作者: TOTOP二十四节气数据库(1901--2050)数据格式说明:如1901年的节气为1月 2月 3月 4月 5月 6月 7月 8月 9月 10月 11月 12月[ 6,21][ 4,19][ 6,21][ 5,21][ 6,22][ 6,22][ 8,23][ 8,24][ 8,24][ 8,24][ 8,23][ 8,22][ 9, 6][11, 4][ 9, 6][10, 6][ 9, 7][ 9, 7][ 7, 8][ 7, 9][ 7, 9][ 7, 9][ 7, 8][ 7,15]上面第一行数据为每月节气对应公历日期,15减去每月第一个节气,每月第二个节气减去15得第二行,这样每月两个节气对应数据都小于16,每月用一个字节存放,高位存放第一个节气数据,低位存放第二个节气的数据,可得下表********************************************************************* *******************************************************/uchar code jieqi_code[]={0x96,0xB4,0x96,0xA6,0x97,0x97,0x78,0x79,0x79,0x69,0x78,0 x77, //19010x96,0xA4,0x96,0x96,0x97,0x87,0x79,0x79,0x79,0x69,0x78,0 x78, //19020x96,0xA5,0x87,0x96,0x87,0x87,0x79,0x69,0x69,0x69,0x78,0 x78, //19030x86,0xA5,0x96,0xA5,0x96,0x97,0x88,0x78,0x78,0x79,0x78,0 x87, //19040x96,0xB4,0x96,0xA6,0x97,0x97,0x78,0x79,0x79,0x69,0x78,0 x77, //19050x96,0xA4,0x96,0x96,0x97,0x97,0x79,0x79,0x79,0x69,0x78,0 x78, //19060x96,0xA5,0x87,0x96,0x87,0x87,0x79,0x69,0x69,0x69,0x78,0 x78, //19070x86,0xA5,0x96,0xA5,0x96,0x97,0x88,0x78,0x78,0x69,0x78,0 x87, //19080x96,0xB4,0x96,0xA6,0x97,0x97,0x78,0x79,0x79,0x69,0x78,0 x77, //19090x96,0xA4,0x96,0x96,0x97,0x97,0x79,0x79,0x79,0x69,0x78,0 x78, //19100x96,0xA5,0x87,0x96,0x87,0x87,0x79,0x69,0x69,0x69,0x78,0 x78, //19110x86,0xA5,0x96,0xA5,0x96,0x97,0x88,0x78,0x78,0x69,0x78,0 x87, //19120x95,0xB4,0x96,0xA6,0x97,0x97,0x78,0x79,0x79,0x69,0x78,0 x77, //19130x96,0xB4,0x96,0xA6,0x97,0x97,0x79,0x79,0x79,0x69,0x78,0 x78, //19140x96,0xA5,0x97,0x96,0x97,0x87,0x79,0x79,0x69,0x69,0x78,0 x78, //19150x96,0xA5,0x96,0xA5,0x96,0x97,0x88,0x78,0x78,0x79,0x77,0 x87, //1916x87, //19170x96,0xB4,0x96,0xA6,0x97,0x97,0x79,0x79,0x79,0x69,0x78,0 x77, //19180x96,0xA5,0x97,0x96,0x97,0x87,0x79,0x79,0x69,0x69,0x78,0 x78, //19190x96,0xA5,0x96,0xA5,0x96,0x97,0x88,0x78,0x78,0x79,0x77,0 x87, //19200x95,0xB4,0x96,0xA5,0x96,0x97,0x78,0x79,0x78,0x69,0x78,0 x87, //19210x96,0xB4,0x96,0xA6,0x97,0x97,0x79,0x79,0x79,0x69,0x78,0 x77, //19220x96,0xA4,0x96,0x96,0x97,0x87,0x79,0x79,0x69,0x69,0x78,0 x78, //19230x96,0xA5,0x96,0xA5,0x96,0x97,0x88,0x78,0x78,0x79,0x77,0 x87, //19240x95,0xB4,0x96,0xA5,0x96,0x97,0x78,0x79,0x78,0x69,0x78,0 x87, //19250x96,0xB4,0x96,0xA6,0x97,0x97,0x78,0x79,0x79,0x69,0x78,0 x77, //19260x96,0xA4,0x96,0x96,0x97,0x87,0x79,0x79,0x79,0x69,0x78,0 x78, //19270x96,0xA5,0x96,0xA5,0x96,0x96,0x88,0x78,0x78,0x78,0x87,0 x87, //19280x95,0xB4,0x96,0xA5,0x96,0x97,0x88,0x78,0x78,0x79,0x77,0 x87, //19290x96,0xB4,0x96,0xA6,0x97,0x97,0x78,0x79,0x79,0x69,0x78,0 x77, //19300x96,0xA4,0x96,0x96,0x97,0x87,0x79,0x79,0x79,0x69,0x78,0 x78, //19310x96,0xA5,0x96,0xA5,0x96,0x96,0x88,0x78,0x78,0x78,0x87,0 x87, //19320x95,0xB4,0x96,0xA5,0x96,0x97,0x88,0x78,0x78,0x69,0x78,0 x87, //19330x96,0xB4,0x96,0xA6,0x97,0x97,0x78,0x79,0x79,0x69,0x78,0 x77, //19340x96,0xA4,0x96,0x96,0x97,0x97,0x79,0x79,0x79,0x69,0x78,0 x78, //19350x96,0xA5,0x96,0xA5,0x96,0x96,0x88,0x78,0x78,0x78,0x87,0 x87, //19360x95,0xB4,0x96,0xA5,0x96,0x97,0x88,0x78,0x78,0x69,0x78,0 x87, //19370x96,0xB4,0x96,0xA6,0x97,0x97,0x78,0x79,0x79,0x69,0x78,0 x77, //1938x78, //19390x96,0xA5,0x96,0xA5,0x96,0x96,0x88,0x78,0x78,0x78,0x87,0 x87, //19400x95,0xB4,0x96,0xA5,0x96,0x97,0x88,0x78,0x78,0x69,0x78,0 x87, //19410x96,0xB4,0x96,0xA6,0x97,0x97,0x78,0x79,0x79,0x69,0x78,0 x77, //19420x96,0xA4,0x96,0x96,0x97,0x97,0x79,0x79,0x79,0x69,0x78,0 x78, //19430x96,0xA5,0x96,0xA5,0xA6,0x96,0x88,0x78,0x78,0x78,0x87,0 x87, //19440x95,0xB4,0x96,0xA5,0x96,0x97,0x88,0x78,0x78,0x79,0x77,0 x87, //19450x95,0xB4,0x96,0xA6,0x97,0x97,0x78,0x79,0x78,0x69,0x78,0 x77, //19460x96,0xB4,0x96,0xA6,0x97,0x97,0x79,0x79,0x79,0x69,0x78,0 x78, //19470x96,0xA5,0xA6,0xA5,0xA6,0x96,0x88,0x88,0x78,0x78,0x87,0 x87, //19480xA5,0xB4,0x96,0xA5,0x96,0x97,0x88,0x79,0x78,0x79,0x77,0 x87, //19490x95,0xB4,0x96,0xA5,0x96,0x97,0x78,0x79,0x78,0x69,0x78,0 x77, //19500x96,0xB4,0x96,0xA6,0x97,0x97,0x79,0x79,0x79,0x69,0x78,0 x78, //19510x96,0xA5,0xA6,0xA5,0xA6,0x96,0x88,0x88,0x78,0x78,0x87,0 x87, //19520xA5,0xB4,0x96,0xA5,0x96,0x97,0x88,0x78,0x78,0x79,0x77,0 x87, //19530x95,0xB4,0x96,0xA5,0x96,0x97,0x78,0x79,0x78,0x68,0x78,0 x87, //19540x96,0xB4,0x96,0xA6,0x97,0x97,0x78,0x79,0x79,0x69,0x78,0 x77, //19550x96,0xA5,0xA5,0xA5,0xA6,0x96,0x88,0x88,0x78,0x78,0x87,0 x87, //19560xA5,0xB4,0x96,0xA5,0x96,0x97,0x88,0x78,0x78,0x79,0x77,0 x87, //19570x95,0xB4,0x96,0xA5,0x96,0x97,0x88,0x78,0x78,0x69,0x78,0 x87, //19580x96,0xB4,0x96,0xA6,0x97,0x97,0x78,0x79,0x79,0x69,0x78,0 x77, //19590x96,0xA4,0xA5,0xA5,0xA6,0x96,0x88,0x88,0x88,0x78,0x87,0 x87, //1960x87, //19610x96,0xB4,0x96,0xA5,0x96,0x97,0x88,0x78,0x78,0x69,0x78,0 x87, //19620x96,0xB4,0x96,0xA6,0x97,0x97,0x78,0x79,0x79,0x69,0x78,0 x77, //19630x96,0xA4,0xA5,0xA5,0xA6,0x96,0x88,0x88,0x88,0x78,0x87,0 x87, //19640xA5,0xB4,0x96,0xA5,0x96,0x96,0x88,0x78,0x78,0x78,0x87,0 x87, //19650x95,0xB4,0x96,0xA5,0x96,0x97,0x88,0x78,0x78,0x69,0x78,0 x87, //19660x96,0xB4,0x96,0xA6,0x97,0x97,0x78,0x79,0x79,0x69,0x78,0 x77, //19670x96,0xA4,0xA5,0xA5,0xA6,0xA6,0x88,0x88,0x88,0x78,0x87,0 x87, //19680xA5,0xB4,0x96,0xA5,0x96,0x96,0x88,0x78,0x78,0x78,0x87,0 x87, //19690x95,0xB4,0x96,0xA5,0x96,0x97,0x88,0x78,0x78,0x69,0x78,0 x87, //19700x96,0xB4,0x96,0xA6,0x97,0x97,0x78,0x79,0x79,0x69,0x78,0 x77, //19710x96,0xA4,0xA5,0xA5,0xA6,0xA6,0x88,0x88,0x88,0x78,0x87,0 x87, //19720xA5,0xB5,0x96,0xA5,0xA6,0x96,0x88,0x78,0x78,0x78,0x87,0 x87, //19730x95,0xB4,0x96,0xA5,0x96,0x97,0x88,0x78,0x78,0x69,0x78,0 x87, //19740x96,0xB4,0x96,0xA6,0x97,0x97,0x78,0x79,0x78,0x69,0x78,0 x77, //19750x96,0xA4,0xA5,0xB5,0xA6,0xA6,0x88,0x89,0x88,0x78,0x87,0 x87, //19760xA5,0xB4,0x96,0xA5,0x96,0x96,0x88,0x88,0x78,0x78,0x87,0 x87, //19770x95,0xB4,0x96,0xA5,0x96,0x97,0x88,0x78,0x78,0x79,0x78,0 x87, //19780x96,0xB4,0x96,0xA6,0x96,0x97,0x78,0x79,0x78,0x69,0x78,0 x77, //19790x96,0xA4,0xA5,0xB5,0xA6,0xA6,0x88,0x88,0x88,0x78,0x87,0 x87, //19800xA5,0xB4,0x96,0xA5,0xA6,0x96,0x88,0x88,0x78,0x78,0x77,0 x87, //19810x95,0xB4,0x96,0xA5,0x96,0x97,0x88,0x78,0x78,0x79,0x77,0 x87, //1982x77, //19830x96,0xB4,0xA5,0xB5,0xA6,0xA6,0x87,0x88,0x88,0x78,0x87,0 x87, //19840xA5,0xB4,0xA6,0xA5,0xA6,0x96,0x88,0x88,0x78,0x78,0x87,0 x87, //19850xA5,0xB4,0x96,0xA5,0x96,0x97,0x88,0x78,0x78,0x79,0x77,0 x87, //19860x95,0xB4,0x96,0xA5,0x96,0x97,0x88,0x79,0x78,0x69,0x78,0 x87, //19870x96,0xB4,0xA5,0xB5,0xA6,0xA6,0x87,0x88,0x88,0x78,0x87,0 x86, //19880xA5,0xB4,0xA5,0xA5,0xA6,0x96,0x88,0x88,0x88,0x78,0x87,0 x87, //19890xA5,0xB4,0x96,0xA5,0x96,0x96,0x88,0x78,0x78,0x79,0x77,0 x87, //19900x95,0xB4,0x96,0xA5,0x86,0x97,0x88,0x78,0x78,0x69,0x78,0 x87, //19910x96,0xB4,0xA5,0xB5,0xA6,0xA6,0x87,0x88,0x88,0x78,0x87,0 x86, //19920xA5,0xB3,0xA5,0xA5,0xA6,0x96,0x88,0x88,0x88,0x78,0x87,0 x87, //19930xA5,0xB4,0x96,0xA5,0x96,0x96,0x88,0x78,0x78,0x78,0x87,0 x87, //19940x95,0xB4,0x96,0xA5,0x96,0x97,0x88,0x76,0x78,0x69,0x78,0 x87, //19950x96,0xB4,0xA5,0xB5,0xA6,0xA6,0x87,0x88,0x88,0x78,0x87,0 x86, //19960xA5,0xB3,0xA5,0xA5,0xA6,0xA6,0x88,0x88,0x88,0x78,0x87,0 x87, //19970xA5,0xB4,0x96,0xA5,0x96,0x96,0x88,0x78,0x78,0x78,0x87,0 x87, //19980x95,0xB4,0x96,0xA5,0x96,0x97,0x88,0x78,0x78,0x69,0x78,0 x87, //19990x96,0xB4,0xA5,0xB5,0xA6,0xA6,0x87,0x88,0x88,0x78,0x87,0 x86, //20000xA5,0xB3,0xA5,0xA5,0xA6,0xA6,0x88,0x88,0x88,0x78,0x87,0 x87, //20010xA5,0xB4,0x96,0xA5,0x96,0x96,0x88,0x78,0x78,0x78,0x87,0 x87, //20020x95,0xB4,0x96,0xA5,0x96,0x97,0x88,0x78,0x78,0x69,0x78,0 x87, //20030x96,0xB4,0xA5,0xB5,0xA6,0xA6,0x87,0x88,0x88,0x78,0x87,0 x86, //2004x87, //20050xA5,0xB4,0x96,0xA5,0xA6,0x96,0x88,0x88,0x78,0x78,0x87,0 x87, //20060x95,0xB4,0x96,0xA5,0x96,0x97,0x88,0x78,0x78,0x69,0x78,0 x87, //20070x96,0xB4,0xA5,0xB5,0xA6,0xA6,0x87,0x88,0x87,0x78,0x87,0 x86, //20080xA5,0xB3,0xA5,0xB5,0xA6,0xA6,0x88,0x88,0x88,0x78,0x87,0 x87, //20090xA5,0xB4,0x96,0xA5,0xA6,0x96,0x88,0x88,0x78,0x78,0x87,0 x87, //20100x95,0xB4,0x96,0xA5,0x96,0x97,0x88,0x78,0x78,0x79,0x78,0 x87, //20110x96,0xB4,0xA5,0xB5,0xA5,0xA6,0x87,0x88,0x87,0x78,0x87,0 x86, //20120xA5,0xB3,0xA5,0xB5,0xA6,0xA6,0x87,0x88,0x88,0x78,0x87,0 x87, //20130xA5,0xB4,0x96,0xA5,0xA6,0x96,0x88,0x88,0x78,0x78,0x87,0 x87, //20140x95,0xB4,0x96,0xA5,0x96,0x97,0x88,0x78,0x78,0x79,0x77,0 x87, //20150x95,0xB4,0xA5,0xB4,0xA5,0xA6,0x87,0x88,0x87,0x78,0x87,0 x86, //20160xA5,0xC3,0xA5,0xB5,0xA6,0xA6,0x87,0x88,0x88,0x78,0x87,0 x87, //20170xA5,0xB4,0xA6,0xA5,0xA6,0x96,0x88,0x88,0x78,0x78,0x87,0 x87, //20180xA5,0xB4,0x96,0xA5,0x96,0x96,0x88,0x78,0x78,0x79,0x77,0 x87, //20190x95,0xB4,0xA5,0xB4,0xA5,0xA6,0x97,0x87,0x87,0x78,0x87,0 x86, //20200xA5,0xC3,0xA5,0xB5,0xA6,0xA6,0x87,0x88,0x88,0x78,0x87,0 x86, //20210xA5,0xB4,0xA5,0xA5,0xA6,0x96,0x88,0x88,0x88,0x78,0x87,0 x87, //20220xA5,0xB4,0x96,0xA5,0x96,0x96,0x88,0x78,0x78,0x79,0x77,0 x87, //20230x95,0xB4,0xA5,0xB4,0xA5,0xA6,0x97,0x87,0x87,0x78,0x87,0 x96, //20240xA5,0xC3,0xA5,0xB5,0xA6,0xA6,0x87,0x88,0x88,0x78,0x87,0 x86, //20250xA5,0xB3,0xA5,0xA5,0xA6,0xA6,0x88,0x88,0x88,0x78,0x87,0 x87, //2026x87, //20270x95,0xB4,0xA5,0xB4,0xA5,0xA6,0x97,0x87,0x87,0x78,0x87,0 x96, //20280xA5,0xC3,0xA5,0xB5,0xA6,0xA6,0x87,0x88,0x88,0x78,0x87,0 x86, //20290xA5,0xB3,0xA5,0xA5,0xA6,0xA6,0x88,0x88,0x88,0x78,0x87,0 x87, //20300xA5,0xB4,0x96,0xA5,0x96,0x96,0x88,0x78,0x78,0x78,0x87,0 x87, //20310x95,0xB4,0xA5,0xB4,0xA5,0xA6,0x97,0x87,0x87,0x78,0x87,0 x96, //20320xA5,0xC3,0xA5,0xB5,0xA6,0xA6,0x88,0x88,0x88,0x78,0x87,0 x86, //20330xA5,0xB3,0xA5,0xA5,0xA6,0xA6,0x88,0x78,0x88,0x78,0x87,0 x87, //20340xA5,0xB4,0x96,0xA5,0xA6,0x96,0x88,0x88,0x78,0x78,0x87,0 x87, //20350x95,0xB4,0xA5,0xB4,0xA5,0xA6,0x97,0x87,0x87,0x78,0x87,0 x96, //20360xA5,0xC3,0xA5,0xB5,0xA6,0xA6,0x87,0x88,0x88,0x78,0x87,0 x86, //20370xA5,0xB3,0xA5,0xA5,0xA6,0xA6,0x88,0x88,0x88,0x78,0x87,0 x87, //20380xA5,0xB4,0x96,0xA5,0xA6,0x96,0x88,0x88,0x78,0x78,0x87,0 x87, //20390x95,0xB4,0xA5,0xB4,0xA5,0xA6,0x97,0x87,0x87,0x78,0x87,0 x96, //20400xA5,0xC3,0xA5,0xB5,0xA5,0xA6,0x87,0x88,0x87,0x78,0x87,0 x86, //20410xA5,0xB3,0xA5,0xB5,0xA6,0xA6,0x88,0x88,0x88,0x78,0x87,0 x87, //20420xA5,0xB4,0x96,0xA5,0xA6,0x96,0x88,0x88,0x78,0x78,0x87,0 x87, //20430x95,0xB4,0xA5,0xB4,0xA5,0xA6,0x97,0x87,0x87,0x88,0x87,0 x96, //20440xA5,0xC3,0xA5,0xB4,0xA5,0xA6,0x87,0x88,0x87,0x78,0x87,0 x86, //20450xA5,0xB3,0xA5,0xB5,0xA6,0xA6,0x87,0x88,0x88,0x78,0x87,0 x87, //20460xA5,0xB4,0x96,0xA5,0xA6,0x96,0x88,0x88,0x78,0x78,0x87,0 x87, //20470x95,0xB4,0xA5,0xB4,0xA5,0xA5,0x97,0x87,0x87,0x88,0x86,0 x96, //2048x86, //20490xA5,0xC3,0xA5,0xB5,0xA6,0xA6,0x87,0x88,0x78,0x78,0x87,0 x87, //2050};unsigned char jieqi (unsigned char yy,mo,dd){unsigned char temp,y,d,m;int addr;d =dd; m =mo;y = yy-1901;addr=y*12+m-1;if(d<15){temp=15-d;if((jieqi_code[addr]>>4)==temp) return (m<<1-1);else return (0);}if(d==15) return (0);if(d>15){temp=d-15;if((jieqi_code[addr]&0x0f)==temp) return (m<<1);else return (0);}}。

阴历年月 24节气的算法 c语言

阴历年月 24节气的算法 c语言
}
int GetWeek(int nYear,int nMonth,int nDay,int nWeekOfFirstday) // 4
{
int nDaysYear[]={31,28,31,30,31,30,31,31,30,31,30,31};
int nDaysLeapYear[]={31,29,31,30,31,30,31,31,30,31,30,31};
nWeek=GetWeek(nYear,nMonth,nDay,nWeekOfFirstday); // 4
isleapyear=IsLeapYear(nYear); // 2
}
int IsLeapYear(int nYear) // 2
{
if(nYear%4==0)
return 1;
else
return 0;
}
int GetWeekOfFirstday(int nYear) // 3
{
int i,j;
printf("the calender of this month as following:\n");
printf("*********************************\n");
printf(" SUN MON TUE WEN THU FRI STA\n");
{
if(nYear>2000)
return ((nYear-2001)*365+(nYear-2001)/4+1)%7;
else if(nYear<2000)
return 6-((2000-nYear)*365+(2000-nYear)/4)%7;

万年历c语言代码讲解

万年历c语言代码讲解

万年历c语言代码讲解摘要:一、万年历C语言代码讲解简介1.万年历的概念及用途2.C语言代码讲解的重要性二、C语言代码基础1.C语言简介2.C语言基本语法3.C语言的数据类型与变量三、万年历C语言代码实现1.计算闰年2.计算月份的天数3.计算日期的星期4.输出万年历四、万年历C语言代码的优化与拓展1.代码性能优化2.功能的拓展与实现五、总结1.万年历C语言代码讲解的意义2.对编程能力的提升正文:一、万年历C语言代码讲解简介万年历是一种记录了公历日期的工具,它可以帮助我们快速查询公历日期对应的农历、节日、提醒等信息。

C语言是一种广泛应用于计算机领域的编程语言,掌握C语言编程对于学习其他编程语言有很大的帮助。

本文将详细讲解万年历C语言代码的实现过程,帮助读者更好地理解C语言编程。

二、C语言代码基础1.C语言简介C语言是一种高级编程语言,由丹尼斯·里奇(Dennis Ritchie)于20世纪70年代在贝尔实验室开发。

C语言具有良好的性能和可移植性,被广泛应用于操作系统、嵌入式系统、硬件驱动等领域。

2.C语言基本语法C语言的基本语法包括变量声明、数据类型、运算符、控制结构、函数等。

了解这些基本语法对于编写C语言代码至关重要。

3.C语言的数据类型与变量C语言的数据类型包括整型、浮点型、字符型等。

变量是存储数据的容器,通过变量名来表示。

声明变量时需要指定变量的数据类型和存储空间。

三、万年历C语言代码实现1.计算闰年闰年是指公历年份可以被4整除但不能被100整除的年份,或者是可以被400整除的年份。

通过编写一个函数,我们可以判断一个年份是否为闰年。

2.计算月份的天数根据公历规定,每个月的天数不同。

通过编写一个函数,我们可以计算指定月份的天数。

3.计算日期的星期通过编写一个函数,我们可以根据公历日期计算对应的星期。

4.输出万年历根据用户输入的日期范围,输出对应的万年历信息。

四、万年历C语言代码的优化与拓展1.代码性能优化在实现万年历C语言代码的过程中,可以通过优化算法、使用更高效的函数等方式提高代码性能。

公历转换成农历c语言函数

公历转换成农历c语言函数

公历转换成农历c语言函数在编程过程中,经常需要进行日期的转换操作。

其中,将公历转换成农历是一个常见的需求。

在C语言中,我们可以通过编写一个函数来实现这个功能。

下面是一个实现公历转换成农历的C语言函数的示例:```c#include <stdio.h>typedef struct {int year; // 公历年份int month; // 公历月份int day; // 公历日期} Date;typedef struct {int year; // 农历年份int month; // 农历月份int day; // 农历日期} LunarDate;// 公历转农历函数void convertToLunar(const Date* gregorianDate, LunarDate* lunarDate) {// 在这里编写公历转农历的具体实现代码// 具体实现略}int main() {Date gregorianDate = {2022, 10, 1}; // 示例:公历日期为2022年10月1日LunarDate lunarDate;convertToLunar(&gregorianDate, &lunarDate);printf("公历日期:%d年%d月%d日\n", gregorianDate.year, gregorianDate.month, gregorianDate.day);printf("农历日期:%d年%d月%d日\n", lunarDate.year, lunarDate.month, lunarDate.day);return 0;}```在上述代码中,我们首先定义了`Date`和`LunarDate`结构体,分别表示公历日期和农历日期。

`Date`结构体包含了年、月、日三个字段,而`LunarDate`结构体也包含了年、月、日三个字段。

公历阳历转阴历农历C51程序键盘数码管成功

公历阳历转阴历农历C51程序键盘数码管成功

/****************************************************************************** ** 实验名: 动态显示数码管实验* 使用的IO : 数码管使用P0,P2.2,P2.3,P2.4* 实验效果: 数码管显示76543210。

* 注意:******************************************************************************* /#include<reg51.h>#include<stdio.h>#define GPIO_DIG P0//数码管显示#define GPIO_KEY P1//键盘sbit LSA=P2^2;sbit LSB=P2^3;sbit LSC=P2^4;sbit K3=P3^2;//外部中断unsigned char code DataTab[404]={//日期差//上大小月//下大小月//闰月月份及大小0x46,0x43,0x21,0x00,//19990x35,0x15,0x51,0x00,//20000x23,0x11,0x52,0x41,0x42,0x12,0x65,0x00,0x31,0x11,0x32,0x00,0x21,0x42,0x52,0x21,0x39,0x52,0x25,0x00,//20050x28,0x25,0x04,0x71,0x48,0x66,0x42,0x00,0x37,0x33,0x22,0x00,0x25,0x15,0x24,0x51,0x44,0x25,0x52,0x00,//20100x33,0x22,0x65,0x00,0x22,0x21,0x25,0x41,0x40,0x24,0x52,0x00,0x30,0x52,0x42,0x91,0x49,0x55,0x05,0x00, //20150x38,0x26,0x44,0x00,0x27,0x53,0x50,0x60,0x46,0x53,0x24,0x00,0x35,0x25,0x54,0x00,0x24,0x41,0x52,0x41, //20200x42,0x45,0x25,0x00,0x31,0x24,0x52,0x00,0x21,0x51,0x12,0x21,0x40,0x55,0x11,0x00,0x28,0x32,0x21,0x61, //2025 0x47,0x26,0x61,0x00,0x36,0x13,0x31,0x00,0x25,0x05,0x31,0x51,0x43,0x12,0x54,0x00,0x33,0x51,0x25,0x00, //2030 0x22,0x42,0x25,0x31,0x41,0x32,0x22,0x00,0x30,0x55,0x02,0x71,0x49,0x55,0x22,0x00,0x38,0x26,0x62,0x00, //2035 0x27,0x13,0x64,0x60,0x45,0x13,0x32,0x00,0x34,0x12,0x55,0x00,0x23,0x10,0x53,0x51,0x42,0x22,0x45,0x00, //2040 0x31,0x52,0x22,0x00,0x21,0x52,0x44,0x21,0x40,0x55,0x44,0x00,0x29,0x26,0x50,0x71,0x47,0x26,0x64,0x00, //2045 0x36,0x25,0x32,0x00,0x25,0x23,0x32,0x50,0x44,0x44,0x55,0x00,0x32,0x24,0x45,0x00,0x22,0x55,0x11,0x30, //2050 0x41,0x33,0x10,0x00,0x31,0x55,0x40,0x81,0x49,0x55,0x50,0x00,0x38,0x46,0x64,0x00,0x27,0x45,0x65,0x60, //2055 0x45,0x05,0x32,0x00,0x34,0x45,0x15,0x00,0x23,0x26,0x23,0x40,0x42,0x25,0x21,0x00,0x32,0x33,0x21,0x00, //2060 0x20,0x43,0x21,0x31,0x39,0x15,0x51,0x00,0x28,0x12,0x52,0x71,0x47,0x12,0x65,0x00,0x35,0x11,0x32,0x00, //2065 0x25,0x50,0x52,0x51,0x44,0x52,0x25,0x00,0x33,0x26,0x22,0x00,0x22,0x52,0x42,0x41,0x41,0x53,0x22,0x00, //20700x30,0x25,0x44,0x81,0x49,0x25,0x52,0x00,0x37,0x22,0x65,0x00,0x26,0x22,0x25,0x61,0x45,0x24,0x52,0x00, //20750x35,0x52,0x45,0x00,0x23,0x25,0x05,0x41,0x42,0x26,0x44,0x00,0x32,0x53,0x24,0x00,0x21,0x23,0x30,0x31, //20800x39,0x45,0x54,0x00,0x28,0x43,0x14,0x71,0x47,0x45,0x25,0x00,0x36,0x24,0x52,0x00,0x25,0x55,0x12,0x50, //20850x44,0x55,0x11,0x00,0x33,0x26,0x50,0x00,0x23,0x52,0x61,0x41,0x40,0x13,0x31,0x00,0x29,0x05,0x51,0x81, //20900x48,0x12,0x55,0x00,0x37,0x11,0x25,0x00,0x26,0x45,0x25,0x60,0x45,0x52,0x22,0x00,0x35,0x55,0x21,0x00, //20950x24,0x25,0x42,0x41,0x42,0x26,0x62,0x00,0x31,0x13,0x52,0x00,0x20,0x03,0x32,0x21 //2099};unsigned char code DIG_CODE[17]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};//0、1、2、3、4、5、6、7、8、9、A、b、C、d、E、F的显示码unsigned char code so_m_d[12]={31,28,31,30,31,30,31,31,30,31,30,31};//公历该月的天数unsigned char DisplayData[8];//用来存放要显示的8位数的值unsigned char TempData[8];unsigned char TurnData[4];//转换用于取出数据表的四个数据unsigned char KeyValue;//用来存放读取到的键值unsigned char KV;char year_soH;char year_so;//公历年月日char month_so;char day_so;int SumDar_so; //char型位数不够,出现瓶颈char year_lu;//农历年月日char month_lu;char day_lu;int SumDar_lu;int n,H;void DigDisplay(); //动态显示函数void Delay10ms(); //延时10msvoid KeyDown(); //检测按键函数void KeyShow(); //检测键值并显示void Turn(); //阳历转换阴历//int LMP(int LP);int month12_lu(int month_a ,unsigned char month_b,unsigned char month_c);/****************************************************************************** ** 函数名: main* 函数功能: 主函数* 输入: 无* 输出: 无******************************************************************************* /void main(){year_lu=0;//农历年月日month_lu=0;day_lu=0;KeyShow();//设置INT0IT0=1;//跳变沿出发方式(下降沿)EX0=1;//打开INT0的中断允许。

电子万年历24节气c程序

电子万年历24节气c程序

/***********************************************************************农历节气******************************///原理:因为每一个公历月会有二个节气,所以分别用高/低4位来表示//表格制作方法:比如:2010年1月5号是节气,1月20是第二个节气//高4位写第一个节气,低4位即20-10=A写第二个节气,最终=0x5A;//---------------------------------------------------------------------------------------------------uchar code tab_jieqi[][12]={/* 1 2 3 4 5 6 7 8 9 10 11 12 单位:月*/{0x5a,0x49,0x6b,0x5a,0x5b,0x6b,0x7d,0x7d,0x8d,0x8d,0x7c,0x7c},//2010年ok{0x6a,0x49,0x6b,0x5a,0x6b,0x6c,0x7d,0x8d,0x8d,0x8e,0x8d,0x7c},//2011年ok{0x6b,0x49,0x5a,0x4a,0x5a,0x5b,0x7c,0x7d,0x7c,0x8d,0x7c,0x7b},//2012年ok 闰年{0x5a,0x48,0x5a,0x4a,0x5b,0x5b,0x7c,0x7d,0x7d,0x8d,0x7c,0x7c},//2013年ok /////////////////////{0x5a,0x49,0x6b,0x5a,0x5b,0x6b,0x7d,0x7d,0x8d,0x8d,0x7c,0x7c},//2014年OK{0x6a,0x49,0x6b,0x5a,0x6b,0x6c,0x7d,0x8d,0x8d,0x8e,0x8c,0x7c},//2015年OK{0x6a,0x49,0x5a,0x49,0x5a,0x5b,0x7c,0x7d,0x7c,0x8d,0x7c,0x7b},//2016年ok/* 1 2 3 4 5 6 7 8 9 10 11 12 单位:月*/{0x5a,0x38,0x5a,0x4a,0x5b,0x5b,0x7c,0x7d,0x7d,0x8d,0x7c,0x7c},//2017年ok //////////////////{0x5a,0x49,0x5b,0x5a,0x5b,0x6b,0x7d,0x7d,0x8d,0x8d,0x7c,0x7c},//2018年ok{0x5a,0x49,0x6b,0x5a,0x6b,0x6b,0x7d,0x8d,0x8d,0x8e,0x8c,0x7c},//2019年ok{0x6A,0x49,0x5A,0x49,0x5A,0x5B,0x6C,0x7c,0x7C,0x8D,0x7C,0x7b},//2020年ok{0x5A,0x38,0x5A,0x4A,0x5b,0x5B,0x7C,0x7D,0x7D,0x8D,0x7C,0x7B},//2021年ok ///////////{0x5A,0x49,0x5A,0x5A,0x5B,0x6B,0x7D,0x7D,0x7D,0x8D,0x7C,0x7C},//2022年ok{0x5A,0x49,0x6B,0x5A,0x6B,0x6b,0x7D,0x8D,0x8D,0x8E,0x8C,0x7C},//2023年ok{0x6A,0x49,0x5A,0x49,0x5A,0x5B,0x6C,0x7c,0x7C,0x8D,0x7C,0x6B},//2024年ok/* 1 2 3 4 5 6 7 8 9 10 11 12 单位:月*/{0x5A,0x38,0x5A,0x4A,0x5B,0x5B,0x7C,0x7D,0x7D,0x8D,0x7C,0x7B},//2025年ok ////////////{0x5A,0x48,0x5A,0x5A,0x5B,0x5B,0x7D,0x7D,0x7D,0x8D,0x7C,0x7C},//2026年ok{0x5A,0x49,0x6B,0x5A,0x6B,0x6B,0x7D,0x8D,0x8D,0x8D,0x7C,0x7C},//2027年ok{0x6A,0x49,0x5A,0x49,0x5A,0x5B,0x6C,0x7C,0x7C,0x8D,0x7C,0x6B},//2028年ok{0x5A,0x38,0x5A,0x4A,0x5B,0x5B,0x7C,0x7D,0x7d,0x8D,0x7C,0x7B},//2029年ok ///////////////{0x5A,0x48,0x5A,0x5A,0x5B,0x5B,0x7D,0x7D,0x7D,0x8D,0x7C,0x7C},//2030年ok{0x5A,0x49,0x6B,0x5A,0x6B,0x6B,0x7D,0x8D,0x8D,0x8D,0x7C,0x7C},//2031年ok{0x6A,0x49,0x5A,0x49,0x5A,0x5B,0x6C,0x7C,0x7C,0x8D,0x7C,0x6B},//2032年ok/* 1 2 3 4 5 6 7 8 9 10 11 12 单位:月*/{0x5A,0x38,0x5A,0x4A,0x5B,0x5B,0x7D,0x7D,0x7D,0x8D,0x7C,0x7B},//2033年////////////{0x5A,0x48,0x5A,0x5A,0x5B,0x5B,0x7D,0x8D,0x7D,0x8D,0x7C,0x7C},//2034年ok{0x5A,0x49,0x6B,0x5A,0x5B,0x6B,0x7D,0x7D,0x8D,0x8D,0x7C,0x7C},//2035年ok{0x6A,0x49,0x5A,0x49,0x5A,0x5B,0x6C,0x7C,0x7C,0x8D,0x7C,0x6B},//2036年ok{0x5A,0x38,0x5A,0x4A,0x5B,0x5B,0x7C,0x7D,0x7d,0x8D,0x7C,0x7B},//2037年ok ///////////////{0x5A,0x48,0x5A,0x5A,0x5B,0x5B,0x7D,0x7D,0x7D,0x8D,0x7C,0x7C},//2038年ok{0x5A,0x49,0x6B,0x5A,0x5B,0x6B,0x7D,0x7D,0x8D,0x8D,0x7C,0x7C},//2039年ok{0x6A,0x49,0x5A,0x49,0x5A,0x5B,0x6C,0x7C,0x7C,0x8D,0x7C,0x6B},//2040年ok/* 1 2 3 4 5 6 7 8 9 10 11 12 单位:月*/{0x5A,0x38,0x5A,0x4A,0x5A,0x5B,0x7C,0x7D,0x7C,0x8D,0x7C,0x7B},//2041年////////////{0x5A,0x48,0x5A,0x4A,0x5B,0x5B,0x7D,0x7D,0x7D,0x8D,0x7C,0x7C},//2042年ok{0x5A,0x49,0x6B,0x5A,0x5B,0x6B,0x7D,0x7D,0x8D,0x8D,0x7C,0x7C},//2043年ok{0x6A,0x49,0x5A,0x49,0x5A,0x5B,0x6C,0x7C,0x7C,0x7D,0x7C,0x6B},//2044年ok{0x5A,0x38,0x5A,0x49,0x5A,0x5B,0x7C,0x7D,0x7C,0x8D,0x7C,0x7B},//2045年ok ///////////////{0x5A,0x48,0x5A,0x4A,0x5B,0x5B,0x7C,0x7D,0x7D,0x8D,0x7C,0x7C},//2046年ok{0x5A,0x49,0x6B,0x5A,0x5B,0x6B,0x7D,0x7D,0x8D,0x8D,0x7C,0x7C},//2047年ok{0x6A,0x49,0x5A,0x49,0x5A,0x5A,0x6C,0x7C,0x7C,0x7D,0x7B,0x6B},//2048年ok/* 1 2 3 4 5 6 7 8 9 10 11 12 单位:月*/{0x59,0x38,0x5A,0x5A,0x5A,0x5B,0x6C,0x7C,0x7C,0x8D,0x7C,0x7B},//2049年////////////{0x5A,0x38,0x5A,0x4A,0x5B,0x5B,0x7C,0x7D,0x7D,0x8D,0x7C,0x7C},//2050年ok{0x5A,0x49,0x5A,0x5A,0x5B,0x6B,0x7D,0x7D,0x7D,0x8D,0x7C,0x7C},//2051年ok{0x5A,0x49,0x5A,0x49,0x5A,0x5A,0x6C,0x7C,0x7C,0x7D,0x7B,0x6B},//2052年ok{0x59,0x38,0x5A,0x49,0x5A,0x5B,0x6C,0x7C,0x7C,0x8D,0x7C,0x7B},//2053年ok ///////////////{0x5A,0x38,0x5A,0x4A,0x5B,0x5B,0x7C,0x7D,0x7D,0x8D,0x7C,0x7C},//2054年ok{0x5A,0x49,0x5A,0x5A,0x5B,0x5B,0x7D,0x7D,0x7D,0x8D,0x7C,0x7C},//2055年ok{0x5A,0x49,0x5A,0x49,0x5A,0x5A,0x6C,0x7C,0x7C,0x7D,0x7B,0x6B},//2056年ok/* 1 2 3 4 5 6 7 8 9 10 11 12 单位:月*/{0x59,0x38,0x5A,0x49,0x5A,0x5B,0x6C,0x7C,0x7C,0x8D,0x7C,0x6B},//2057年////////////{0x5A,0x38,0x5A,0x4A,0x5B,0x5B,0x7C,0x7D,0x7D,0x8D,0x7C,0x7B},//2058年ok{0x5A,0x49,0x5A,0x5A,0x5B,0x5B,0x7D,0x7D,0x7D,0x8D,0x7C,0x7C},//2059年ok{0x5A,0x49,0x5A,0x49,0x5A,0x5A,0x6C,0x7C,0x7C,0x7D,0x6B,0x6B},//2060年ok{0x59,0x38,0x5A,0x49,0x5A,0x5B,0x6C,0x7C,0x7C,0x8D,0x7C,0x6B},//2061年ok ///////////////{0x5A,0x38,0x5A,0x4A,0x5B,0x5B,0x7C,0x7D,0x7D,0x8D,0x7C,0x7B},//2062年ok{0x5A,0x48,0x5A,0x5A,0x5B,0x5B,0x7D,0x7D,0x7D,0x8D,0x7C,0x7C},//2063年ok{0x5A,0x49,0x5A,0x49,0x5A,0x5A,0x6C,0x7C,0x7C,0x7C,0x6B,0x6B},//2064年ok/* 1 2 3 4 5 6 7 8 9 10 11 12 单位:月*/{0x59,0x38,0x5A,0x49,0x5A,0x5B,0x6C,0x7C,0x7C,0x8D,0x7C,0x6B},//2065年////////////{0x5A,0x38,0x5A,0x4A,0x5B,0x5B,0x7C,0x7D,0x7D,0x8D,0x7C,0x7B},//2066年ok{0x5A,0x48,0x5A,0x5A,0x5B,0x5B,0x7D,0x7D,0x7D,0x8D,0x7C,0x7C},//2067年ok{0x5A,0x49,0x5A,0x49,0x4A,0x5A,0x6C,0x6C,0x7C,0x7C,0x6B,0x6B},//2068年ok{0x59,0x38,0x5A,0x49,0x5A,0x5B,0x6C,0x7C,0x7C,0x8D,0x7C,0x6B},//2069年ok ///////////////{0x5A,0x38,0x5A,0x4A,0x5A,0x5B,0x7C,0x7D,0x7C,0x8D,0x7C,0x7B},//2070年ok{0x5A,0x48,0x5A,0x5A,0x5B,0x5B,0x7D,0x7D,0x7D,0x8D,0x7C,0x7C},//2071年ok{0x5A,0x49,0x5A,0x49,0x4A,0x5A,0x6C,0x6C,0x7C,0x7C,0x6B,0x6B},//2072年ok/* 1 2 3 4 5 6 7 8 9 10 11 12 单位:月*/{0x59,0x38,0x5A,0x49,0x5A,0x5B,0x6C,0x7C,0x7C,0x7D,0x7C,0x6B},//2073年////////////{0x5A,0x38,0x5A,0x4A,0x5A,0x5B,0x7C,0x7D,0x7C,0x8D,0x7C,0x7B},//2074年ok{0x5A,0x48,0x5A,0x4A,0x5B,0x5B,0x7C,0x7D,0x7D,0x8D,0x7C,0x7C},//2075年ok{0x5A,0x49,0x5A,0x49,0x4A,0x5A,0x6C,0x6C,0x7C,0x7C,0x6B,0x6B},//2076年ok{0x59,0x38,0x5A,0x49,0x5A,0x5B,0x6C,0x7C,0x7C,0x7D,0x7C,0x6B},//2077年ok ///////////////{0x5A,0x38,0x5A,0x49,0x5A,0x5B,0x6C,0x7D,0x7C,0x8D,0x7C,0x7B},//2078年ok{0x5A,0x48,0x5A,0x4A,0x5B,0x5B,0x7C,0x7D,0x7D,0x8D,0x7C,0x7C},//2079年ok{0x5A,0x49,0x5A,0x49,0x4A,0x5A,0x6C,0x6C,0x7C,0x7C,0x6B,0x6B},//2080年ok/* 1 2 3 4 5 6 7 8 9 10 11 12 单位:月*/{0x59,0x38,0x5A,0x49,0x5A,0x5A,0x6C,0x7C,0x7C,0x7D,0x7B,0x6B},//2081年////////////{0x5A,0x38,0x5A,0x49,0x5A,0x5B,0x6C,0x7C,0x7C,0x8D,0x7C,0x7B},//2082年ok{0x5A,0x38,0x5A,0x4A,0x5B,0x5B,0x7C,0x7D,0x7D,0x8D,0x7C,0x7C},//2083年ok{0x5A,0x49,0x49,0x49,0x4A,0x5A,0x6C,0x6C,0x6C,0x7C,0x6B,0x6B},//2084年ok{0x49,0x38,0x5A,0x49,0x5A,0x5A,0x6C,0x7C,0x7C,0x7D,0x7B,0x6B},//2085年ok ///////////////{0x59,0x38,0x5A,0x49,0x5A,0x5B,0x6C,0x7D,0x7C,0x8D,0x7C,0x7B},//2086年ok{0x5A,0x38,0x5A,0x4A,0x5B,0x5B,0x7C,0x7D,0x7D,0x8D,0x7C,0x7C},//2087年ok{0x5A,0x49,0x49,0x49,0x4A,0x4A,0x6C,0x6C,0x6C,0x7C,0x6B,0x6B},//2088年ok/* 1 2 3 4 5 6 7 8 9 10 11 12 单位:月*/{0x49,0x38,0x5A,0x49,0x5A,0x5A,0x6C,0x7C,0x7C,0x7D,0x7B,0x6B},//2089年////////////{0x59,0x38,0x5A,0x49,0x5B,0x5B,0x6C,0x7C,0x7C,0x8D,0x7C,0x6B},//2090年ok{0x5A,0x38,0x5A,0x4A,0x5B,0x5B,0x7C,0x7D,0x7D,0x8D,0x7C,0x7B},//2091年ok{0x5A,0x49,0x49,0x49,0x4A,0x4A,0x6C,0x6C,0x6C,0x7C,0x6B,0x6B},//2092年ok{0x49,0x38,0x5A,0x49,0x5A,0x5A,0x6C,0x7C,0x7C,0x7C,0x6B,0x6B},//2093年ok ///////////////{0x59,0x38,0x5A,0x49,0x5A,0x5B,0x6C,0x7C,0x7C,0x8D,0x7C,0x6B},//2094年ok{0x5A,0x38,0x5A,0x4A,0x5B,0x5B,0x7C,0x7D,0x7D,0x8D,0x7C,0x7B},//2095年ok{0x5A,0x48,0x49,0x49,0x4A,0x4A,0x6C,0x6C,0x6C,0x7C,0x6B,0x6B},//2096年ok/* 1 2 3 4 5 6 7 8 9 10 11 12 单位:月*/{0x49,0x38,0x5A,0x49,0x5A,0x5A,0x6C,0x6C,0x7C,0x7C,0x6B,0x6B},//2097年////////////{0x59,0x38,0x5A,0x49,0x5A,0x5B,0x6C,0x7C,0x7C,0x8D,0x7C,0x6B},//2098年ok{0x5A,0x38,0x5A,0x4A,0x5B,0x5B,0x7C,0x7D,0x7D,0x8D,0x7C,0x7B},//2099年ok};/*******************************************************************农历节气转换******************************///输入年月日,如果当天是一个节气,就返回1 至24,无节气就返回0//如:输入2016年12月21日,则返回22= 冬至,//前面的20不要:get_jieqi(16,12,21);//1----24如下//立春、雨水、惊蛰、春分、清明、谷雨、立夏、小满、芒种、夏至、小暑、大暑.//立秋、处暑、白露、秋分、寒露、霜降、立冬、小雪、大雪、冬至、小寒、大寒.uchar get_jieqi(uchar y_y,uchar m_o,uchar d_d){uchar i,jie;if((y_y<100)&(y_y>9)) //只计算2010-2099年,其它不计算,以免产生误码{i=tab_jieqi[y_y-10][m_o-1];//查表得到本月的二个节气if(d_d>9)i=(i&0x0f)+10;//如大于9号了,加多10天,else i>>=4;if(i==d_d) //二者相等,说明当天是一个农历节日{switch(m_o){case 1: if(d_d>10)jie=24;else jie=23;break; //如果大于10号,就是第二个节气case 2: if(d_d>10)jie=2; else jie=1; break;case 3: if(d_d>10)jie=4; else jie=3; break;case 4: if(d_d>10)jie=6; else jie=5; break;case 5: if(d_d>10)jie=8; else jie=7; break;case 6: if(d_d>10)jie=10;else jie=9; break;case 7: if(d_d>10)jie=12;else jie=11;break;case 8: if(d_d>10)jie=14;else jie=13;break;case 9: if(d_d>10)jie=16;else jie=15;break;case 10: if(d_d>10)jie=18;else jie=17;break;case 11: if(d_d>10)jie=20;else jie=19;break;case 12: if(d_d>10)jie=22;else jie=21;break;default : ;}}else jie=0;}else jie=0;return jie;}。

C语言实现农历万年历

C语言实现农历万年历
2 / 48
2016 年全新原创
C 语言实现农历万年历
星期的计算,普遍采用的公式是:
paradise300
W = [Y-1] + [(Y-1)/4] - [(Y-1)/100] + [(Y-1)/400] + D
Y 是年份,D 是这一天在这一年中的年内序数加 1,也就是这一天在这一年中 是第几天。这个公式验证了一下是可行的。
首先,通过对公历正月初一的统计,发现从公元 1600 年到 6400 年之间,最 早出现在 19(即 1 月 20 日),最晚出现在 51(2 月 21 日),两者之差为 32,即 需要 6 个位来描述,6 个位的范围从 0 到 63,足够描述从 19 到 51 了。农历闰月 从正月到十二月,转换为数字即 1 到 12,0 表示无闰月,总的范围是即从 0 到 12,需要 4 个位。而农历月份大小是比较规范,大月 30 天,小月 29 天,因此可 以用 1 个位来表示农历一个月的天数,月份大小信息可以描述为 13 个位。综合 以上几项数据,最为经济的存储方式就是把这几项合在一起,总共 23 位数据, 可以用 3 个字节来存储。简而言之,一个农历年的信息可以用 3 个字节来保存。
公历每个月的天数大小还算固定,只要通过判断闰年来区分 2 月天数即可, 还是非常简单的。从第 3 点至第 7 点,这些是没有简单规律的,对于一般需求, 用查表法可以解决,即节省空间,又提升效率,两全齐美。第三部分中将给出详 细数据,以及对数据的解释。
三、数据
为了兼顾空间(数据大小)和时间(运行效率),我也是下足了工夫。
要实现一个完整的万年历需要具备以下几点内容:
1. 星期 2. 公历每个月总天数 3. 农历正月初一对应的公历日期 4. 农历每个月的总天数 5. 农历闰月 6. 二十四节气 7. 数九、梅雨、三伏 8. 干支

用c语言编写万年历思路

用c语言编写万年历思路

用c语言编写万年历思路摘要:一、万年历的概念及用途二、用C 语言编写万年历的优势三、编写万年历的基本思路1.计算闰年2.计算月份的天数3.计算星期几4.输出结果四、编写万年历的注意事项1.闰年的判断2.月份天数的计算3.星期几的计算4.输出格式的设计正文:一、万年历的概念及用途万年历,又称历书,是一种历法工具,用于查询公历、农历、节气、节日等信息。

在我国,万年历具有悠久的历史,传统的万年历通常以阴历为主,兼顾阳历。

随着科技的发展,现代万年历功能更加丰富,不仅可以查询农历、阳历,还可以查询星座、黄历等信息。

二、用C 语言编写万年历的优势C 语言是一种通用的、过程式的计算机程序设计语言,具有较高的执行效率和良好的跨平台性。

用C 语言编写万年历,可以充分发挥C 语言的特点,实现高效、稳定的程序运行。

此外,C 语言具有丰富的库函数,可以方便地处理日期、时间等数据。

三、编写万年历的基本思路编写万年历的基本思路可以分为四个步骤:计算闰年、计算月份的天数、计算星期几和输出结果。

1.计算闰年闰年是指公历年份可以被4 整除但不能被100 整除的年份,或者是可以被400 整除的年份。

通过编写一个简单的程序,可以判断给定的年份是否为闰年。

2.计算月份的天数根据公历规定,每个月的天数有所不同。

通过编写一个函数,可以计算给定月份的天数。

需要注意的是,2 月份的天数需要根据是否为闰年来确定。

3.计算星期几计算星期几需要先确定输入的日期,然后计算该日期距离某个基准日期(如1900 年1 月1 日)的天数,再将天数除以7 取余数,余数即为星期几。

4.输出结果将计算出的结果按照一定的格式输出,如显示阳历、农历、节气、节日等信息。

四、编写万年历的注意事项在编写万年历的过程中,需要注意以下几点:1.闰年的判断:要确保程序能够正确判断闰年,以避免2 月份天数计算错误。

2.月份天数的计算:要根据闰年的情况,正确计算2 月份的天数。

3.星期几的计算:要选择合适的基准日期,确保计算结果准确。

农历阳历之间转换和节气节日查询C语言编程

农历阳历之间转换和节气节日查询C语言编程

//基于1602液晶显示的程序设计#include<reg52.h>//C51写的公历转农历和星期#define uchar unsigned char#define uint unsigned int/*公历年对应的农历数据,每年三字节,格式第一字节BIT7-4 位表示闰月月份,值为0 为无闰月,BIT3-0 对应农历第1-4 月的大小第二字节BIT7-0 对应农历第5-12 月大小,第三字节BIT7 表示农历第13 个月大小月份对应的位为1 表示本农历月大(30 天),为0 表示小(29 天)第三字节BIT6-5 表示春节的公历月份,BIT4-0 表示春节的公历日期*/code uchar year_code[597] = {0x04,0xAe,0x53, //19010x0A,0x57,0x48, //19020x55,0x26,0xBd, //19030x0d,0x26,0x50, //19040x0d,0x95,0x44, //19050x46,0xAA,0xB9, //19060x05,0x6A,0x4d, //19070x09,0xAd,0x42, //19080x24,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, //19300x0e,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, //19740x8d,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, //1999 294 0x0C,0x96,0x45, //2000 297 0x4d,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, //20180x47,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, //20620x0d,0x4A,0x51, //20640x0d,0xA5,0x45, //20650x55,0xAA,0xBA, //20660x05,0x6A,0x4e, //20670x0A,0x6d,0x43, //20680x45,0x2e,0xB7, //20690x05,0x2d,0x4B, //20700x8A,0x95,0xBf, //20710x0A,0x95,0x53, //20720x0B,0x4A,0x47, //20730x6B,0x55,0x3B, //20740x0A,0xd5,0x4f, //20750x05,0x5A,0x45, //20760x4A,0x5d,0x38, //20770x0A,0x5B,0x4C, //20780x05,0x2B,0x42, //20790x3A,0x93,0xB6, //20800x06,0x93,0x49, //20810x77,0x29,0xBd, //20820x06,0xAA,0x51, //20830x0A,0xd5,0x46, //20840x54,0xdA,0xBA, //20850x04,0xB6,0x4e, //20860x0A,0x57,0x43, //20870x45,0x27,0x38, //20880x0d,0x26,0x4A, //20890x8e,0x93,0x3e, //20900x0d,0x52,0x52, //20910x0d,0xAA,0x47, //20920x66,0xB5,0x3B, //20930x05,0x6d,0x4f, //20940x04,0xAe,0x45, //20950x4A,0x4e,0xB9, //20960x0A,0x4d,0x4C, //20970x0d,0x15,0x41, //20980x2d,0x92,0xB5, //2099};code uchar jieqi_code[]={0x96,0xB4,0x96,0xA6,0x97,0x97,0x78,0x79,0x79,0x69,0x78,0x77, //1901 0x96,0xA4,0x96,0x96,0x97,0x87,0x79,0x79,0x79,0x69,0x78,0x78, //19020x96,0xA5,0x87,0x96,0x87,0x87,0x79,0x69,0x69,0x69,0x78,0x78, //19030x86,0xA5,0x96,0xA5,0x96,0x97,0x88,0x78,0x78,0x79,0x78,0x87, //19040x96,0xA4,0x96,0x96,0x97,0x97,0x79,0x79,0x79,0x69,0x78,0x78, //1906 0x96,0xA5,0x87,0x96,0x87,0x87,0x79,0x69,0x69,0x69,0x78,0x78, //1907 0x86,0xA5,0x96,0xA5,0x96,0x97,0x88,0x78,0x78,0x69,0x78,0x87, //1908 0x96,0xB4,0x96,0xA6,0x97,0x97,0x78,0x79,0x79,0x69,0x78,0x77, //1909 0x96,0xA4,0x96,0x96,0x97,0x97,0x79,0x79,0x79,0x69,0x78,0x78, //1910 0x96,0xA5,0x87,0x96,0x87,0x87,0x79,0x69,0x69,0x69,0x78,0x78, //1911 0x86,0xA5,0x96,0xA5,0x96,0x97,0x88,0x78,0x78,0x69,0x78,0x87, //1912 0x95,0xB4,0x96,0xA6,0x97,0x97,0x78,0x79,0x79,0x69,0x78,0x77, //1913 0x96,0xB4,0x96,0xA6,0x97,0x97,0x79,0x79,0x79,0x69,0x78,0x78, //1914 0x96,0xA5,0x97,0x96,0x97,0x87,0x79,0x79,0x69,0x69,0x78,0x78, //1915 0x96,0xA5,0x96,0xA5,0x96,0x97,0x88,0x78,0x78,0x79,0x77,0x87, //1916 0x95,0xB4,0x96,0xA6,0x96,0x97,0x78,0x79,0x78,0x69,0x78,0x87, //1917 0x96,0xB4,0x96,0xA6,0x97,0x97,0x79,0x79,0x79,0x69,0x78,0x77, //1918 0x96,0xA5,0x97,0x96,0x97,0x87,0x79,0x79,0x69,0x69,0x78,0x78, //1919 0x96,0xA5,0x96,0xA5,0x96,0x97,0x88,0x78,0x78,0x79,0x77,0x87, //1920 0x95,0xB4,0x96,0xA5,0x96,0x97,0x78,0x79,0x78,0x69,0x78,0x87, //1921 0x96,0xB4,0x96,0xA6,0x97,0x97,0x79,0x79,0x79,0x69,0x78,0x77, //1922 0x96,0xA4,0x96,0x96,0x97,0x87,0x79,0x79,0x69,0x69,0x78,0x78, //1923 0x96,0xA5,0x96,0xA5,0x96,0x97,0x88,0x78,0x78,0x79,0x77,0x87, //1924 0x95,0xB4,0x96,0xA5,0x96,0x97,0x78,0x79,0x78,0x69,0x78,0x87, //1925 0x96,0xB4,0x96,0xA6,0x97,0x97,0x78,0x79,0x79,0x69,0x78,0x77, //1926 0x96,0xA4,0x96,0x96,0x97,0x87,0x79,0x79,0x79,0x69,0x78,0x78, //1927 0x96,0xA5,0x96,0xA5,0x96,0x96,0x88,0x78,0x78,0x78,0x87,0x87, //1928 0x95,0xB4,0x96,0xA5,0x96,0x97,0x88,0x78,0x78,0x79,0x77,0x87, //1929 0x96,0xB4,0x96,0xA6,0x97,0x97,0x78,0x79,0x79,0x69,0x78,0x77, //1930 0x96,0xA4,0x96,0x96,0x97,0x87,0x79,0x79,0x79,0x69,0x78,0x78, //1931 0x96,0xA5,0x96,0xA5,0x96,0x96,0x88,0x78,0x78,0x78,0x87,0x87, //1932 0x95,0xB4,0x96,0xA5,0x96,0x97,0x88,0x78,0x78,0x69,0x78,0x87, //1933 0x96,0xB4,0x96,0xA6,0x97,0x97,0x78,0x79,0x79,0x69,0x78,0x77, //1934 0x96,0xA4,0x96,0x96,0x97,0x97,0x79,0x79,0x79,0x69,0x78,0x78, //1935 0x96,0xA5,0x96,0xA5,0x96,0x96,0x88,0x78,0x78,0x78,0x87,0x87, //1936 0x95,0xB4,0x96,0xA5,0x96,0x97,0x88,0x78,0x78,0x69,0x78,0x87, //1937 0x96,0xB4,0x96,0xA6,0x97,0x97,0x78,0x79,0x79,0x69,0x78,0x77, //1938 0x96,0xA4,0x96,0x96,0x97,0x97,0x79,0x79,0x79,0x69,0x78,0x78, //1939 0x96,0xA5,0x96,0xA5,0x96,0x96,0x88,0x78,0x78,0x78,0x87,0x87, //1940 0x95,0xB4,0x96,0xA5,0x96,0x97,0x88,0x78,0x78,0x69,0x78,0x87, //1941 0x96,0xB4,0x96,0xA6,0x97,0x97,0x78,0x79,0x79,0x69,0x78,0x77, //1942 0x96,0xA4,0x96,0x96,0x97,0x97,0x79,0x79,0x79,0x69,0x78,0x78, //1943 0x96,0xA5,0x96,0xA5,0xA6,0x96,0x88,0x78,0x78,0x78,0x87,0x87, //1944 0x95,0xB4,0x96,0xA5,0x96,0x97,0x88,0x78,0x78,0x79,0x77,0x87, //1945 0x95,0xB4,0x96,0xA6,0x97,0x97,0x78,0x79,0x78,0x69,0x78,0x77, //1946 0x96,0xB4,0x96,0xA6,0x97,0x97,0x79,0x79,0x79,0x69,0x78,0x78, //1947 0x96,0xA5,0xA6,0xA5,0xA6,0x96,0x88,0x88,0x78,0x78,0x87,0x87, //19480x95,0xB4,0x96,0xA5,0x96,0x97,0x78,0x79,0x78,0x69,0x78,0x77, //1950 0x96,0xB4,0x96,0xA6,0x97,0x97,0x79,0x79,0x79,0x69,0x78,0x78, //1951 0x96,0xA5,0xA6,0xA5,0xA6,0x96,0x88,0x88,0x78,0x78,0x87,0x87, //1952 0xA5,0xB4,0x96,0xA5,0x96,0x97,0x88,0x78,0x78,0x79,0x77,0x87, //1953 0x95,0xB4,0x96,0xA5,0x96,0x97,0x78,0x79,0x78,0x68,0x78,0x87, //1954 0x96,0xB4,0x96,0xA6,0x97,0x97,0x78,0x79,0x79,0x69,0x78,0x77, //1955 0x96,0xA5,0xA5,0xA5,0xA6,0x96,0x88,0x88,0x78,0x78,0x87,0x87, //1956 0xA5,0xB4,0x96,0xA5,0x96,0x97,0x88,0x78,0x78,0x79,0x77,0x87, //1957 0x95,0xB4,0x96,0xA5,0x96,0x97,0x88,0x78,0x78,0x69,0x78,0x87, //1958 0x96,0xB4,0x96,0xA6,0x97,0x97,0x78,0x79,0x79,0x69,0x78,0x77, //1959 0x96,0xA4,0xA5,0xA5,0xA6,0x96,0x88,0x88,0x88,0x78,0x87,0x87, //1960 0xA5,0xB4,0x96,0xA5,0x96,0x96,0x88,0x78,0x78,0x78,0x87,0x87, //1961 0x96,0xB4,0x96,0xA5,0x96,0x97,0x88,0x78,0x78,0x69,0x78,0x87, //1962 0x96,0xB4,0x96,0xA6,0x97,0x97,0x78,0x79,0x79,0x69,0x78,0x77, //1963 0x96,0xA4,0xA5,0xA5,0xA6,0x96,0x88,0x88,0x88,0x78,0x87,0x87, //1964 0xA5,0xB4,0x96,0xA5,0x96,0x96,0x88,0x78,0x78,0x78,0x87,0x87, //1965 0x95,0xB4,0x96,0xA5,0x96,0x97,0x88,0x78,0x78,0x69,0x78,0x87, //1966 0x96,0xB4,0x96,0xA6,0x97,0x97,0x78,0x79,0x79,0x69,0x78,0x77, //1967 0x96,0xA4,0xA5,0xA5,0xA6,0xA6,0x88,0x88,0x88,0x78,0x87,0x87, //1968 0xA5,0xB4,0x96,0xA5,0x96,0x96,0x88,0x78,0x78,0x78,0x87,0x87, //1969 0x95,0xB4,0x96,0xA5,0x96,0x97,0x88,0x78,0x78,0x69,0x78,0x87, //1970 0x96,0xB4,0x96,0xA6,0x97,0x97,0x78,0x79,0x79,0x69,0x78,0x77, //1971 0x96,0xA4,0xA5,0xA5,0xA6,0xA6,0x88,0x88,0x88,0x78,0x87,0x87, //1972 0xA5,0xB5,0x96,0xA5,0xA6,0x96,0x88,0x78,0x78,0x78,0x87,0x87, //1973 0x95,0xB4,0x96,0xA5,0x96,0x97,0x88,0x78,0x78,0x69,0x78,0x87, //1974 0x96,0xB4,0x96,0xA6,0x97,0x97,0x78,0x79,0x78,0x69,0x78,0x77, //1975 0x96,0xA4,0xA5,0xB5,0xA6,0xA6,0x88,0x89,0x88,0x78,0x87,0x87, //1976 0xA5,0xB4,0x96,0xA5,0x96,0x96,0x88,0x88,0x78,0x78,0x87,0x87, //1977 0x95,0xB4,0x96,0xA5,0x96,0x97,0x88,0x78,0x78,0x79,0x78,0x87, //1978 0x96,0xB4,0x96,0xA6,0x96,0x97,0x78,0x79,0x78,0x69,0x78,0x77, //1979 0x96,0xA4,0xA5,0xB5,0xA6,0xA6,0x88,0x88,0x88,0x78,0x87,0x87, //1980 0xA5,0xB4,0x96,0xA5,0xA6,0x96,0x88,0x88,0x78,0x78,0x77,0x87, //1981 0x95,0xB4,0x96,0xA5,0x96,0x97,0x88,0x78,0x78,0x79,0x77,0x87, //1982 0x95,0xB4,0x96,0xA5,0x96,0x97,0x78,0x79,0x78,0x69,0x78,0x77, //1983 0x96,0xB4,0xA5,0xB5,0xA6,0xA6,0x87,0x88,0x88,0x78,0x87,0x87, //1984 0xA5,0xB4,0xA6,0xA5,0xA6,0x96,0x88,0x88,0x78,0x78,0x87,0x87, //1985 0xA5,0xB4,0x96,0xA5,0x96,0x97,0x88,0x78,0x78,0x79,0x77,0x87, //1986 0x95,0xB4,0x96,0xA5,0x96,0x97,0x88,0x79,0x78,0x69,0x78,0x87, //1987 0x96,0xB4,0xA5,0xB5,0xA6,0xA6,0x87,0x88,0x88,0x78,0x87,0x86, //1988 0xA5,0xB4,0xA5,0xA5,0xA6,0x96,0x88,0x88,0x88,0x78,0x87,0x87, //1989 0xA5,0xB4,0x96,0xA5,0x96,0x96,0x88,0x78,0x78,0x79,0x77,0x87, //1990 0x95,0xB4,0x96,0xA5,0x86,0x97,0x88,0x78,0x78,0x69,0x78,0x87, //1991 0x96,0xB4,0xA5,0xB5,0xA6,0xA6,0x87,0x88,0x88,0x78,0x87,0x86, //19920xA5,0xB4,0x96,0xA5,0x96,0x96,0x88,0x78,0x78,0x78,0x87,0x87, //1994 0x95,0xB4,0x96,0xA5,0x96,0x97,0x88,0x76,0x78,0x69,0x78,0x87, //1995 0x96,0xB4,0xA5,0xB5,0xA6,0xA6,0x87,0x88,0x88,0x78,0x87,0x86, //1996 0xA5,0xB3,0xA5,0xA5,0xA6,0xA6,0x88,0x88,0x88,0x78,0x87,0x87, //1997 0xA5,0xB4,0x96,0xA5,0x96,0x96,0x88,0x78,0x78,0x78,0x87,0x87, //1998 0x95,0xB4,0x96,0xA5,0x96,0x97,0x88,0x78,0x78,0x69,0x78,0x87, //1999 0x96,0xB4,0xA5,0xB5,0xA6,0xA6,0x87,0x88,0x88,0x78,0x87,0x86, //2000 0xA5,0xB3,0xA5,0xA5,0xA6,0xA6,0x88,0x88,0x88,0x78,0x87,0x87, //2001 0xA5,0xB4,0x96,0xA5,0x96,0x96,0x88,0x78,0x78,0x78,0x87,0x87, //2002 0x95,0xB4,0x96,0xA5,0x96,0x97,0x88,0x78,0x78,0x69,0x78,0x87, //2003 0x96,0xB4,0xA5,0xB5,0xA6,0xA6,0x87,0x88,0x88,0x78,0x87,0x86, //2004 0xA5,0xB3,0xA5,0xA5,0xA6,0xA6,0x88,0x88,0x88,0x78,0x87,0x87, //2005 0xA5,0xB4,0x96,0xA5,0xA6,0x96,0x88,0x88,0x78,0x78,0x87,0x87, //2006 0x95,0xB4,0x96,0xA5,0x96,0x97,0x88,0x78,0x78,0x69,0x78,0x87, //2007 0x96,0xB4,0xA5,0xB5,0xA6,0xA6,0x87,0x88,0x87,0x78,0x87,0x86, //2008 0xA5,0xB3,0xA5,0xB5,0xA6,0xA6,0x88,0x88,0x88,0x78,0x87,0x87, //2009 0xA5,0xB4,0x96,0xA5,0xA6,0x96,0x88,0x88,0x78,0x78,0x87,0x87, //2010 0x95,0xB4,0x96,0xA5,0x96,0x97,0x88,0x78,0x78,0x79,0x78,0x87, //2011 0x96,0xB4,0xA5,0xB5,0xA5,0xA6,0x87,0x88,0x87,0x78,0x87,0x86, //2012 0xA5,0xB3,0xA5,0xB5,0xA6,0xA6,0x87,0x88,0x88,0x78,0x87,0x87, //2013 0xA5,0xB4,0x96,0xA5,0xA6,0x96,0x88,0x88,0x78,0x78,0x87,0x87, //2014 0x95,0xB4,0x96,0xA5,0x96,0x97,0x88,0x78,0x78,0x79,0x77,0x87, //2015 0x95,0xB4,0xA5,0xB4,0xA5,0xA6,0x87,0x88,0x87,0x78,0x87,0x86, //2016 0xA5,0xC3,0xA5,0xB5,0xA6,0xA6,0x87,0x88,0x88,0x78,0x87,0x87, //2017 0xA5,0xB4,0xA6,0xA5,0xA6,0x96,0x88,0x88,0x78,0x78,0x87,0x87, //2018 0xA5,0xB4,0x96,0xA5,0x96,0x96,0x88,0x78,0x78,0x79,0x77,0x87, //2019 0x95,0xB4,0xA5,0xB4,0xA5,0xA6,0x97,0x87,0x87,0x78,0x87,0x86, //2020 0xA5,0xC3,0xA5,0xB5,0xA6,0xA6,0x87,0x88,0x88,0x78,0x87,0x86, //2021 0xA5,0xB4,0xA5,0xA5,0xA6,0x96,0x88,0x88,0x88,0x78,0x87,0x87, //2022 0xA5,0xB4,0x96,0xA5,0x96,0x96,0x88,0x78,0x78,0x79,0x77,0x87, //2023 0x95,0xB4,0xA5,0xB4,0xA5,0xA6,0x97,0x87,0x87,0x78,0x87,0x96, //2024 0xA5,0xC3,0xA5,0xB5,0xA6,0xA6,0x87,0x88,0x88,0x78,0x87,0x86, //2025 0xA5,0xB3,0xA5,0xA5,0xA6,0xA6,0x88,0x88,0x88,0x78,0x87,0x87, //2026 0xA5,0xB4,0x96,0xA5,0x96,0x96,0x88,0x78,0x78,0x78,0x87,0x87, //2027 0x95,0xB4,0xA5,0xB4,0xA5,0xA6,0x97,0x87,0x87,0x78,0x87,0x96, //2028 0xA5,0xC3,0xA5,0xB5,0xA6,0xA6,0x87,0x88,0x88,0x78,0x87,0x86, //2029 0xA5,0xB3,0xA5,0xA5,0xA6,0xA6,0x88,0x88,0x88,0x78,0x87,0x87, //2030 0xA5,0xB4,0x96,0xA5,0x96,0x96,0x88,0x78,0x78,0x78,0x87,0x87, //2031 0x95,0xB4,0xA5,0xB4,0xA5,0xA6,0x97,0x87,0x87,0x78,0x87,0x96, //2032 0xA5,0xC3,0xA5,0xB5,0xA6,0xA6,0x88,0x88,0x88,0x78,0x87,0x86, //2033 0xA5,0xB3,0xA5,0xA5,0xA6,0xA6,0x88,0x78,0x88,0x78,0x87,0x87, //2034 0xA5,0xB4,0x96,0xA5,0xA6,0x96,0x88,0x88,0x78,0x78,0x87,0x87, //2035 0x95,0xB4,0xA5,0xB4,0xA5,0xA6,0x97,0x87,0x87,0x78,0x87,0x96, //20360xA5,0xB3,0xA5,0xA5,0xA6,0xA6,0x88,0x88,0x88,0x78,0x87,0x87, //20380xA5,0xB4,0x96,0xA5,0xA6,0x96,0x88,0x88,0x78,0x78,0x87,0x87, //20390x95,0xB4,0xA5,0xB4,0xA5,0xA6,0x97,0x87,0x87,0x78,0x87,0x96, //20400xA5,0xC3,0xA5,0xB5,0xA5,0xA6,0x87,0x88,0x87,0x78,0x87,0x86, //20410xA5,0xB3,0xA5,0xB5,0xA6,0xA6,0x88,0x88,0x88,0x78,0x87,0x87, //20420xA5,0xB4,0x96,0xA5,0xA6,0x96,0x88,0x88,0x78,0x78,0x87,0x87, //20430x95,0xB4,0xA5,0xB4,0xA5,0xA6,0x97,0x87,0x87,0x88,0x87,0x96, //20440xA5,0xC3,0xA5,0xB4,0xA5,0xA6,0x87,0x88,0x87,0x78,0x87,0x86, //20450xA5,0xB3,0xA5,0xB5,0xA6,0xA6,0x87,0x88,0x88,0x78,0x87,0x87, //20460xA5,0xB4,0x96,0xA5,0xA6,0x96,0x88,0x88,0x78,0x78,0x87,0x87, //20470x95,0xB4,0xA5,0xB4,0xA5,0xA5,0x97,0x87,0x87,0x88,0x86,0x96, //20480xA4,0xC3,0xA5,0xA5,0xA5,0xA6,0x97,0x87,0x87,0x78,0x87,0x86, //20490xA5,0xC3,0xA5,0xB5,0xA6,0xA6,0x87,0x88,0x78,0x78,0x87,0x87, //2050 };///月份数据表code uchar day_code1[9]={0x0,0x1f,0x3b,0x5a,0x78,0x97,0xb5,0xd4,0xf3};code uint day_code2[3]={0x111,0x130,0x14e};code uchar jieqi_name[][3]={"hi","xh","dh","lc","ys","jz","cf","qm","gy","lx","xm","mz","xz","xs","ds","lq","cs ","bl","qf","hl","sj","ld","xx","dx","dz",};code uchar gjieri_name[][2]={"hi","yd","fn","ld","qn","et","jj","js","gq",};code uchar njieri_name[][2]={"hi","cj","yx","dw","qx","zq","cy","lb",};/*函数功能:输入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数据*/data uchar year_moon,month_moon,day_moon,week;uchar qi=0,gri=0,nri=0;void jieqi (uchar *nyr){uint temp,yy,dd,mm,addr,y;uchar mo,ndd;yy=nyr[0]*100+nyr[1];mm=nyr[2];dd=nyr[3];y = yy-1901;mo=month_moon/16*10+month_moon%16;ndd=day_moon/16*10+day_moon%16;addr=y*12+mm-1;if(dd<15){temp=15-dd;if((jieqi_code[addr]>>4)==temp) qi=mm*2-1;else qi=0;}if(dd==15) qi=0;if(dd>15){temp=dd-15;if((jieqi_code[addr]&0x0f)==temp) qi=mm*2;else qi=0;}shijian[3]=qi;////////////////////////////////////////////////////////////////////////////////// LCD_write_char(10,1,' ');LCD_write_char(11,1,jieqi_name[qi][0]);LCD_write_char(12,1,jieqi_name[qi][1]);LCD_write_char(13,1,' ');if(mm==1&&dd==1) gri=1;if(mm==3&&dd==8) gri=2;if(mm==5&&dd==1) gri=3;if(mm==5&&dd==4) gri=4;if(mm==6&&dd==1) gri=5;if(mm==8&&dd==1) gri=6;if(mm==9&&dd==10) gri=7;if(mm==10&&dd==1) gri=8;if(mo==1&&ndd==1) nri=1;if(mo==1&&ndd==15) nri=2;if(mo==5&&ndd==5) nri=3;if(mo==7&&ndd==7) nri=4;if(mo==8&&ndd==15) nri=5;if(mo==9&&ndd==9) nri=6;if(mo==12&&ndd==8) nri=7;/*********************************************************/shijian[4]=gri;shijian[5]=nri;/**********************************************************/if(nri!=0){LCD_write_char(14,1,njieri_name[nri][0]);LCD_write_char(15,1,njieri_name[nri][1]);}else{LCD_write_char(14,1,gjieri_name[gri][0]);LCD_write_char(15,1,gjieri_name[gri][1]);}}bit c_moon;/*子函数,用于读取数据表中农历月的大月或小月,如果该月为大返回1,为小返回0*/ bit get_moon_day(uchar month_p,uint table_addr){uchar temp;switch (month_p){case 1:{temp=year_code[table_addr]&0x08;if (temp==0)return(0);else return(1);}case 2:{temp=year_code[table_addr]&0x04;if (temp==0)return(0);else return(1);}case 3:{temp=year_code[table_addr]&0x02;if (temp==0)return(0);else return(1);}case 4:{temp=year_code[table_addr]&0x01;if (temp==0)return(0);else return(1);}case 5:{temp=year_code[table_addr+1]&0x80;if (temp==0) return(0);else return(1);}case 6:{temp=year_code[table_addr+1]&0x40;if (temp==0)return(0);else return(1);}case 7:{temp=year_code[table_addr+1]&0x20;if (temp==0)return(0);else return(1);}case 8:{temp=year_code[table_addr+1]&0x10;if (temp==0)return(0);else return(1);}case 9:{temp=year_code[table_addr+1]&0x08;if (temp==0)return(0);else return(1);}case 10:{temp=year_code[table_addr+1]&0x04;if (temp==0)return(0);else return(1);}case 11:{temp=year_code[table_addr+1]&0x02;if (temp==0)return(0);else return(1);}case 12:{temp=year_code[table_addr+1]&0x01;if (temp==0)return(0);else return(1);}case 13:{temp=year_code[table_addr+2]&0x80;if (temp==0)return(0);else return(1);}}}/*函数功能:输入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数据*/void Conversion(bit c,uchar year,uchar month,uchar day){ //c=0 为21世纪,c=1 为19世纪输入输出数据均为BCD数据uchar temp1,temp2,temp3,month_p;uint temp4,table_addr;bit flag2,flag_y;temp1=year/16; //BCD->hex 先把数据转换为十六进制temp2=year%16;year=temp1*10+temp2;temp1=month/16;temp2=month%16;month=temp1*10+temp2;temp1=day/16;temp2=day%16;day=temp1*10+temp2;//定位数据表地址if(c==0){table_addr=(year+0x64-1)*0x3;}else{table_addr=(year-1)*0x3;}//定位数据表地址完成//取当年春节所在的公历月份temp1=year_code[table_addr+2]&0x60;temp1=_cror_(temp1,5);//取当年春节所在的公历月份完成//取当年春节所在的公历日temp2=year_code[table_addr+2]&0x1f;//取当年春节所在的公历日完成// 计算当年春年离当年元旦的天数,春节只会在公历1月或2月if(temp1==0x1){temp3=temp2-1;}else{temp3=temp2+0x1f-1;}// 计算当年春年离当年元旦的天数完成//计算公历日离当年元旦的天数,为了减少运算,用了两个表//day_code1[9],day_code2[3]//如果公历月在九月或前,天数会少于0xff,用表day_code1[9],//在九月后,天数大于0xff,用表day_code2[3]//如输入公历日为8月10日,则公历日离元旦天数为day_code1[8-1]+10-1//如输入公历日为11月10日,则公历日离元旦天数为day_code2[11-10]+10-1if (month<10){temp4=day_code1[month-1]+day-1;}else{temp4=day_code2[month-10]+day-1;}if ((month>0x2)&&(year%0x4==0)){ //如果公历月大于2月并且该年的2月为闰月,天数加1temp4+=1;}//计算公历日离当年元旦的天数完成//判断公历日在春节前还是春节后if (temp4>=temp3){ //公历日在春节后或就是春节当日使用下面代码进行运算temp4-=temp3;month=0x1;month_p=0x1; //month_p为月份指向,公历日在春节前或就是春节当日month_p指向首月flag2=get_moon_day(month_p,table_addr);//检查该农历月为大小还是小月,大月返回1,小月返回0flag_y=0;if(flag2==0)temp1=0x1d; //小月29天else temp1=0x1e; //大小30天temp2=year_code[table_addr]&0xf0;temp2=_cror_(temp2,4); //从数据表中取该年的闰月月份,如为0则该年无闰月while(temp4>=temp1){temp4-=temp1;month_p+=1;if(month==temp2){flag_y=~flag_y;if(flag_y==0)month+=1;}else month+=1;flag2=get_moon_day(month_p,table_addr);if(flag2==0)temp1=0x1d;else temp1=0x1e;}day=temp4+1;}else{ //公历日在春节前使用下面代码进行运算temp3-=temp4;if (year==0x0){year=0x63;c=1;}else year-=1;table_addr-=0x3;month=0xc;temp2=year_code[table_addr]&0xf0;temp2=_cror_(temp2,4);if (temp2==0)month_p=0xc;elsemonth_p=0xd; ///*month_p为月份指向,如果当年有闰月,一年有十三个月,月指向13,无闰月指向12*/ flag_y=0;flag2=get_moon_day(month_p,table_addr);if(flag2==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;flag2=get_moon_day(month_p,table_addr);if(flag2==0)temp1=0x1d;else temp1=0x1e;}day=temp1-temp3+1;}c_moon=c; //HEX->BCD ,运算结束后,把数据转换为BCD数据temp1=year/10;temp1=_crol_(temp1,4);temp2=year%10;year_moon=temp1|temp2;temp1=month/10;temp1=_crol_(temp1,4);temp2=month%10;month_moon=temp1|temp2;temp1=day/10;temp1=_crol_(temp1,4);temp2=day%10;day_moon=temp1|temp2;}/*函数功能:输入BCD阳历数据,输出BCD星期数据(只允许1901-2099年)调用函数示例:Conver_week(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世纪调用函数后,原有数据不变,读week得出阴历BCD数据*/code uchar table_week[12]={0,3,3,6,1,4,6,2,5,0,3,5}; //月修正数据表/*算法:日期+年份+所过闰年数+月较正数之和除7 的余数就是星期但如果是在闰年又不到3 月份上述之和要减一天再除7星期数为0*/void Conver_week(bit c,uchar year,uchar month,uchar day){//c=0 为21世纪,c=1 为19世纪输入输出数据均为BCD数据uchar temp1,temp2;temp1=year/16; //BCD->hex 先把数据转换为十六进制temp2=year%16;year=temp1*10+temp2;temp1=month/16;temp2=month%16;month=temp1*10+temp2;temp1=day/16;temp2=day%16;day=temp1*10+temp2;if (c==0){year+=0x64;} //如果为21世纪,年份数加100temp1=year/0x4; //所过闰年数只算1900年之后的temp2=year+temp1;temp2=temp2%0x7; //为节省资源,先进行一次取余,避免数大于0xff,避免使用整型数据temp2=temp2+day+table_week[month-1];if (year%0x4==0&&month<3)temp2-=1;week=temp2%0x7;}//testuchar c_sun,year_sun,month_sun,day_sun;/***********************************************农历转换函数************************************************/unsigned char set_1[4];bit flag_1=0,flag_2=0;void nongli(uchar *nyr){uchar i=0;code uchar table_week[][4]={"Sun","Mon","Tue","Wed","Thu","Fri","Sat"};year_sun=nyr[1]/10*16+nyr[1]%10;month_sun=nyr[2]/10*16+nyr[2]%10;day_sun=nyr[3]/10*16+nyr[3]%10;//LCD_clear();if(nyr[0]==20){LCD_write_char(0,1,'2');LCD_write_char(1,1,'0');Conversion(0,year_sun,month_sun,day_sun);Conver_week(0,year_sun,month_sun,day_sun);}else if(nyr[0]==19){LCD_write_char(0,1,'1');LCD_write_char(1,1,'9');Conversion(1,year_sun,month_sun,day_sun);Conver_week(1,year_sun,month_sun,day_sun);}else{LCD_write_str(0,1,"Error Input!");sound_3();delay1(200);delay1(200);delay1(200);delay1(200);delay1(200);delay1(200);flag_1=1;return;}LCD_write_char(2,1,year_moon/16+0x30);LCD_write_char(3,1,year_moon%16+0x30);LCD_write_char(4,1,'-');LCD_write_char(5,1,month_moon/16+0x30);LCD_write_char(6,1,month_moon%16+0x30);LCD_write_char(7,1,'-');LCD_write_char(8,1,day_moon/16+0x30);LCD_write_char(9,1,day_moon%16+0x30);LCD_write_str(10,1," ");LCD_write_str(12,0,table_week[week%16]);}/*************************************************接受要转换成农历个阳历的年月日函数**************************************************/void receive(){unsigned char i;LCD_clear();//清屏key_value=16;ds1302_read_time();for(i=0;i<4;i++)set_1[i]=time_buf1[i];set_1[0]=20;LCD_write_char(0,0,set_1[0]/10+0x30);LCD_write_char(1,0,set_1[0]%10+0x30);LCD_write_char(2,0,set_1[1]/10+0x30);LCD_write_char(3,0,set_1[1]%10+0x30);LCD_write_char(4,0,'-');LCD_write_char(5,0,set_1[2]/10+0x30);LCD_write_char(6,0,set_1[2]%10+0x30);LCD_write_char(7,0,'-');LCD_write_char(8,0,set_1[3]/10+0x30);LCD_write_char(9,0,set_1[3]%10+0x30);nongli(set_1);i=0;LCD_write_com(0x0f);//打开光标LCD_write_com(0x80+i);//写入初始地址while(1){key();if((key_value>=0)&&(key_value<=9)){while(1){keyscan();if(!keydown){delay1(10);keyscan();if(!keydown){LCD_write_Data(key_value+0x30);LCD_write_com(0x80+i);//校正写数据时数据指针的加一if(i==0){set_1[0]=key_value*10+set_1[0]%10;key_value=16;break;}if(i==1){set_1[0]=key_value+set_1[0]/10*10;key_value=16;break;}if(i==2)//年份{set_1[1]=key_value*10+set_1[1]%10;key_value=16;break;}if(i==3){set_1[1]=key_value+set_1[1]/10*10;key_value=16;break;}if(i==4)//'-'符号不变{LCD_write_Data('-');LCD_write_com(0x80+i);//校正写数据时数据指针的加一key_value=16;break;}if(i==5)//月份{set_1[2]=key_value*10+set_1[2]%10;key_value=16;break;}if(i==6){set_1[2]=key_value+set_1[2]/10*10;key_value=16;break;}if(i==7)//'-'符号不变{LCD_write_Data('-');LCD_write_com(0x80+i);//校正写数据时数据指针的加一key_value=16;break;}if(i==8)//年份{set_1[3]=key_value*10+set_1[3]%10;key_value=16;break;}if(i==9){set_1[3]=key_value+set_1[3]/10*10;key_value=16;break;}}}}}if(key_value==12){while(1){keyscan();if(!keydown){delay1(10);keyscan();if(!keydown){flag_2=1;key_value=16;break;}}}break;}if(key_value==13){while(1){keyscan();if(!keydown){delay1(10);keyscan();if(!keydown){if((i>0)&&(i<=9))i--;LCD_write_com(0x80+i);key_value=16;break;}}}}if(key_value==14){while(1){keyscan();if(!keydown){delay1(10);keyscan();if(!keydown){if(i<9)i=i+1;LCD_write_com(0x80+i);key_value=16;break;}}}。

C语言实现农历万年历

C语言实现农历万年历

农历数据:
第 23 位 保留
第 22 至 17 位 农历正月初一的年内序数
第 16 至 13 位 闰月
第 12 至 0 位 月份大小信息
因此,农历数据使用 24 个位,即 3 字节。
上述四个块,分别有如下含义:
3 / 48
2016 年全新原创
C 语言实现农历万年历
paradise300
① 保留位始终为 0; ② 农历正月初一距离公历元旦的天数; ③ 0 表示无闰月,1 至 12 表示闰月月份; ④ 从低位到高位分别对应从正月到(闰)十二月的每个月的大小,“1”表 示大月,即该月有 30 天,“0”表示小月,即该月有 29 天。
//1899年农历十月及以后的月份,每月初一在1900年内的序数。 //cPreMonth中分别对应农历的十月、十一月、十二月、正月。 char const cPreMonth[4]={-59,-29,0,30};
//农历月份信息。一年用个字节表示
//+-----------------------------------------------------------------------+
节气数据:
经统计,公历年的首个节气均为“小寒”。
第 47 至 46 位
第 45 至 0 位
小寒的年内序数减 3 从大寒到冬至每个节气 2 个位,表示距上一节气天数
5 / 48
2016 年全新原创
C 语言实现农历万年历
paradise300
其中第一部分,在使用时,两位数据需要加上 3,才能得到小寒的年内序数, 第二部分,第 45 至 44 位,表示了大寒距离小寒的天数,第 43 至 42 位,表示立 春距离大寒的天数,……以此类推。

万年历代码c语言

万年历代码c语言

万年历代码c语言万年历是一种实用的日历工具,它可以根据年、月、日来显示当天的日期信息,并可以切换到其他日期来查询对应的日期信息。

在编写万年历的代码时,我们需要考虑输入的年份是否为闰年、每个月的天数、以及每个月第一天是星期几等等。

以下是一份使用C语言编写万年历的参考代码:```c#include <stdio.h>// 判断是否为闰年int isLeapYear(int year) {return (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0); }// 获取某年某月的天数int getMonthDays(int year, int month) {int days[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};if (month == 2 && isLeapYear(year)) {return 29;}return days[month - 1];}// 获取某年某月第一天是星期几int getFirstDayOfWeek(int year, int month) {int day = 1;for (int i = 1800; i < year; i++) {if (isLeapYear(i)) {day = (day + 366) % 7;} else {day = (day + 365) % 7;}}for (int i = 1; i < month; i++) {day = (day + getMonthDays(year, i)) % 7;}return day;}int main() {int year, month;printf("请输入年份:");scanf("%d", &year);printf("请输入月份:");scanf("%d", &month);// 判断输入是否合法if (year < 1800 || month < 1 || month > 12) {printf("输入的年份或月份不合法!\n");return 0;}// 获取某年某月的天数和第一天是星期几int days = getMonthDays(year, month);int firstDayOfWeek = getFirstDayOfWeek(year, month); // 打印万年历printf("日一二三四五六\n");for (int i = 0; i < firstDayOfWeek; i++) {printf(" ");}for (int i = 1; i <= days; i++) {printf("%2d ", i);if ((firstDayOfWeek + i) % 7 == 0) {printf("\n");}}printf("\n");return 0;}```以上代码实现了一个简单的万年历功能,在控制台输出给定年份和月份的月历。

c++万年历及公历农历转换源代码2

c++万年历及公历农历转换源代码2

#include <stdio.h>#include <stdlib.h>#include <conio.h>#define X " Sun Mon Tue Wed Thu Fri Sat"#define P printf#define B break#define FP fprintfstruct date /*日期*/{int year;int month;int date;};struct taglunarcal /**/{int basedays;int intercalation;int monthdays[13];}dalist[]={{31,8,0,1,0,0,1,0,1,1,0,1,1,0,1},{50,0,0,1,0,0,1,0,1,0,1,1,1,0,0},{39,0,1,0,1,0,0,1,0,1,0,1 ,1,1,0},{29,5,0,1,0,1,0,0,1,0,0,1,1,0,1},{47,0,1,1,0,1,0,0,1,0,0,1,1,0,0},{35,0,1,1,0,1,1,0,0,1,0,1,0,1,0},{25,4,0,1,1,0,1,0,1,0,1,0,1,0,1},{4 4,0,0,1,0,1,0,1,1,0,1,0,1,0,0},{33,0,1,0,0,1,1,0,1,0,1,1,0,1,0},{22,2,0,1,0,0,1,0,1,0,1,1,1,0,1},{41,0,0,1,0,0,1,0,1,0,1,1,1,0,0},{3 0,6,1,0,1,0,0,1,0,0,1,1,0,1,1},{49,0,1,0,1,0,0,1,0,0,1,1,0,1,0},{37,0,1,1,0,1,0,0,1,0,0,1,0,1,0},{26,5,1,1,0,1,0,1,0,1,0,1,0,0,1},{4 5,0,1,0,1,1,0,1,0,1,0,1,0,1,0},{35,0,0,1,0,1,0,1,1,0,1,0,1,0,0},{23,2,1,0,0,1,0,1,1,0,1,1,0,1,0},{42,0,1,0,0,1,0,1,0,1,1,0,1,1,0},{3 2,7,0,1,0,0,1,0,0,1,1,0,1,1,1},{51,0,0,1,0,0,1,0,0,1,1,0,1,1,0},{39,0,1,0,1,0,0,1,0,0,1,0,1,1,0},{28,5,1,0,1,1,0,0,1,0,0,1,0,1,1},{4 7,0,0,1,1,0,1,0,1,0,0,1,0,1,0},{36,0,0,1,1,0,1,1,0,1,0,1,0,0,0},{24,4,1,0,1,0,1,1,0,1,1,0,1,0,1},{44,0,0,0,1,0,1,0,1,1,0,1,1,0,0},{3 3,0,1,0,0,1,0,1,0,1,0,1,1,1,0},{23,2,0,1,0,0,1,0,0,1,0,1,1,1,1},{41,0,0,1,0,0,1,0,0,1,0,1,1,1,0},{30,6,0,1,1,0,0,1,0,0,1,0,1,1,0},{4 8,0,1,1,0,1,0,1,0,0,1,0,1,0,0},{37,0,1,1,1,0,1,0,1,0,0,1,0,1,0},{26,5,0,1,1,0,1,1,0,1,0,1,0,0,1},{45,0,0,1,0,1,1,0,1,0,1,1,0,1,0},{3 5,0,0,0,1,0,1,0,1,1,0,1,1,0,0},{24,3,1,0,0,1,0,0,1,1,0,1,1,1,0},{42,0,1,0,0,1,0,0,1,0,1,1,1,0,0},{31,7,1,1,0,0,1,0,0,1,0,1,1,0,1},{5 0,0,1,1,0,0,1,0,0,1,0,1,0,1,0},{39,0,1,1,0,1,0,1,0,0,1,0,1,0,0},{27,6,1,1,0,1,1,0,1,0,0,1,0,1,0},{46,0,1,0,1,1,0,1,0,1,0,1,0,1,0},{3 6,0,0,1,0,1,0,1,1,0,1,0,1,0,0},{25,4,1,0,1,0,1,0,1,0,1,1,0,1,1},{44,0,0,0,1,0,0,1,0,1,1,1,0,1,0},{33,0,1,0,0,1,0,0,1,0,1,1,0,1,0},{2 2,2,1,1,0,0,1,0,0,1,0,1,0,1,1},7,0,1,0,1,1,0,1,0,1,0,1,0,1,0},{27,5,0,1,0,1,0,1,0,1,1,0,1,0,1},{45,0,0,1,0,0,1,1,0,1,1,0,1,0,0},{34,0,1,0,1,0,0,1,0,1,1,0,1,1,0},{2 4,3,0,1,0,1,0,0,1,0,1,0,1,1,1},{43,0,0,1,0,1,0,0,1,0,1,0,1,1,0},{31,8,1,0,1,0,1,0,0,1,0,1,0,1,0},{49,0,1,1,1,0,1,0,0,1,0,1,0,1,0},{3 9,0,0,1,1,0,1,0,1,0,1,0,1,0,0},{28,6,1,0,1,0,1,1,0,1,0,1,0,1,0},{46,0,1,0,1,0,1,0,1,1,0,1,0,1,0},{36,0,0,1,0,0,1,0,1,1,0,1,1,0,0},{2 5,4,1,0,1,0,0,1,0,1,0,1,1,1,0},{44,0,1,0,1,0,0,1,0,1,0,1,1,1,0},{33,0,0,1,0,1,0,0,1,0,0,1,1,0,0},{21,3,1,1,1,0,1,0,0,1,0,0,1,1,0},{4 0,0,1,1,0,1,1,0,0,1,0,1,0,1,0},{30,7,0,1,0,1,1,0,1,0,1,0,1,0,1},{48,0,0,1,0,1,0,1,1,0,1,0,1,0,0},{37,0,1,0,0,1,0,1,1,0,1,1,0,1,0},{2 7,5,0,1,0,0,1,0,1,0,1,1,1,0,1},{46,0,0,1,0,0,1,0,1,0,1,1,0,1,0},{34,0,1,0,1,0,0,1,0,0,1,1,0,1,0},{23,4,1,1,0,1,0,0,1,0,0,1,1,0,1},{4 2,0,1,1,0,1,0,0,1,0,0,1,0,1,0},{31,8,1,1,0,1,0,1,0,1,0,0,1,0,1},{49,0,1,0,1,1,0,1,0,1,0,1,0,0,0},{38,0,1,0,1,1,0,1,1,0,1,0,1,0,0},{2 8,6,1,0,0,1,0,1,1,0,1,1,0,1,0},{47,0,1,0,0,1,0,1,0,1,1,0,1,1,0},{36,0,0,1,0,0,1,0,0,1,1,0,1,1,0},{25,4,1,0,1,0,0,1,0,0,1,0,1,1,1},{4 4,0,1,0,1,0,0,1,0,0,1,0,1,1,0},{33,0,1,0,1,1,0,0,1,0,0,1,0,1,1},{51,0,0,1,1,0,1,0,1,0,0,1,0,1,0},{40,0,0,1,1,0,1,1,0,1,0,1,0,0,0},{2 9,6,1,0,1,0,1,1,0,1,1,0,1,0,0},{48,0,1,0,1,0,1,0,1,1,0,1,1,0,0},{37,0,1,0,0,1,0,0,1,1,0,1,1,1,0},{27,5,0,1,0,0,1,0,0,1,0,1,1,1,1},{4 6,0,0,1,0,0,1,0,0,1,0,1,1,1,0},{35,0,0,1,1,0,0,1,0,0,1,0,1,1,0},{23,3,0,1,1,0,1,0,1,0,0,1,0,1,0},{41,0,1,1,1,0,1,0,1,0,0,1,0,1,0},{3 1,8,0,1,1,0,1,0,1,1,0,0,1,0,1},{50,0,0,1,0,1,1,0,1,0,1,1,0,0,0},{38,0,1,0,1,0,1,0,1,1,0,1,1,0,0},{28,5,1,0,0,1,0,0,1,1,0,1,1,0,1},{4 7,0,1,0,0,1,0,0,1,0,1,1,1,0,0},{36,0,1,1,0,0,1,0,0,1,0,1,1,0,0},{24,4,1,1,0,1,0,1,0,0,1,0,1,0,1},{43,0,1,1,0,1,0,1,0,0,1,0,1,0,0},{3 2,0,1,1,0,1,1,0,1,0,0,1,0,1,0},{22,2,0,1,0,1,1,0,1,0,1,0,1,0,1},{40,0,0,1,0,1,0,1,1,0,1,0,1,0,0},{29,7,1,0,1,0,1,0,1,0,1,1,0,1,1},{4 9,0,0,0,1,0,0,1,0,1,1,1,0,1,0},{38,0,1,0,0,1,0,0,1,0,1,1,0,1,0},{26,5,1,1,0,0,1,0,0,1,0,1,0,1,1},{45,0,1,0,1,0,1,0,0,1,0,1,0,1,0},{4 5,0,1,0,1,1,0,1,0,0,1,0,1,0,0},{23,4,1,0,1,1,1,0,1,0,1,0,1,0,1},{41,0,1,0,1,0,1,1,0,1,0,1,0,1,0},{31,9,0,1,0,1,0,1,0,1,1,1,0,1,1},{5 0,0,0,1,0,0,1,0,1,1,1,0,1,0,0},{39,0,1,0,1,0,0,1,0,1,1,0,1,1,0},{28,6,0,1,0,1,0,0,0,1,0,1,1,1,0},{47,0,0,1,0,1,0,0,1,0,1,0,1,1,0},{3 6,0,1,0,1,0,1,0,0,1,0,0,1,1,0},{25,4,0,1,1,1,1,0,0,1,0,1,0,1,1},{43,0,0,1,1,0,1,0,1,0,1,0,1,0,0},{32,0,1,0,1,0,1,1,0,1,0,1,0,1,0},{2 2,2,0,1,0,1,1,0,1,1,0,1,0,1,1},{41,0,0,1,0,0,1,0,1,1,0,1,1,0,0},{29,6,1,0,1,0,0,1,1,0,1,1,1,0,1},{48,0,1,0,1,0,0,1,0,0,1,1,1,0,0},{3 7,0,1,1,0,1,0,0,1,0,0,1,1,0,0},{26,5,1,1,1,0,1,0,1,0,0,1,1,0,1},{44,0,1,1,0,1,0,1,0,1,0,0,1,1,0},{34,0,0,1,0,1,1,0,1,0,1,0,1,0,0},{2 3,3,0,1,1,1,0,1,1,0,1,0,1,0,1},{42,0,1,0,0,1,0,1,1,0,1,1,0,1,0},{31,7,0,1,0,0,1,0,1,1,1,1,0,1,1},{50,0,0,1,0,0,1,0,1,0,1,1,0,1,0},{3 9,0,1,0,1,0,0,1,0,0,1,1,0,1,0},4,5,1,1,0,1,1,1,0,1,0,1,0,0,1},{43,0,1,0,1,1,0,1,0,1,1,0,1,0,0},{32,0,0,1,0,1,0,1,1,0,1,1,0,1,0},{22,2,0,1,0,1,0,1,0,1,1,0,1,1,1},{4 1,0,0,1,0,0,1,0,0,1,1,0,1,1,0},{30,7,1,0,1,0,0,1,0,1,0,1,1,1,0},{48,0,1,0,1,0,0,1,0,0,1,0,1,1,0},{37,0,1,0,1,0,1,0,1,0,0,1,0,1,0},{2 6,5,1,0,1,1,0,0,1,0,0,1,0,1,0},{45,0,0,1,1,0,1,1,0,1,0,0,1,0,0},{33,0,1,0,1,0,1,1,0,1,1,0,1,0,0},{23,3,0,1,0,0,1,0,1,1,0,1,1,0,0},{4 2,0,1,0,0,1,0,0,1,1,0,1,1,1,0},{32,8,0,1,0,0,1,0,0,1,1,1,1,1,1},{50,0,0,1,0,0,1,0,0,1,0,1,1,1,0},{39,0,0,1,1,0,0,1,0,0,1,0,1,1,0},{2 8,6,0,1,1,0,1,0,0,0,1,0,1,0,0},{46,0,1,1,1,0,1,0,1,0,0,1,0,1,0},{35,0,0,1,1,0,1,0,1,1,0,0,1,0,0},{24,4,1,0,1,0,0,1,1,0,1,1,0,0,0},{4 3,0,1,0,1,0,1,0,1,0,1,1,1,0,0},{33,0,1,0,0,1,0,0,1,0,1,1,1,0,0},{21,3,1,1,0,1,0,0,1,0,1,1,1,0,0},{40,0,1,1,0,0,1,0,0,1,0,1,1,0,0},{2 9,7,1,1,0,1,0,1,0,1,0,1,0,1,0},{48,0,1,1,0,1,0,1,0,0,1,0,1,0,0},{36,0,1,1,0,1,1,0,1,0,0,1,0,1,0},{26,5,0,1,0,1,1,1,0,1,0,1,0,1,1},{4 5,0,0,1,0,1,0,1,1,0,1,0,1,0,0},{34,0,1,0,1,0,0,1,1,0,1,1,0,1,0},{23,4,0,1,0,1,0,1,0,1,1,1,0,1,1},{42,0,0,1,0,1,0,0,1,0,1,1,0,1,0},{3 1,8,1,0,1,0,1,0,0,1,1,0,1,1,1},{50,0,1,0,1,0,1,0,0,1,0,1,0,1,0},{38,0,1,0,1,1,0,1,0,0,1,0,1,0,0},{27,6,1,0,1,1,0,1,1,0,1,0,1,0,1},{4 6,0,1,0,1,0,1,1,0,1,0,1,0,1,0},{36,0,0,1,0,1,0,1,0,1,1,0,1,0,0},{24,4,1,0,1,0,1,0,1,1,1,0,1,0,0},{43,0,1,0,1,0,0,1,0,1,1,0,1,1,0},{3 3,0,0,1,0,1,0,0,1,0,1,0,1,1,0},{22,3,1,0,1,1,0,0,1,0,0,1,1,1,1},{40,0,0,1,1,0,1,0,0,1,0,0,1,1,0},{29,7,0,1,1,1,0,0,1,1,0,0,1,1,1},{4 8,0,0,1,1,0,1,0,1,0,1,0,1,0,0},{37,0,1,0,1,0,1,1,0,1,0,1,0,1,0},{26,5,0,1,0,0,1,0,1,1,0,1,0,1,1},{45,0,0,1,0,0,1,0,1,1,0,1,1,0,0},{3 4,0,1,0,1,0,0,1,0,1,0,1,1,1,0},{24,4,0,1,0,1,0,1,0,0,1,1,1,0,1},{41,0,1,1,0,1,0,0,1,0,0,1,1,0,0},{30,8,1,1,1,0,1,0,0,1,0,1,1,0,1},{4 9,0,1,1,0,1,0,1,0,1,0,0,1,0,0},{38,0,1,1,0,1,1,0,1,0,1,0,1,0,0},{27,6,0,1,1,0,1,0,1,0,1,0,1,0,0},{46,0,0,1,0,1,0,1,1,0,1,1,0,1,0},{3 6,0,0,1,0,0,1,0,1,0,1,1,1,0,0},{25,4,1,0,1,0,1,0,0,1,1,1,0,1,0},{43,0,1,0,1,0,0,1,0,0,1,1,0,1,0},{32,0,1,0,1,0,0,0,0,1,0,1,0,1,0},{2 1,2,1,1,1,1,0,0,1,0,0,1,0,1,1},{40,0,1,1,0,1,0,1,0,1,0,0,1,0,0}};getleap( int year ) /*1代表闰年*/{if ( year % 400 == 0 )return 1;else if ( year % 100 == 0 )return 0;else if ( year % 4 == 0 )return 1;elsereturn 0;}print(int n){int i;for(i=0;i<n;i++) printf(" ");}int day(int year){long a,b;if(year<=2000){a=2000-year;b=6-(a+a/4-a/100+a/400)%7; return b;}else{a=year-2000; b=(a+1+(a-1)/4-(a-1)/100+(a-1)/400)%7+6; return b%7; }}solardate(struct date * input) /*公历年第几天*/{int i,number=0,solarcal[12]={31,28,31,30,31,30,31,31,30,31,30,31}; number=getleap(input->year);for(i=0;i<input->month-1;i++){number+=solarcal[i];}return number+input->date;}lunardate(struct date *input)/*农历年第几天*/{int i,leap=0,number=0;if(dalist[input->year-1900].intercalation==0)leap=0;else if(input->month==dalist[input->year-1900].intercalation){printf(" 0 not leap month\n 1 leap month");scanf("%d",&leap);}else if(input->month>dalist[input->year-1900].intercalation) leap=1;for(i=0;i<input->month+leap-1;i++)number+=dalist[input->year-1900].monthdays[i]+29;return number+input->date;}lunarmonth(int year,int *mon){int i,j;mon[0]=dalist[year].monthdays[0]+29;for(i=1,j=1;i<12;i++,j++){if(i==dalist[year].intercalation){mon[i-1]+=dalist[year].monthdays[j]+29;j++;}mon[i]=mon[i-1]+dalist[year].monthdays[j]+29;}}main(){int i,j,k,m,n,f1,f2,year,d,y,ly,cord,greday,lunday,diff,add,leap,tlylm[12],lastylm[12],a[13]={0,31,28,31,30,31,30,31,31,30,31,30,31},SolarDays[2][12] = {{31,59,90,120,151,181,212,243,273,304,334,365},{31,60,91,121,152,182,213,244,274,305,335, 366}};char fname[12]={"0"}; FILE *fw;struct date input;do{printf("\n--------------------------------------------\n");printf(" 请选择");printf("\n--------------------------------------------\n");printf(" 1 公历转换成农历");printf("\n--------------------------------------------\n");printf(" 2 农历转换成公历");printf("\n--------------------------------------------\n");printf(" 3 万年历");printf("\n--------------------------------------------\n");printf(" 4 退出");printf("\n--------------------------------------------\n");printf("\n 请选择: 1,2,3,4\n");scanf("%d",&cord);clrscr();switch(cord){case 1:{printf("\n(公历) 请输入年.月.日(yyyy.mm.dd) \n");scanf("%d.%d.%d",&input.year,&input.month,&input.date);/*输入年月日*/y=input.year;greday=solardate(&input);/*公历年第几天*/diff=greday-dalist[y-1900].basedays;if(diff>0)lunarmonth(y-1900,tlylm);else{y-=1;lunarmonth(y-1900,tlylm);diff+=tlylm[11];}for(i=0;tlylm[i]<diff;i++);if(i!=0)diff-=tlylm[i-1];printf("(农历) %d.%d.%d",y,i+1,diff);break;}clrscr();case 2:{printf("\n(农历) 请输入年.月.日(yyyy.mm.dd) \n");scanf("%d.%d.%d",&input.year,&input.month,&input.date);y=input.year;ly=getleap(y);lunday=lunardate(&input);/*农历年第几天*/add=lunday+dalist[y-1900].basedays;if(add-365+ly>0){add-=365+ly;y+=1;}for(i=0;SolarDays[ly][i]<add;i++);if(i!=0)add-=SolarDays[ly][i-1];printf("(公历) %d.%d.%d",y,i+1,add);break;}case 3:{system("cls");P(" 请输入你所要查看的年份:");scanf("%d",&year);fw=fopen(fname,"w+");if(fw==NULL){P(" can not open file."); return;}P(" The calendar of the year %d.\n",year);FP(fw,"The calendar of the year %d.\n",year);d=day(year);if(year%4==0&&year%100||year%400==0) a[2]++;for(i=1;i<=12;i+=2){m=0; n=0; f1=0; f2=0;switch(i){case 1:P(" Januray 1 "); FP(fw," Januray 1 "); B; case 3:P(" March 3 "); FP(fw," March 3 "); B; case 5:P(" May 5 "); FP(fw," May 5 "); B; case 7:P(" July 7 "); FP(fw," July 7 "); B; case 9:P(" September 9 "); FP(fw," September 9 "); B; case 11:P(" Nevember 11 "); FP(fw," Nevember 11 "); B; }print(21);for(k=0;k<21;k++) fprintf(fw," ");switch(i+1){case 2:P(" February 2 "); FP(fw," February 2 ");B; case 4:P(" April 4 "); FP(fw," April 4 ");B;case 6:P(" June 6 "); FP(fw," June 6 ");B; case 8:P(" August 8 "); FP(fw," August 8 "); B; case 10:P(" October 10 "); FP(fw," October 10 ");B; case 12:P(" December 12"); FP(fw," December 12");B;}P("\n");fprintf(fw,"\n");P(X); fprintf(fw,X); print(6);fprintf(fw," "); P(X); fprintf(fw,X);fprintf(fw,"\n"); P("\n");for(j=0;j<6;j++){if(j==0){print(d*4); for(k=0;k<d*4;k++) fprintf(fw," ");for(k=0;k<7-d;k++){P("%4d",++m); fprintf(fw,"%4d",m);}print(6); fprintf(fw," ");d+=a[i]%7; d%=7;print(d*4); for(k=0;k<d*4;k++) fprintf(fw," ");for(k=0;k<7-d;k++){P("%4d",++n); fprintf(fw,"%4d",n);}P("\n"); fprintf(fw,"\n");}else{for(k=0;k<7;k++){if(m<a[i]){P("%4d",++m); fprintf(fw,"%4d",m);}else{print(4); fprintf(fw,"");}if(m==a[i]) f1=1;}print(6); fprintf(fw," ");for(k=0;k<7;k++){if(n<a[i+1]){P("%4d",++n);fprintf(fw,"%4d",n);}else{print(4); fprintf(fw,"");}if(n==a[i+1]) f2=1;}P("\n"); fprintf(fw,"\n");if(f1&&f2) B;}}d+=a[i+1]%7; d%=7; P(" "); fprintf(fw," "); if(i==5){getch();system("cls");}}fclose(fw);getch();break;}case 4:{exit(0);}}}while(cord<=4);}。

农历转换函数C语言版

农历转换函数C语言版

农历转换函数(C语言版)char *GetDayOf(PSYSTEMTIME pSt){/*天干名称*/const char *cTianGan[] = {&quot;甲&quot;,&quot;乙&quot;,&quot;丙&quot;,&quot;丁&quot;,&quot;戊&quot;,&quot;己&quot;,&quot;庚&quot;,&quot;辛&quot;,&quot;壬&quot;,&quot;癸&quot;};/*地支名称*/const char *cDiZhi[] = {&quot;子&quot;,&quot;丑&quot;,&quot;寅&quot;,&quot;卯&quot;,&quot;辰&quot;,&quot;巳&quot;,&quot;午&quot;,&quot;未&quot;,&quot;申&quot;,&quot;酉&quot;,&quot;戌&quot;,&quot;亥&quot;};/*属相名称*/const char *cShuXiang[] = {&quot;鼠&quot;,&quot;牛&quot;,&quot;虎&quot;,&quot;兔&quot;,&quot;龙&quot;,&quot;蛇&quot;,&quot;马&quot;,&quot;羊&quot;,&quot;猴&quot;,&quot;鸡&quot;,&quot;狗&quot;,&quot;猪&quot;};/*农历日期名*/const char *cDayName[] = {&quot;*&quot;,&quot;初一&quot;,&quot;初二&quot;,&quot;初三&quot;,&quot;初四&quot;,&quot;初五&quot;,&quot;初六&quot;,&quot;初七&quot;,&quot;初八&quot;,&quot;初九&quot;,&quot;初十&quot;,&quot;十一&quot;,&quot;十二&quot;,&quot;十三&quot;,&quot;十四&quot;,&quot;十五&quot;,&quot;十六&quot;,&quot;十七&quot;,&quot;十八&quot;,&quot;十九&quot;,&quot;二十&quot;,&quot;廿一&quot;,&quot;廿二&quot;,&quot;廿三&quot;,&quot;廿四&quot;,&quot;廿五&quot;,&quot;廿六&quot;,&quot;廿七&quot;,&quot;廿八&quot;,&quot;廿九&quot;,&quot;三十&quot;};/*农历月份名*/const char *cMonName[] = {&quot;*&quot;,&quot;正&quot;,&quot;二&quot;,&quot;三&quot;,&quot;四&quot;,&quot;五&quot;,&quot;六&quot;,&quot;七&quot;,&quot;八&quot;,&quot;九&quot;,&quot;十&quot;,&quot;十一&quot;,&quot;腊&quot;};/*公历每月前面的天数*/const int wMonthAdd[12] ={0,31,59,90,120,151,181,212,243,273,304,334};/*农历数据*/const int wNongliData[100] ={2635,333387,1701,1748,267701,694,2391,133423,117 5,396438,3402,3749,331177,1453,694,201326,2350,465197,322 1,3402,400202,2901,1386,267611,605,2349,137515,2709,464 533,1738,2901,330421,1242,2651,199255,1323,529706,3733,17 06,398762,2741,1206,267438,2647,1318,204070,3477,461653,13 86,2413,330077,1197,2637,268877,3365,531109,2900,2922,39 8042,2395,1179,267415,2635,661067,1701,1748,398772,2742,23 91,330031,1175,1611,200010,3749,527717,1452,2742,332397,23 50,3222,268949,3402,3493,133973,1386,464219,605,2349,334 123,2709,2890,267946,2773,592565,1210,2651,395863,1323,27 07,265877};static int wCurYear,wCurMonth,wCurDay;static int nTheDate,nIsEnd,m,k,n,i,nBit;TCHAR szNongli[30], szNongliDay[10],szShuXiang[10]; /*---取当前公历年、月、日---*/wCurYear = pSt->;wYear;wCurMonth = pSt->;wMonth;wCurDay = pSt->;wDay;/*---计算到初始时间1921年2月8日的天数:1921-2-8(正月初一)---*/nTheDate = (wCurYear - 1921) * 365 + (wCurYear - 1921) / 4 + wCurDay + wMonthAdd[wCurMonth - 1] - 38;if((!(wCurYear % 4)) && (wCurMonth >; 2)) nTheDate = nTheDate + 1;/*--计算农历天干、地支、月、日---*/nIsEnd = 0;m = 0;while(nIsEnd != 1){if(wNongliData[m] ;=0)//获取wNongliData(m)的第n个二进制位的值nBit = wNongliData[m];for(i=1;i; wNongliData[m] / 65536 + 1) wCurMonth = wCurMonth - 1;}/*--生成农历天干、地支、属相 ==>; wNongli--*/ wsprintf(szShuXiang,&quot;%s&quot;,cShuXiang[((wC urYear - 4) % 60) % 12]);wsprintf(szNongli,&quot;%s(%s%s)年&quot;,szShuXiang,cTianGan[((wCurYear - 4) % 60) % 10],cDiZhi[((wCurYear - 4) % 60) % 12]);/*--生成农历月、日 ==>; wNongliDay--*/if (wCurMonth < 1)wsprintf(szNongliDay,&quot;闰%s&quot;,cMonName[-1 * wCurMonth]);elsestrcpy(szNongliDay,cMonName[wCurMonth]);strcat(szNongliDay,&quot;月&quot;);strcat(szNongliDay,cDayName[wCurDay]);return strcat(szNongli,szNongliDay);}。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

//基于1602液晶显示的程序设计#include<reg52.h>//C51写的公历转农历和星期#define uchar unsigned char#define uint unsigned int/*公历年对应的农历数据,每年三字节,格式第一字节BIT7-4 位表示闰月月份,值为0 为无闰月,BIT3-0 对应农历第1-4 月的大小第二字节BIT7-0 对应农历第5-12 月大小,第三字节BIT7 表示农历第13 个月大小月份对应的位为1 表示本农历月大(30 天),为0 表示小(29 天)第三字节BIT6-5 表示春节的公历月份,BIT4-0 表示春节的公历日期*/code uchar year_code[597] = {0x04,0xAe,0x53, //19010x0A,0x57,0x48, //19020x55,0x26,0xBd, //19030x0d,0x26,0x50, //19040x0d,0x95,0x44, //19050x46,0xAA,0xB9, //19060x05,0x6A,0x4d, //19070x09,0xAd,0x42, //19080x24,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, //19300x0e,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, //19740x8d,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, //1999 294 0x0C,0x96,0x45, //2000 297 0x4d,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, //20180x47,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, //20620x0d,0x4A,0x51, //20640x0d,0xA5,0x45, //20650x55,0xAA,0xBA, //20660x05,0x6A,0x4e, //20670x0A,0x6d,0x43, //20680x45,0x2e,0xB7, //20690x05,0x2d,0x4B, //20700x8A,0x95,0xBf, //20710x0A,0x95,0x53, //20720x0B,0x4A,0x47, //20730x6B,0x55,0x3B, //20740x0A,0xd5,0x4f, //20750x05,0x5A,0x45, //20760x4A,0x5d,0x38, //20770x0A,0x5B,0x4C, //20780x05,0x2B,0x42, //20790x3A,0x93,0xB6, //20800x06,0x93,0x49, //20810x77,0x29,0xBd, //20820x06,0xAA,0x51, //20830x0A,0xd5,0x46, //20840x54,0xdA,0xBA, //20850x04,0xB6,0x4e, //20860x0A,0x57,0x43, //20870x45,0x27,0x38, //20880x0d,0x26,0x4A, //20890x8e,0x93,0x3e, //20900x0d,0x52,0x52, //20910x0d,0xAA,0x47, //20920x66,0xB5,0x3B, //20930x05,0x6d,0x4f, //20940x04,0xAe,0x45, //20950x4A,0x4e,0xB9, //20960x0A,0x4d,0x4C, //20970x0d,0x15,0x41, //20980x2d,0x92,0xB5, //2099};code uchar jieqi_code[]={0x96,0xB4,0x96,0xA6,0x97,0x97,0x78,0x79,0x79,0x69,0x78,0x77, //1901 0x96,0xA4,0x96,0x96,0x97,0x87,0x79,0x79,0x79,0x69,0x78,0x78, //19020x96,0xA5,0x87,0x96,0x87,0x87,0x79,0x69,0x69,0x69,0x78,0x78, //19030x86,0xA5,0x96,0xA5,0x96,0x97,0x88,0x78,0x78,0x79,0x78,0x87, //19040x96,0xA4,0x96,0x96,0x97,0x97,0x79,0x79,0x79,0x69,0x78,0x78, //1906 0x96,0xA5,0x87,0x96,0x87,0x87,0x79,0x69,0x69,0x69,0x78,0x78, //1907 0x86,0xA5,0x96,0xA5,0x96,0x97,0x88,0x78,0x78,0x69,0x78,0x87, //1908 0x96,0xB4,0x96,0xA6,0x97,0x97,0x78,0x79,0x79,0x69,0x78,0x77, //1909 0x96,0xA4,0x96,0x96,0x97,0x97,0x79,0x79,0x79,0x69,0x78,0x78, //1910 0x96,0xA5,0x87,0x96,0x87,0x87,0x79,0x69,0x69,0x69,0x78,0x78, //1911 0x86,0xA5,0x96,0xA5,0x96,0x97,0x88,0x78,0x78,0x69,0x78,0x87, //1912 0x95,0xB4,0x96,0xA6,0x97,0x97,0x78,0x79,0x79,0x69,0x78,0x77, //1913 0x96,0xB4,0x96,0xA6,0x97,0x97,0x79,0x79,0x79,0x69,0x78,0x78, //1914 0x96,0xA5,0x97,0x96,0x97,0x87,0x79,0x79,0x69,0x69,0x78,0x78, //1915 0x96,0xA5,0x96,0xA5,0x96,0x97,0x88,0x78,0x78,0x79,0x77,0x87, //1916 0x95,0xB4,0x96,0xA6,0x96,0x97,0x78,0x79,0x78,0x69,0x78,0x87, //1917 0x96,0xB4,0x96,0xA6,0x97,0x97,0x79,0x79,0x79,0x69,0x78,0x77, //1918 0x96,0xA5,0x97,0x96,0x97,0x87,0x79,0x79,0x69,0x69,0x78,0x78, //1919 0x96,0xA5,0x96,0xA5,0x96,0x97,0x88,0x78,0x78,0x79,0x77,0x87, //1920 0x95,0xB4,0x96,0xA5,0x96,0x97,0x78,0x79,0x78,0x69,0x78,0x87, //1921 0x96,0xB4,0x96,0xA6,0x97,0x97,0x79,0x79,0x79,0x69,0x78,0x77, //1922 0x96,0xA4,0x96,0x96,0x97,0x87,0x79,0x79,0x69,0x69,0x78,0x78, //1923 0x96,0xA5,0x96,0xA5,0x96,0x97,0x88,0x78,0x78,0x79,0x77,0x87, //1924 0x95,0xB4,0x96,0xA5,0x96,0x97,0x78,0x79,0x78,0x69,0x78,0x87, //1925 0x96,0xB4,0x96,0xA6,0x97,0x97,0x78,0x79,0x79,0x69,0x78,0x77, //1926 0x96,0xA4,0x96,0x96,0x97,0x87,0x79,0x79,0x79,0x69,0x78,0x78, //1927 0x96,0xA5,0x96,0xA5,0x96,0x96,0x88,0x78,0x78,0x78,0x87,0x87, //1928 0x95,0xB4,0x96,0xA5,0x96,0x97,0x88,0x78,0x78,0x79,0x77,0x87, //1929 0x96,0xB4,0x96,0xA6,0x97,0x97,0x78,0x79,0x79,0x69,0x78,0x77, //1930 0x96,0xA4,0x96,0x96,0x97,0x87,0x79,0x79,0x79,0x69,0x78,0x78, //1931 0x96,0xA5,0x96,0xA5,0x96,0x96,0x88,0x78,0x78,0x78,0x87,0x87, //1932 0x95,0xB4,0x96,0xA5,0x96,0x97,0x88,0x78,0x78,0x69,0x78,0x87, //1933 0x96,0xB4,0x96,0xA6,0x97,0x97,0x78,0x79,0x79,0x69,0x78,0x77, //1934 0x96,0xA4,0x96,0x96,0x97,0x97,0x79,0x79,0x79,0x69,0x78,0x78, //1935 0x96,0xA5,0x96,0xA5,0x96,0x96,0x88,0x78,0x78,0x78,0x87,0x87, //1936 0x95,0xB4,0x96,0xA5,0x96,0x97,0x88,0x78,0x78,0x69,0x78,0x87, //1937 0x96,0xB4,0x96,0xA6,0x97,0x97,0x78,0x79,0x79,0x69,0x78,0x77, //1938 0x96,0xA4,0x96,0x96,0x97,0x97,0x79,0x79,0x79,0x69,0x78,0x78, //1939 0x96,0xA5,0x96,0xA5,0x96,0x96,0x88,0x78,0x78,0x78,0x87,0x87, //1940 0x95,0xB4,0x96,0xA5,0x96,0x97,0x88,0x78,0x78,0x69,0x78,0x87, //1941 0x96,0xB4,0x96,0xA6,0x97,0x97,0x78,0x79,0x79,0x69,0x78,0x77, //1942 0x96,0xA4,0x96,0x96,0x97,0x97,0x79,0x79,0x79,0x69,0x78,0x78, //1943 0x96,0xA5,0x96,0xA5,0xA6,0x96,0x88,0x78,0x78,0x78,0x87,0x87, //1944 0x95,0xB4,0x96,0xA5,0x96,0x97,0x88,0x78,0x78,0x79,0x77,0x87, //1945 0x95,0xB4,0x96,0xA6,0x97,0x97,0x78,0x79,0x78,0x69,0x78,0x77, //1946 0x96,0xB4,0x96,0xA6,0x97,0x97,0x79,0x79,0x79,0x69,0x78,0x78, //1947 0x96,0xA5,0xA6,0xA5,0xA6,0x96,0x88,0x88,0x78,0x78,0x87,0x87, //19480x95,0xB4,0x96,0xA5,0x96,0x97,0x78,0x79,0x78,0x69,0x78,0x77, //1950 0x96,0xB4,0x96,0xA6,0x97,0x97,0x79,0x79,0x79,0x69,0x78,0x78, //1951 0x96,0xA5,0xA6,0xA5,0xA6,0x96,0x88,0x88,0x78,0x78,0x87,0x87, //1952 0xA5,0xB4,0x96,0xA5,0x96,0x97,0x88,0x78,0x78,0x79,0x77,0x87, //1953 0x95,0xB4,0x96,0xA5,0x96,0x97,0x78,0x79,0x78,0x68,0x78,0x87, //1954 0x96,0xB4,0x96,0xA6,0x97,0x97,0x78,0x79,0x79,0x69,0x78,0x77, //1955 0x96,0xA5,0xA5,0xA5,0xA6,0x96,0x88,0x88,0x78,0x78,0x87,0x87, //1956 0xA5,0xB4,0x96,0xA5,0x96,0x97,0x88,0x78,0x78,0x79,0x77,0x87, //1957 0x95,0xB4,0x96,0xA5,0x96,0x97,0x88,0x78,0x78,0x69,0x78,0x87, //1958 0x96,0xB4,0x96,0xA6,0x97,0x97,0x78,0x79,0x79,0x69,0x78,0x77, //1959 0x96,0xA4,0xA5,0xA5,0xA6,0x96,0x88,0x88,0x88,0x78,0x87,0x87, //1960 0xA5,0xB4,0x96,0xA5,0x96,0x96,0x88,0x78,0x78,0x78,0x87,0x87, //1961 0x96,0xB4,0x96,0xA5,0x96,0x97,0x88,0x78,0x78,0x69,0x78,0x87, //1962 0x96,0xB4,0x96,0xA6,0x97,0x97,0x78,0x79,0x79,0x69,0x78,0x77, //1963 0x96,0xA4,0xA5,0xA5,0xA6,0x96,0x88,0x88,0x88,0x78,0x87,0x87, //1964 0xA5,0xB4,0x96,0xA5,0x96,0x96,0x88,0x78,0x78,0x78,0x87,0x87, //1965 0x95,0xB4,0x96,0xA5,0x96,0x97,0x88,0x78,0x78,0x69,0x78,0x87, //1966 0x96,0xB4,0x96,0xA6,0x97,0x97,0x78,0x79,0x79,0x69,0x78,0x77, //1967 0x96,0xA4,0xA5,0xA5,0xA6,0xA6,0x88,0x88,0x88,0x78,0x87,0x87, //1968 0xA5,0xB4,0x96,0xA5,0x96,0x96,0x88,0x78,0x78,0x78,0x87,0x87, //1969 0x95,0xB4,0x96,0xA5,0x96,0x97,0x88,0x78,0x78,0x69,0x78,0x87, //1970 0x96,0xB4,0x96,0xA6,0x97,0x97,0x78,0x79,0x79,0x69,0x78,0x77, //1971 0x96,0xA4,0xA5,0xA5,0xA6,0xA6,0x88,0x88,0x88,0x78,0x87,0x87, //1972 0xA5,0xB5,0x96,0xA5,0xA6,0x96,0x88,0x78,0x78,0x78,0x87,0x87, //1973 0x95,0xB4,0x96,0xA5,0x96,0x97,0x88,0x78,0x78,0x69,0x78,0x87, //1974 0x96,0xB4,0x96,0xA6,0x97,0x97,0x78,0x79,0x78,0x69,0x78,0x77, //1975 0x96,0xA4,0xA5,0xB5,0xA6,0xA6,0x88,0x89,0x88,0x78,0x87,0x87, //1976 0xA5,0xB4,0x96,0xA5,0x96,0x96,0x88,0x88,0x78,0x78,0x87,0x87, //1977 0x95,0xB4,0x96,0xA5,0x96,0x97,0x88,0x78,0x78,0x79,0x78,0x87, //1978 0x96,0xB4,0x96,0xA6,0x96,0x97,0x78,0x79,0x78,0x69,0x78,0x77, //1979 0x96,0xA4,0xA5,0xB5,0xA6,0xA6,0x88,0x88,0x88,0x78,0x87,0x87, //1980 0xA5,0xB4,0x96,0xA5,0xA6,0x96,0x88,0x88,0x78,0x78,0x77,0x87, //1981 0x95,0xB4,0x96,0xA5,0x96,0x97,0x88,0x78,0x78,0x79,0x77,0x87, //1982 0x95,0xB4,0x96,0xA5,0x96,0x97,0x78,0x79,0x78,0x69,0x78,0x77, //1983 0x96,0xB4,0xA5,0xB5,0xA6,0xA6,0x87,0x88,0x88,0x78,0x87,0x87, //1984 0xA5,0xB4,0xA6,0xA5,0xA6,0x96,0x88,0x88,0x78,0x78,0x87,0x87, //1985 0xA5,0xB4,0x96,0xA5,0x96,0x97,0x88,0x78,0x78,0x79,0x77,0x87, //1986 0x95,0xB4,0x96,0xA5,0x96,0x97,0x88,0x79,0x78,0x69,0x78,0x87, //1987 0x96,0xB4,0xA5,0xB5,0xA6,0xA6,0x87,0x88,0x88,0x78,0x87,0x86, //1988 0xA5,0xB4,0xA5,0xA5,0xA6,0x96,0x88,0x88,0x88,0x78,0x87,0x87, //1989 0xA5,0xB4,0x96,0xA5,0x96,0x96,0x88,0x78,0x78,0x79,0x77,0x87, //1990 0x95,0xB4,0x96,0xA5,0x86,0x97,0x88,0x78,0x78,0x69,0x78,0x87, //1991 0x96,0xB4,0xA5,0xB5,0xA6,0xA6,0x87,0x88,0x88,0x78,0x87,0x86, //19920xA5,0xB4,0x96,0xA5,0x96,0x96,0x88,0x78,0x78,0x78,0x87,0x87, //1994 0x95,0xB4,0x96,0xA5,0x96,0x97,0x88,0x76,0x78,0x69,0x78,0x87, //1995 0x96,0xB4,0xA5,0xB5,0xA6,0xA6,0x87,0x88,0x88,0x78,0x87,0x86, //1996 0xA5,0xB3,0xA5,0xA5,0xA6,0xA6,0x88,0x88,0x88,0x78,0x87,0x87, //1997 0xA5,0xB4,0x96,0xA5,0x96,0x96,0x88,0x78,0x78,0x78,0x87,0x87, //1998 0x95,0xB4,0x96,0xA5,0x96,0x97,0x88,0x78,0x78,0x69,0x78,0x87, //1999 0x96,0xB4,0xA5,0xB5,0xA6,0xA6,0x87,0x88,0x88,0x78,0x87,0x86, //2000 0xA5,0xB3,0xA5,0xA5,0xA6,0xA6,0x88,0x88,0x88,0x78,0x87,0x87, //2001 0xA5,0xB4,0x96,0xA5,0x96,0x96,0x88,0x78,0x78,0x78,0x87,0x87, //2002 0x95,0xB4,0x96,0xA5,0x96,0x97,0x88,0x78,0x78,0x69,0x78,0x87, //2003 0x96,0xB4,0xA5,0xB5,0xA6,0xA6,0x87,0x88,0x88,0x78,0x87,0x86, //2004 0xA5,0xB3,0xA5,0xA5,0xA6,0xA6,0x88,0x88,0x88,0x78,0x87,0x87, //2005 0xA5,0xB4,0x96,0xA5,0xA6,0x96,0x88,0x88,0x78,0x78,0x87,0x87, //2006 0x95,0xB4,0x96,0xA5,0x96,0x97,0x88,0x78,0x78,0x69,0x78,0x87, //2007 0x96,0xB4,0xA5,0xB5,0xA6,0xA6,0x87,0x88,0x87,0x78,0x87,0x86, //2008 0xA5,0xB3,0xA5,0xB5,0xA6,0xA6,0x88,0x88,0x88,0x78,0x87,0x87, //2009 0xA5,0xB4,0x96,0xA5,0xA6,0x96,0x88,0x88,0x78,0x78,0x87,0x87, //2010 0x95,0xB4,0x96,0xA5,0x96,0x97,0x88,0x78,0x78,0x79,0x78,0x87, //2011 0x96,0xB4,0xA5,0xB5,0xA5,0xA6,0x87,0x88,0x87,0x78,0x87,0x86, //2012 0xA5,0xB3,0xA5,0xB5,0xA6,0xA6,0x87,0x88,0x88,0x78,0x87,0x87, //2013 0xA5,0xB4,0x96,0xA5,0xA6,0x96,0x88,0x88,0x78,0x78,0x87,0x87, //2014 0x95,0xB4,0x96,0xA5,0x96,0x97,0x88,0x78,0x78,0x79,0x77,0x87, //2015 0x95,0xB4,0xA5,0xB4,0xA5,0xA6,0x87,0x88,0x87,0x78,0x87,0x86, //2016 0xA5,0xC3,0xA5,0xB5,0xA6,0xA6,0x87,0x88,0x88,0x78,0x87,0x87, //2017 0xA5,0xB4,0xA6,0xA5,0xA6,0x96,0x88,0x88,0x78,0x78,0x87,0x87, //2018 0xA5,0xB4,0x96,0xA5,0x96,0x96,0x88,0x78,0x78,0x79,0x77,0x87, //2019 0x95,0xB4,0xA5,0xB4,0xA5,0xA6,0x97,0x87,0x87,0x78,0x87,0x86, //2020 0xA5,0xC3,0xA5,0xB5,0xA6,0xA6,0x87,0x88,0x88,0x78,0x87,0x86, //2021 0xA5,0xB4,0xA5,0xA5,0xA6,0x96,0x88,0x88,0x88,0x78,0x87,0x87, //2022 0xA5,0xB4,0x96,0xA5,0x96,0x96,0x88,0x78,0x78,0x79,0x77,0x87, //2023 0x95,0xB4,0xA5,0xB4,0xA5,0xA6,0x97,0x87,0x87,0x78,0x87,0x96, //2024 0xA5,0xC3,0xA5,0xB5,0xA6,0xA6,0x87,0x88,0x88,0x78,0x87,0x86, //2025 0xA5,0xB3,0xA5,0xA5,0xA6,0xA6,0x88,0x88,0x88,0x78,0x87,0x87, //2026 0xA5,0xB4,0x96,0xA5,0x96,0x96,0x88,0x78,0x78,0x78,0x87,0x87, //2027 0x95,0xB4,0xA5,0xB4,0xA5,0xA6,0x97,0x87,0x87,0x78,0x87,0x96, //2028 0xA5,0xC3,0xA5,0xB5,0xA6,0xA6,0x87,0x88,0x88,0x78,0x87,0x86, //2029 0xA5,0xB3,0xA5,0xA5,0xA6,0xA6,0x88,0x88,0x88,0x78,0x87,0x87, //2030 0xA5,0xB4,0x96,0xA5,0x96,0x96,0x88,0x78,0x78,0x78,0x87,0x87, //2031 0x95,0xB4,0xA5,0xB4,0xA5,0xA6,0x97,0x87,0x87,0x78,0x87,0x96, //2032 0xA5,0xC3,0xA5,0xB5,0xA6,0xA6,0x88,0x88,0x88,0x78,0x87,0x86, //2033 0xA5,0xB3,0xA5,0xA5,0xA6,0xA6,0x88,0x78,0x88,0x78,0x87,0x87, //2034 0xA5,0xB4,0x96,0xA5,0xA6,0x96,0x88,0x88,0x78,0x78,0x87,0x87, //2035 0x95,0xB4,0xA5,0xB4,0xA5,0xA6,0x97,0x87,0x87,0x78,0x87,0x96, //20360xA5,0xB3,0xA5,0xA5,0xA6,0xA6,0x88,0x88,0x88,0x78,0x87,0x87, //20380xA5,0xB4,0x96,0xA5,0xA6,0x96,0x88,0x88,0x78,0x78,0x87,0x87, //20390x95,0xB4,0xA5,0xB4,0xA5,0xA6,0x97,0x87,0x87,0x78,0x87,0x96, //20400xA5,0xC3,0xA5,0xB5,0xA5,0xA6,0x87,0x88,0x87,0x78,0x87,0x86, //20410xA5,0xB3,0xA5,0xB5,0xA6,0xA6,0x88,0x88,0x88,0x78,0x87,0x87, //20420xA5,0xB4,0x96,0xA5,0xA6,0x96,0x88,0x88,0x78,0x78,0x87,0x87, //20430x95,0xB4,0xA5,0xB4,0xA5,0xA6,0x97,0x87,0x87,0x88,0x87,0x96, //20440xA5,0xC3,0xA5,0xB4,0xA5,0xA6,0x87,0x88,0x87,0x78,0x87,0x86, //20450xA5,0xB3,0xA5,0xB5,0xA6,0xA6,0x87,0x88,0x88,0x78,0x87,0x87, //20460xA5,0xB4,0x96,0xA5,0xA6,0x96,0x88,0x88,0x78,0x78,0x87,0x87, //20470x95,0xB4,0xA5,0xB4,0xA5,0xA5,0x97,0x87,0x87,0x88,0x86,0x96, //20480xA4,0xC3,0xA5,0xA5,0xA5,0xA6,0x97,0x87,0x87,0x78,0x87,0x86, //20490xA5,0xC3,0xA5,0xB5,0xA6,0xA6,0x87,0x88,0x78,0x78,0x87,0x87, //2050 };///月份数据表code uchar day_code1[9]={0x0,0x1f,0x3b,0x5a,0x78,0x97,0xb5,0xd4,0xf3};code uint day_code2[3]={0x111,0x130,0x14e};code uchar jieqi_name[][3]={"hi","xh","dh","lc","ys","jz","cf","qm","gy","lx","xm","mz","xz","xs","ds","lq","cs ","bl","qf","hl","sj","ld","xx","dx","dz",};code uchar gjieri_name[][2]={"hi","yd","fn","ld","qn","et","jj","js","gq",};code uchar njieri_name[][2]={"hi","cj","yx","dw","qx","zq","cy","lb",};/*函数功能:输入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数据*/data uchar year_moon,month_moon,day_moon,week;uchar qi=0,gri=0,nri=0;void jieqi (uchar *nyr){uint temp,yy,dd,mm,addr,y;uchar mo,ndd;yy=nyr[0]*100+nyr[1];mm=nyr[2];dd=nyr[3];y = yy-1901;mo=month_moon/16*10+month_moon%16;ndd=day_moon/16*10+day_moon%16;addr=y*12+mm-1;if(dd<15){temp=15-dd;if((jieqi_code[addr]>>4)==temp) qi=mm*2-1;else qi=0;}if(dd==15) qi=0;if(dd>15){temp=dd-15;if((jieqi_code[addr]&0x0f)==temp) qi=mm*2;else qi=0;}shijian[3]=qi;////////////////////////////////////////////////////////////////////////////////// LCD_write_char(10,1,' ');LCD_write_char(11,1,jieqi_name[qi][0]);LCD_write_char(12,1,jieqi_name[qi][1]);LCD_write_char(13,1,' ');if(mm==1&&dd==1) gri=1;if(mm==3&&dd==8) gri=2;if(mm==5&&dd==1) gri=3;if(mm==5&&dd==4) gri=4;if(mm==6&&dd==1) gri=5;if(mm==8&&dd==1) gri=6;if(mm==9&&dd==10) gri=7;if(mm==10&&dd==1) gri=8;if(mo==1&&ndd==1) nri=1;if(mo==1&&ndd==15) nri=2;if(mo==5&&ndd==5) nri=3;if(mo==7&&ndd==7) nri=4;if(mo==8&&ndd==15) nri=5;if(mo==9&&ndd==9) nri=6;if(mo==12&&ndd==8) nri=7;/*********************************************************/shijian[4]=gri;shijian[5]=nri;/**********************************************************/if(nri!=0){LCD_write_char(14,1,njieri_name[nri][0]);LCD_write_char(15,1,njieri_name[nri][1]);}else{LCD_write_char(14,1,gjieri_name[gri][0]);LCD_write_char(15,1,gjieri_name[gri][1]);}}bit c_moon;/*子函数,用于读取数据表中农历月的大月或小月,如果该月为大返回1,为小返回0*/ bit get_moon_day(uchar month_p,uint table_addr){uchar temp;switch (month_p){case 1:{temp=year_code[table_addr]&0x08;if (temp==0)return(0);else return(1);}case 2:{temp=year_code[table_addr]&0x04;if (temp==0)return(0);else return(1);}case 3:{temp=year_code[table_addr]&0x02;if (temp==0)return(0);else return(1);}case 4:{temp=year_code[table_addr]&0x01;if (temp==0)return(0);else return(1);}case 5:{temp=year_code[table_addr+1]&0x80;if (temp==0) return(0);else return(1);}case 6:{temp=year_code[table_addr+1]&0x40;if (temp==0)return(0);else return(1);}case 7:{temp=year_code[table_addr+1]&0x20;if (temp==0)return(0);else return(1);}case 8:{temp=year_code[table_addr+1]&0x10;if (temp==0)return(0);else return(1);}case 9:{temp=year_code[table_addr+1]&0x08;if (temp==0)return(0);else return(1);}case 10:{temp=year_code[table_addr+1]&0x04;if (temp==0)return(0);else return(1);}case 11:{temp=year_code[table_addr+1]&0x02;if (temp==0)return(0);else return(1);}case 12:{temp=year_code[table_addr+1]&0x01;if (temp==0)return(0);else return(1);}case 13:{temp=year_code[table_addr+2]&0x80;if (temp==0)return(0);else return(1);}}}/*函数功能:输入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数据*/void Conversion(bit c,uchar year,uchar month,uchar day){ //c=0 为21世纪,c=1 为19世纪输入输出数据均为BCD数据uchar temp1,temp2,temp3,month_p;uint temp4,table_addr;bit flag2,flag_y;temp1=year/16; //BCD->hex 先把数据转换为十六进制temp2=year%16;year=temp1*10+temp2;temp1=month/16;temp2=month%16;month=temp1*10+temp2;temp1=day/16;temp2=day%16;day=temp1*10+temp2;//定位数据表地址if(c==0){table_addr=(year+0x64-1)*0x3;}else{table_addr=(year-1)*0x3;}//定位数据表地址完成//取当年春节所在的公历月份temp1=year_code[table_addr+2]&0x60;temp1=_cror_(temp1,5);//取当年春节所在的公历月份完成//取当年春节所在的公历日temp2=year_code[table_addr+2]&0x1f;//取当年春节所在的公历日完成// 计算当年春年离当年元旦的天数,春节只会在公历1月或2月if(temp1==0x1){temp3=temp2-1;}else{temp3=temp2+0x1f-1;}// 计算当年春年离当年元旦的天数完成//计算公历日离当年元旦的天数,为了减少运算,用了两个表//day_code1[9],day_code2[3]//如果公历月在九月或前,天数会少于0xff,用表day_code1[9],//在九月后,天数大于0xff,用表day_code2[3]//如输入公历日为8月10日,则公历日离元旦天数为day_code1[8-1]+10-1//如输入公历日为11月10日,则公历日离元旦天数为day_code2[11-10]+10-1if (month<10){temp4=day_code1[month-1]+day-1;}else{temp4=day_code2[month-10]+day-1;}if ((month>0x2)&&(year%0x4==0)){ //如果公历月大于2月并且该年的2月为闰月,天数加1temp4+=1;}//计算公历日离当年元旦的天数完成//判断公历日在春节前还是春节后if (temp4>=temp3){ //公历日在春节后或就是春节当日使用下面代码进行运算temp4-=temp3;month=0x1;month_p=0x1; //month_p为月份指向,公历日在春节前或就是春节当日month_p指向首月flag2=get_moon_day(month_p,table_addr);//检查该农历月为大小还是小月,大月返回1,小月返回0flag_y=0;if(flag2==0)temp1=0x1d; //小月29天else temp1=0x1e; //大小30天temp2=year_code[table_addr]&0xf0;temp2=_cror_(temp2,4); //从数据表中取该年的闰月月份,如为0则该年无闰月while(temp4>=temp1){temp4-=temp1;month_p+=1;if(month==temp2){flag_y=~flag_y;if(flag_y==0)month+=1;}else month+=1;flag2=get_moon_day(month_p,table_addr);if(flag2==0)temp1=0x1d;else temp1=0x1e;}day=temp4+1;}else{ //公历日在春节前使用下面代码进行运算temp3-=temp4;if (year==0x0){year=0x63;c=1;}else year-=1;table_addr-=0x3;month=0xc;temp2=year_code[table_addr]&0xf0;temp2=_cror_(temp2,4);if (temp2==0)month_p=0xc;elsemonth_p=0xd; ///*month_p为月份指向,如果当年有闰月,一年有十三个月,月指向13,无闰月指向12*/ flag_y=0;flag2=get_moon_day(month_p,table_addr);if(flag2==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;flag2=get_moon_day(month_p,table_addr);if(flag2==0)temp1=0x1d;else temp1=0x1e;}day=temp1-temp3+1;}c_moon=c; //HEX->BCD ,运算结束后,把数据转换为BCD数据temp1=year/10;temp1=_crol_(temp1,4);temp2=year%10;year_moon=temp1|temp2;temp1=month/10;temp1=_crol_(temp1,4);temp2=month%10;month_moon=temp1|temp2;temp1=day/10;temp1=_crol_(temp1,4);temp2=day%10;day_moon=temp1|temp2;}/*函数功能:输入BCD阳历数据,输出BCD星期数据(只允许1901-2099年)调用函数示例:Conver_week(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世纪调用函数后,原有数据不变,读week得出阴历BCD数据*/code uchar table_week[12]={0,3,3,6,1,4,6,2,5,0,3,5}; //月修正数据表/*算法:日期+年份+所过闰年数+月较正数之和除7 的余数就是星期但如果是在闰年又不到3 月份上述之和要减一天再除7星期数为0*/void Conver_week(bit c,uchar year,uchar month,uchar day){//c=0 为21世纪,c=1 为19世纪输入输出数据均为BCD数据uchar temp1,temp2;temp1=year/16; //BCD->hex 先把数据转换为十六进制temp2=year%16;year=temp1*10+temp2;temp1=month/16;temp2=month%16;month=temp1*10+temp2;temp1=day/16;temp2=day%16;day=temp1*10+temp2;if (c==0){year+=0x64;} //如果为21世纪,年份数加100temp1=year/0x4; //所过闰年数只算1900年之后的temp2=year+temp1;temp2=temp2%0x7; //为节省资源,先进行一次取余,避免数大于0xff,避免使用整型数据temp2=temp2+day+table_week[month-1];if (year%0x4==0&&month<3)temp2-=1;week=temp2%0x7;}//testuchar c_sun,year_sun,month_sun,day_sun;/***********************************************农历转换函数************************************************/unsigned char set_1[4];bit flag_1=0,flag_2=0;void nongli(uchar *nyr){uchar i=0;code uchar table_week[][4]={"Sun","Mon","Tue","Wed","Thu","Fri","Sat"};year_sun=nyr[1]/10*16+nyr[1]%10;month_sun=nyr[2]/10*16+nyr[2]%10;day_sun=nyr[3]/10*16+nyr[3]%10;//LCD_clear();if(nyr[0]==20){LCD_write_char(0,1,'2');LCD_write_char(1,1,'0');Conversion(0,year_sun,month_sun,day_sun);Conver_week(0,year_sun,month_sun,day_sun);}else if(nyr[0]==19){LCD_write_char(0,1,'1');LCD_write_char(1,1,'9');Conversion(1,year_sun,month_sun,day_sun);Conver_week(1,year_sun,month_sun,day_sun);}else{LCD_write_str(0,1,"Error Input!");sound_3();delay1(200);delay1(200);delay1(200);delay1(200);delay1(200);delay1(200);flag_1=1;return;}LCD_write_char(2,1,year_moon/16+0x30);LCD_write_char(3,1,year_moon%16+0x30);LCD_write_char(4,1,'-');LCD_write_char(5,1,month_moon/16+0x30);LCD_write_char(6,1,month_moon%16+0x30);LCD_write_char(7,1,'-');LCD_write_char(8,1,day_moon/16+0x30);LCD_write_char(9,1,day_moon%16+0x30);LCD_write_str(10,1," ");LCD_write_str(12,0,table_week[week%16]);}/*************************************************接受要转换成农历个阳历的年月日函数**************************************************/void receive(){unsigned char i;LCD_clear();//清屏key_value=16;ds1302_read_time();for(i=0;i<4;i++)set_1[i]=time_buf1[i];set_1[0]=20;LCD_write_char(0,0,set_1[0]/10+0x30);LCD_write_char(1,0,set_1[0]%10+0x30);LCD_write_char(2,0,set_1[1]/10+0x30);LCD_write_char(3,0,set_1[1]%10+0x30);LCD_write_char(4,0,'-');LCD_write_char(5,0,set_1[2]/10+0x30);LCD_write_char(6,0,set_1[2]%10+0x30);LCD_write_char(7,0,'-');LCD_write_char(8,0,set_1[3]/10+0x30);LCD_write_char(9,0,set_1[3]%10+0x30);nongli(set_1);i=0;LCD_write_com(0x0f);//打开光标LCD_write_com(0x80+i);//写入初始地址while(1){key();if((key_value>=0)&&(key_value<=9)){while(1){keyscan();if(!keydown){delay1(10);keyscan();if(!keydown){LCD_write_Data(key_value+0x30);LCD_write_com(0x80+i);//校正写数据时数据指针的加一if(i==0){set_1[0]=key_value*10+set_1[0]%10;key_value=16;break;}if(i==1){set_1[0]=key_value+set_1[0]/10*10;key_value=16;break;}if(i==2)//年份{set_1[1]=key_value*10+set_1[1]%10;key_value=16;break;}if(i==3){set_1[1]=key_value+set_1[1]/10*10;key_value=16;break;}if(i==4)//'-'符号不变{LCD_write_Data('-');LCD_write_com(0x80+i);//校正写数据时数据指针的加一key_value=16;break;}if(i==5)//月份{set_1[2]=key_value*10+set_1[2]%10;key_value=16;break;}if(i==6){set_1[2]=key_value+set_1[2]/10*10;key_value=16;break;}if(i==7)//'-'符号不变{LCD_write_Data('-');LCD_write_com(0x80+i);//校正写数据时数据指针的加一key_value=16;break;}if(i==8)//年份{set_1[3]=key_value*10+set_1[3]%10;key_value=16;break;}if(i==9){set_1[3]=key_value+set_1[3]/10*10;key_value=16;break;}}}}}if(key_value==12){while(1){keyscan();if(!keydown){delay1(10);keyscan();if(!keydown){flag_2=1;key_value=16;break;}}}break;}if(key_value==13){while(1){keyscan();if(!keydown){delay1(10);keyscan();if(!keydown){if((i>0)&&(i<=9))i--;LCD_write_com(0x80+i);key_value=16;break;}}}}if(key_value==14){while(1){keyscan();if(!keydown){delay1(10);keyscan();if(!keydown){if(i<9)i=i+1;LCD_write_com(0x80+i);key_value=16;break;}}}。

相关文档
最新文档