单片机万年历阴阳历c语言,单片机阴历阳历c算法万年历.pdf

单片机阴历阳历c算法万年历

当前位置: 首页 > 嵌入式系统 > 51 单片机万年历优化算法源程序

51 单片机万年历优化算法源程序

字体大小 : 小 中 大 作者: 来源: 日期: 2007-06-06 点击: 1046

一、 阳历算法

具体算法见函数 void get_solar_day_date(void) ,这样阳历日历的星期排法就确定了。

表 1:

变量定义:

Public:

Unsigned int temp_total_day;

Unsigned char gc_solar_calendar_year;

Unsigned char gc_solar_calendar_month;

Unsigned char gc_solar_calendar_date;

Unsigned char gc_lunar_calendar_year;

Unsigned char gc_lunar_calendar_month;

Unsigned char gc_lunar_calendar_date;

Unsigned char start_day_of_week ;

说明:函数 get_solar_day_date(void) 的输入变量: gc_solar_calendar_year 和 gc_solar_calendar_month

输出变量: start_day_of_week 和 temp_total_day

Void get_solar_day_date(void)

{

unsigned char temp01;

/*calculate what day is the day of the current month and year. Mon~Sun?*/

/* 条件初始化二次,减少运算数据量 . temp_total_day 是 int 型变量 */

start_day_of_week = 2; temp_total_day = 0;calculate_temp = 1;

if(gc_solar_calendar_year > 99)

{start_day_of_week = 6;calculate_temp = 100;}

for(temp01 = calculate_temp; temp01

{ if(temp01%4 == 0){start_day_of_week +=2;temp_total_day += 366; }

else {start_day_of_week +=1;temp_total_day += 365;}}

for(temp01 = 1;temp01

{ switch(temp01)

{case 1,3,5,7,8,10,12: start_day_of_week +=3;temp_total_day +=31;break;

case 2: if(((gc_solar_calendar_year%4) == 0)&&(gc_solar_calendar_year != 200))

{start_day_of_week +=1; temp_total_day +=29;}

else {start_day_of_week +=0;temp_total_day +=28;} break;

case 4,6,9,11: start_day_of_week +=2; temp_total_day +=30; break;}}

start_day_of_week %=7;

/*-end of calculate what day is the day(Mon~Sun?) and total day --*/

}

二、 阴历算法

200 年需要 200 × 2 = 400 个字节,构成阴历压缩数据表 lunar_calendar_month_table[] 如下

const char lunar_calendar_month_table[]={ // 从阴历年 190

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值