万年历单片机课程设计,单片机万年历设计报告
想用单片机设计一个万年历,如何实现阳历到农历的转换?最好是给出思路...
<% ' 用途: ' 当前日期计算该日期的农历天干地支及当年属相 ' ##-------------------------------------------## Dim objChinaDay Dim sDay, sWeekDay, sChinaDay, sChinaYear,sChinaAni Set objChinaDay = New ChinaDay Call objChinaDay.Action("",sDay,sWeekDay,sChinaYear,sChinaDay,sChinaAni) Response.Write sDay&" " '当前日期 Response.Write sWeekDay&" " '星期 Response.Write sChinaYear&" " '农历年份 Response.Write sChinaDay&" " '农历日期 Response.Write sChinaAni&" " '生肖' Copyright: 本代码非原创,原作者未知。 '********************************************************************************* Class ChinaDay Dim arrWeekName(7), MonthAdd(11), NongliData(99) Dim arrTianGan(9), arrDiZhi(11), arrShuXiang(11), arrDayName(30), arrMonName(12) Dim curTime, curYear, curMonth, curDay, curWeekday Dim i, m, n, k, isEnd, bit, TheDate '初始化数据 Sub Class_Initialize() '------------------------------------------------------------------------- '定义显示字串 '星期名 arrWeekName(0) = "*" arrWeekName(1) = "星期日" arrWeekName(2) = "星期一" arrWeekName(3) = "星期二" arrWeekName(4) = "星期三" arrWeekName(5) = "星期四" arrWeekName(6) = "星期五" arrWeekName(7) = "星期六" '天干名称 arrTianGan(0) = "甲" arrTianGan(1) = "乙" arrTianGan(2) = "丙" arrTianGan(3) = "丁" arrTianGan(4) = "戊" arrTianGan(5) = "己" arrTianGan(6) = "庚" arrTianGan(7) = "辛" arrTianGan(8) = "壬" arrTianGan(9) = "癸" '地支名称 arrDiZhi(0) = "子" arrDiZhi(1) = "丑" arrDiZhi(2) = "寅" arrDiZhi(3) = "卯" arrDiZhi(4) = "辰" arrDiZhi(5) = "巳" arrDiZhi(6) = "午" arrDiZhi(7) = "未" arrDiZhi(8) = "申" arrDiZhi(9) = "酉" arrDiZhi(10) = "戌" arrDiZhi(11) = "亥" '属相名称 arrShuXiang(0) = "鼠" arrShuXiang(1) = "牛" arrShuXiang(2) = "虎" arrShuXiang(3) = "兔" arrShuXiang(4) = "龙" arrShuXiang(5) = "蛇" arrShuXiang(6) = "马" arrShuXiang(7) = "羊" arrShuXiang(8) = "猴" arrShuXiang(9) = "鸡" arrShuXiang(10) = "狗" arrShuXiang(11) = "猪" '农历日期名 arrDayName(0) = "*" arrDayName(1) = "初一" arrDayName(2) = "初二" arrDayName(3) = "初三" arrDayName(4) = "初四" arrDayName(5) = "初五" arrDayName(6) = "初六" arrDayName(7) = "初七" arrDayName(8) = "初八" arrDayName(9) = "初九" arrDayName(10) = "初十" arrDayName(11) = "十一" arrDayName(12) = "十二" arrDayName(13) = "十三" arrDayName(14) = "十四" arrDayName(15) = "十五" arrDayName(16) = "十六" arrDayName(17) = "十七" arrDayName(18) = "十八" arrDayName(19) = "十九" arrDayName(20) = "二十" arrDayName(21) = "廿一" arrDayName(22) = "廿二" arrDayName(23) = "廿三" arrDayName(24) = "廿四" arrDayName(25) = "廿五" arrDayName(26) = "廿六" arrDayName(27) = "廿七" arrDayName(28) = "廿八" arrDayName(29) = "廿九" arrDayName(30) = "卅十" '农历月份名 arrMonName(0) = "*" arrMonName(1) = "正" arrMonName(2) = "二" arrMonName(3) = "三" arrMonName(4) = "四" arrMonName(5) = "五" arrMonName(6) = "六" arrMonName(7) = "七" arrMonName(8) = "八" arrMonName(9) = "九" arrMonName(10) = "十" arrMonName(11) = "冬" arrMonName(12) = "腊" '------------------------------------------------------------------------- '公差数据定义 '公历每月前面的天数 MonthAdd(0) = 0 MonthAdd(1) = 31 MonthAdd(2) = 59 MonthAdd(3) = 90 MonthAdd(4) = 120 MonthAdd(5) = 151 MonthAdd(6) = 181 MonthAdd(7) = 212 MonthAdd(8) = 243 MonthAdd(9) = 273 MonthAdd(10) = 304 MonthAdd(11) = 334 '农历数据 NongliData(0) = 2635 NongliData(1) = 333387 NongliData(2) = 1701 NongliData(3) = 1748 NongliData(4) = 267701 NongliData(5) = 694 NongliData(6) = 2391 NongliData(7) = 133423 NongliData(8) = 1175 NongliData(9) = 396438 NongliData(10) = 3402 NongliData(11) = 3749 NongliData(12) = 331177 NongliData(13) = 1453 NongliData(14) = 694 NongliData(15) = 201326 NongliData(16) = 2350 NongliData(17) = 465197 NongliData(18) = 3221 NongliData(19) = 3402 NongliData(20) = 400202 NongliData(21) = 2901 NongliData(22) = 1386 NongliData(23) = 267611 NongliData(24) = 605 NongliData(25) = 2349 NongliData(26) = 137515 NongliData(27) = 2709 NongliData(28) = 464533 NongliData(29) = 1738 NongliData(30) = 2901 NongliData(31) = 330421 NongliData(32) = 1242 NongliData(33) = 2651 NongliData(34) = 199255 NongliData(35) = 1323 NongliData(36) = 529706 NongliData(37) = 3733 NongliData(38) = 1706 NongliData(39) = 398762 NongliData(40) = 2741 NongliData(41) = 1206 NongliData(42) = 267438 NongliData(43) = 2647 NongliData(44) = 1318 NongliData(45) = 204070 NongliData(46) = 3477 NongliData(47) = 461653 NongliData(48) = 1386 NongliData(49) = 2413 NongliData(50) = 330077 NongliData(51) = 1197 NongliData(52) = 2637 NongliData(53) = 268877 NongliData(54) = 3365 NongliData(55) = 531109 NongliData(56) = 2900 NongliData(57) = 2922 NongliData(58) = 398042 NongliData(59) = 2395 NongliData(60) = 1179 NongliData(61) = 267415 NongliData(62) = 2635 NongliData(63) = 661067 NongliData(64) = 1701 NongliData(65) = 1748 NongliData(66) = 398772 NongliData(67) = 2742 NongliData(68) = 2391 NongliData(69) = 330031 NongliData(70) = 1175 NongliData(71) = 1611 NongliData(72) = 200010 NongliData(73) = 3749 NongliData(74) = 527717 NongliData(75) = 1452 NongliData(76) = 2742 NongliData(77) = 332397 NongliData(78) = 2350 NongliData(79) = 3222 NongliData(80) = 268949 NongliData(81) = 3402 NongliData(82) = 3493 NongliData(83) = 133973 NongliData(84) = 1386 NongliData(85) = 464219 NongliData(86) = 605 NongliData(87) = 2349 NongliData(88) = 334123 NongliData(89) = 2709 NongliData(90) = 2890 NongliData(91) = 267946 NongliData(92) = 2773 NongliData(93) = 592565 NongliData(94) = 1210 NongliData(95) = 2651 NongliData(96) = 395863 NongliData(97) = 1323 NongliData(98) = 2707 NongliData(99) = 265877 End Sub '################################################################# '主要方法 Action ' inDay 输入日期,如果不输入则默认为当前日期 ' sDay 中文格式日期 ' sWeekDay 周几 ' sChinaYear 农历年 ' sChinaDay 农历日 ' sChinaAni 属相 '################################################################# Public Function Action(inDay,sDay,sWeekDay,sChinaYear,sChinaDay,sChinaAni) '转换要转换的日期 If inDay="" Or Not IsDate(inDay) Then '获取当前系统时间 curTime = Now() Else curTime = CDate(inDay) End If If Datediff("d",curTime,Cdate("1921-2-8"))>0 Then Exit Function End If '生成当前公历年、月、日 ==> sDay curYear = Year(curTime) curMonth = Month(curTime) curDay = Day(curTime) sDay = curYear&"年" If (curMonth < 10) Then sDay = sDay&"0"&curMonth&"月" Else sDay = sDay&curMonth&"月" End If If (curDay < 10) Then sDay = sDay&"0"&curDay&"日" Else sDay = sDay&curDay&"日" End If '生成当前公历星期 ==> sWeekDay curWeekday = Weekday(curTime) sWeekDay = arrWeekName(curWeekday) '计算到初始时间1921年2月8日的天数:1921-2-8(正月初一) TheDate = (curYear - 1921) * 365 + Int((curYear - 1921) / 4) + curDay + MonthAdd(curMonth - 1) - 38 If ((curYear Mod 4) = 0 AND curMonth > 2) Then TheDate = TheDate + 1 End If '计算农历天干、地支、月、日 isEnd = 0 m = 0 '------------------------------------ Do If (NongliData(m) < 4095) Then k = 11 Else k = 12 End if n = k '------------------------------------ Do If (n < 0) Then Exit Do End If '获取NongliData(m)的第n个二进制位的值 bit = NongliData(m) For i = 1 To n Step 1 bit = Int(bit / 2) Next bit = bit Mod 2 If (TheDate <= 29 + bit) Then isEnd = 1 Exit Do End If TheDate = TheDate - 29 - bit n = n - 1 Loop '------------------------------------ If (isEnd = 1) Then Exit Do End If m = m + 1 Loop '------------------------------------ curYear = 1921 + m curMonth = k - n + 1 curDay = TheDate If (k = 12) Then If (curMonth = (Int(NongliData(m) / 65536) + 1)) Then curMonth = 1 - curMonth ElseIf (curMonth > (Int(NongliData(m) / 65536) + 1)) Then curMonth = curMonth - 1 End if End If '生成农历天干、地支==> sChinaYear sChinaYear = "农历"&arrTianGan(((curYear - 4) Mod 60) Mod 10)&arrDiZhi(((curYear - 4) Mod 60) Mod 12)&"年" '生成属相 == > sChinaAni sChinaAni = arrShuXiang(((curYear - 4) Mod 60) Mod 12) '生成农历月、日 ==> NongliDayStr If (curMonth < 1) Then sChinaDay = "闰"&arrMonName(-1 * curMonth) Else sChinaDay = arrMonName(curMonth) End If sChinaDay = sChinaDay&"月" sChinaDay = sChinaDay & arrDayName(curDay) End Function End Class %>
虹泰牌万年历的电源电路图
万年历的电源电路一般就是用变压器将电压变成12v然后经过整流滤波后经过7805稳压得到5v的电压给控制和存储芯片供电的,电路很简单的,整流电路可以用4只1N4007,滤波电路一般是2200uf的滤波电容耐压只要高压12v就行了,7805是稳压块,型号一般是lm7805。别的不会有什么不同了,一般被雷击过的电器不太好修,大多数故障都是出在电源,还有的故障会出在电源之后的电路,需要仔细的检查才能彻底排除故障。
谁能跟我说说单片机万年历的设计思路呗
仔细研究野火的STM32F103开发板的实时时钟例程,就会学到很多东西这个单片机的实时时钟只是一个简单的32位计数器,计的是秒,要换算成年月日时分秒,完全是要根据阳历的闰年规律计算的,先找一个基准日期,称为时间戳然后根据现今时间与时间戳的差值(以S为单位)计算当前的年月日时分秒钟星期几,然后根据表格查每年的农历有几个月,几个大小月,闰月是个月,春节在哪一天,当前日期是在春节前还是春节后,就能计算出农历日期,然后计算24节气,由于24节是按阳历年划分的,而阳历的一年只有365天和366天两种,因此24节的阳历日期基本固定,找一个标准,然后记下各个节气和标准日期的正负误差就可以确定当前节气的阳历日期了,还有天干地支,只要有一个基准,求12和10的余数,推算很容易的基于单片机的万年历怎么做啊只要求显示日期和时间?电路图、程序有谁...
#include <reg52.h>#include<stddef.h>#define uchar unsigned char#define uint unsigned int#define LCD1602_FLAG#define LCD1602_PORT P0sbit lcd1602_rs=P2^0;sbit lcd1602_e=P2^2;sbit lcd1602_rw=P2^1;sbit lcd1602_busy=P0^7;sbit key_ch=P3^5;sbit key_add=P3^6;sbit key_minus=P3^7;uchar i,sec,min,h,date,month,flag;uint year;uchar *chgstr[7]={" ","sec","min","hour","date","min","year"};uchar j,k,m,n,o,p;uchar code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};uchar timestr[10],datestr[10];void init();void delay(uint);void time_display();void date_display();void control();void time();/************************************** 函数名称:lcd1602_CheckBusy()* 函数功能:状态查询*************************************/void lcd1602_CheckBusy(){do{lcd1602_busy=1;lcd1602_rs=0;lcd1602_rw=1;lcd1602_e=0;lcd1602_e=1;}while(lcd1602_busy);}/***************************************** 函数名称: lcd1602_WriteCmd()* 函数功能:写命令* 入口参数:命令字* 出口参数:无****************************************/void lcd1602_WriteCmd(const uchar cmd){lcd1602_CheckBusy();lcd1602_rs=0;lcd1602_rw=0;lcd1602_e=1;LCD1602_PORT=cmd;lcd1602_e=0;}/********************************************* 函数名称:lcd1602_WriteData()* 函数功能:写数据* 入口参数:c--待写数据* 出口参数:无**********************************************/void lcd1602_WriteData(const uchar c){lcd1602_CheckBusy();lcd1602_rs=1;lcd1602_rw=0;lcd1602_e=1;LCD1602_PORT=c;lcd1602_e=0;}/************************************************* 函数名称:lcd1602_Init()* 函数功能:初始化LCD* 入口参数:无* 出口参数:无************************************************/void lcd1602_Init(){lcd1602_WriteCmd(0x38);//显示模式为8位2行5*7点阵lcd1602_WriteCmd(0x0c); //display enable,flag enable,flash enable,lcd1602_WriteCmd(0x06); //flag move to right,screen don't movelcd1602_WriteCmd(0x01); //clear screen}/************************************************** 函数名称:lcd1602_Display()* 函数功能: 字符显示* 入口参数:ptr--字符或字符串指针* 出口参数:无* 说 明:用户可通过以下方式来调用:* 1)lcd1602_Display("Hello,world!");* 2) INT8U 存储类型 txt[]="要显示的字符串";* 或者 INT8U 存储类型 txt[]={'t','x','t',..,'\0'};* INT8U *ptr;* ptr=&txt;* lcd1602_Display(ptr);* 或 lcd1602_Display(txt);* 或 lcd1602_Display(&txt);*************************************************/void lcd1602_Display(const uchar *ptr,uchar line,uchar xaddr){uchar data i=0;uchar *data q;q=ptr;switch(line){case 0:lcd1602_WriteCmd(0x80+xaddr);while(q!=NULL && (*q!='\0') && i<16){lcd1602_WriteData(*q);q++;i++;}break;case 1:lcd1602_WriteCmd(0xc0+xaddr);while(q!=NULL && (*q!='\0') && i<16){lcd1602_WriteData(*q);q++;i++;}break;}}void main(){lcd1602_Init();init();while(1){time_display();date_display();control();}}void init(){i=0;sec=0;min=30;h=7;date=17;month=10;year=2023;flag=0;EA=1;ET0=1;TMOD=0x01;TH0=(65536-50000)/256;TL0=(65536-50000)%256;TR0=1;}void delay(uint z){uint x,y;for(x=z;x>0;x--)for(y=110;y>0;y--);}void time_display(){timestr[7]=0x30+sec%10;timestr[6]=0x30+sec/10;timestr[5]=':';timestr[4]=0x30+min%10;timestr[3]=0x30+min/10;timestr[2]=':';timestr[1]=0x30+h%10;timestr[0]=0x30+h/10;timestr[8]=0;lcd1602_Display(timestr,1,3);}void date_display(){datestr[9]=0x30+date%10;datestr[8]=0x30+date/10;datestr[7]=':';datestr[6]=0x30+month%10;datestr[5]=0x30+month/10;datestr[4]=':';datestr[3]=0x30+year%10;datestr[2]=0x30+year/10%10;datestr[1]=0x30+year/100%10;datestr[0]=0x30+year/1000;lcd1602_Display(datestr,0,2);}void control(){if(!key_ch){delay(5);if(!key_ch){flag++;TR0=0;if(flag==7){flag=0;TR0=1;lcd1602_Init();}lcd1602_Display(chgstr[flag],1,12);}}while(!key_ch);if(flag==1&&key_add==0){while(!key_add);sec++;if(sec==60)sec=0;}if(flag==1&&key_minus==0){while(!key_minus);sec--;if(sec==-1)sec=59;}if(flag==2&&key_add==0){while(!key_add);min++;if(min==60)min=0;}if(flag==2&&key_minus==0){while(!key_minus);min--;if(min==-1)min=59;}if(flag==3&&key_add==0){while(!key_add);h++;if(h==24)h=0;}if(flag==3&&key_minus==0){while(!key_minus);h--;if(h==-1)h=23;}if(flag==4&&key_add==0){while(!key_add);date++;if(date==29)if((year%4!=0)&&(month==2))date=1;if(date==30)if((year%4==0)&&(month==2))date=1;if(date==31)if((month==4)||(month==6)||(month==9)||(month==11))date=1;if(date==32)if((month==1)||(month==3)||(month==5)||(month==7)||(month==8)||(month==10)||(month==12))date=1;}if(flag==4&&key_minus==0){while(!key_minus);if(date>1)date--;}if(flag==5&&key_add==0){while(!key_add);month++;if(month==13)month=1;}if(flag==5&&key_minus==0){while(!key_minus);month--;if(month==0)month=12;}if(flag==6&&key_add==0){while(!key_add);year++;if(year==99)year=1;}if(flag==6&&key_minus==0){while(!key_minus);year--;if(year==0)year=99;}}void T0_rpt() interrupt 1{TH0=(65536-50000)/256;TL0=(65536-50000)%256;i++;time();}void time(){if(i==20){i=0;sec++;if(sec==60){sec=0;min++;if(min==60){min=0;h++;if(h==24){h=0;min=0;sec=0;date++;if(date==29)if((year%4!=0)&&(month==2)){date=1;month++;if(month==13){month=1;year++;}}if(date==30)if((year%4==0)&&(month==2)){date=1;month++;if(month==13){month=1;year++;}}if(date==31)if((month==4)||(month==6)||(month==9)||(month==11)){date=1;month++;if(month==13){month=1;year++;}}if(date==32)if((month==1)||(month==3)||(month==5)||(month==7)||(month==8)||(month==10)||(month==12)){date=1;month++;if(month==13){month=1;year++;}}}}}}}基于单片机的数字万年历设计毕业论文
佛教讲的修来生,今生辛苦为的是来生幸福,幸福的概念不是不用修行,而是加倍努力的修行。每个人生下来都是婴儿,但不是每个婴儿都是幸福的,因为他的前生可能作了恶或者别的。而幸福的人佛祖会辟佑你和你的家人。修行不是以时间长短来分高低的,所以即便你不记得以前的修行也没有关系,靠的是悟性,对生活,人生的感应。认真修行的人的心是善良的,会比较靠近佛所以能更加容易的领悟佛法。希望你能明白,这两者并不矛盾!
C51单片机的万年历程序设计
//C51写的公历转农历和星期#define uchar unsigned char#define uint unsigned int#include <intrins.h>/*公历年对应的农历数据,每年三字节,格式第一字节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, //1901 0 0x0A,0x57,0x48, //1902 3 0x55,0x26,0xBd, //1903 6 0x0d,0x26,0x50, //1904 9 0x0d,0x95,0x44, //1905 12 0x46,0xAA,0xB9, //1906 15 0x05,0x6A,0x4d, //1907 18 0x09,0xAd,0x42, //1908 21 0x24,0xAe,0xB6, //1909 0x04,0xAe,0x4A, //1910 0x6A,0x4d,0xBe, //1911 0x0A,0x4d,0x52, //1912 0x0d,0x25,0x46, //1913 0x5d,0x52,0xBA, //1914 0x0B,0x54,0x4e, //1915 0x0d,0x6A,0x43, //1916 0x29,0x6d,0x37, //1917 0x09,0x5B,0x4B, //1918 0x74,0x9B,0xC1, //1919 0x04,0x97,0x54, //1920 0x0A,0x4B,0x48, //1921 0x5B,0x25,0xBC, //1922 0x06,0xA5,0x50, //1923 0x06,0xd4,0x45, //1924 0x4A,0xdA,0xB8, //1925 0x02,0xB6,0x4d, //1926 0x09,0x57,0x42, //1927 0x24,0x97,0xB7, //1928 0x04,0x97,0x4A, //1929 0x66,0x4B,0x3e, //1930 0x0d,0x4A,0x51, //1931 0x0e,0xA5,0x46, //1932 0x56,0xd4,0xBA, //1933 0x05,0xAd,0x4e, //1934 0x02,0xB6,0x44, //1935 0x39,0x37,0x38, //1936 0x09,0x2e,0x4B, //1937 0x7C,0x96,0xBf, //1938 0x0C,0x95,0x53, //1939 0x0d,0x4A,0x48, //1940 0x6d,0xA5,0x3B, //1941 0x0B,0x55,0x4f, //1942 0x05,0x6A,0x45, //1943 0x4A,0xAd,0xB9, //1944 0x02,0x5d,0x4d, //1945 0x09,0x2d,0x42, //1946 0x2C,0x95,0xB6, //1947 0x0A,0x95,0x4A, //1948 0x7B,0x4A,0xBd, //1949 0x06,0xCA,0x51, //1950 0x0B,0x55,0x46, //1951 0x55,0x5A,0xBB, //1952 0x04,0xdA,0x4e, //1953 0x0A,0x5B,0x43, //1954 0x35,0x2B,0xB8, //1955 0x05,0x2B,0x4C, //1956 0x8A,0x95,0x3f, //1957 0x0e,0x95,0x52, //1958 0x06,0xAA,0x48, //1959 0x7A,0xd5,0x3C, //1960 0x0A,0xB5,0x4f, //1961 0x04,0xB6,0x45, //1962 0x4A,0x57,0x39, //1963 0x0A,0x57,0x4d, //1964 0x05,0x26,0x42, //1965 0x3e,0x93,0x35, //1966 0x0d,0x95,0x49, //1967 0x75,0xAA,0xBe, //1968 0x05,0x6A,0x51, //1969 0x09,0x6d,0x46, //1970 0x54,0xAe,0xBB, //1971 0x04,0xAd,0x4f, //1972 0x0A,0x4d,0x43, //1973 0x4d,0x26,0xB7, //1974 0x0d,0x25,0x4B, //1975 0x8d,0x52,0xBf, //1976 0x0B,0x54,0x52, //1977 0x0B,0x6A,0x47, //1978 0x69,0x6d,0x3C, //1979 0x09,0x5B,0x50, //1980 0x04,0x9B,0x45, //1981 0x4A,0x4B,0xB9, //1982 0x0A,0x4B,0x4d, //1983 0xAB,0x25,0xC2, //1984 0x06,0xA5,0x54, //1985 0x06,0xd4,0x49, //1986 0x6A,0xdA,0x3d, //1987 0x0A,0xB6,0x51, //1988 0x09,0x37,0x46, //1989 0x54,0x97,0xBB, //1990 0x04,0x97,0x4f, //1991 0x06,0x4B,0x44, //1992 0x36,0xA5,0x37, //1993 0x0e,0xA5,0x4A, //1994 0x86,0xB2,0xBf, //1995 0x05,0xAC,0x53, //1996 0x0A,0xB6,0x47, //1997 0x59,0x36,0xBC, //1998 0x09,0x2e,0x50, //1999 294 0x0C,0x96,0x45, //2000 297 0x4d,0x4A,0xB8, //2001 0x0d,0x4A,0x4C, //2002 0x0d,0xA5,0x41, //2003 0x25,0xAA,0xB6, //2004 0x05,0x6A,0x49, //2005 0x7A,0xAd,0xBd, //2006 0x02,0x5d,0x52, //2007 0x09,0x2d,0x47, //2008 0x5C,0x95,0xBA, //2009 0x0A,0x95,0x4e, //2010 0x0B,0x4A,0x43, //2011 0x4B,0x55,0x37, //2012 0x0A,0xd5,0x4A, //2013 0x95,0x5A,0xBf, // 0x04,0xBA,0x53, //2023 0x0A,0x5B,0x48, //2023 0x65,0x2B,0xBC, //2023 0x05,0x2B,0x50, //2023 0x0A,0x93,0x45, //2023 0x47,0x4A,0xB9, //2023 0x06,0xAA,0x4C, //2023 0x0A,0xd5,0x41, //2023 0x24,0xdA,0xB6, //2023 0x04,0xB6,0x4A, //2024 0x69,0x57,0x3d, //2025 0x0A,0x4e,0x51, //2026 0x0d,0x26,0x46, //2027 0x5e,0x93,0x3A, //2028 0x0d,0x53,0x4d, //2029 0x05,0xAA,0x43, //2030 0x36,0xB5,0x37, //2031 0x09,0x6d,0x4B, //2032 0xB4,0xAe,0xBf, //2033 0x04,0xAd,0x53, //2034 0x0A,0x4d,0x48, //2035 0x6d,0x25,0xBC, //2036 0x0d,0x25,0x4f, //2037 0x0d,0x52,0x44, //2038 0x5d,0xAA,0x38, //2039 0x0B,0x5A,0x4C, //2040 0x05,0x6d,0x41, //2041 0x24,0xAd,0xB6, //2042 0x04,0x9B,0x4A, //2043 0x7A,0x4B,0xBe, //2044 0x0A,0x4B,0x51, //2045 0x0A,0xA5,0x46, //2046 0x5B,0x52,0xBA, //2047 0x06,0xd2,0x4e, //2048 0x0A,0xdA,0x42, //2049 0x35,0x5B,0x37, //2050 0x09,0x37,0x4B, //2051 0x84,0x97,0xC1, //2052 0x04,0x97,0x53, //2053 0x06,0x4B,0x48, //2054 0x66,0xA5,0x3C, //2055 0x0e,0xA5,0x4f, //2056 0x06,0xB2,0x44, //2057 0x4A,0xB6,0x38, //2058 0x0A,0xAe,0x4C, //2059 0x09,0x2e,0x42, //2060 0x3C,0x97,0x35, //2061 0x0C,0x96,0x49, //2062 0x7d,0x4A,0xBd, //2063 0x0d,0x4A,0x51, //2064 0x0d,0xA5,0x45, //2065 0x55,0xAA,0xBA, //2066 0x05,0x6A,0x4e, //2067 0x0A,0x6d,0x43, //2068 0x45,0x2e,0xB7, //2069 0x05,0x2d,0x4B, //2070 0x8A,0x95,0xBf, //2071 0x0A,0x95,0x53, //2072 0x0B,0x4A,0x47, //2073 0x6B,0x55,0x3B, //2074 0x0A,0xd5,0x4f, //2075 0x05,0x5A,0x45, //2076 0x4A,0x5d,0x38, //2077 0x0A,0x5B,0x4C, //2078 0x05,0x2B,0x42, //2079 0x3A,0x93,0xB6, //2080 0x06,0x93,0x49, //2081 0x77,0x29,0xBd, //2082 0x06,0xAA,0x51, //2083 0x0A,0xd5,0x46, //2084 0x54,0xdA,0xBA, //2085 0x04,0xB6,0x4e, //2086 0x0A,0x57,0x43, //2087 0x45,0x27,0x38, //2088 0x0d,0x26,0x4A, //2089 0x8e,0x93,0x3e, //2090 0x0d,0x52,0x52, //2091 0x0d,0xAA,0x47, //2092 0x66,0xB5,0x3B, //2093 0x05,0x6d,0x4f, //2094 0x04,0xAe,0x45, //2095 0x4A,0x4e,0xB9, //2096 0x0A,0x4d,0x4C, //2097 0x0d,0x15,0x41, //2098 0x2d,0x92,0xB5, //2099};///月份数据表code uchar day_code1[9]={0x0,0x1f,0x3b,0x5a,0x78,0x97,0xb5,0xd4,0xf3};code uint day_code2[3]={0x111,0x130,0x14e};/*函数功能:输入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数据*/bit c_moon;data uchar year_moon,month_moon,day_moon,week;/*子函数,用于读取数据表中农历月的大月或小月,如果该月为大返回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-1 if (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月为闰月,天数加1 temp4+=1; } //计算公历日离当年元旦的天数完成 //判断公历日在春节前还是春节后 if (temp4>=temp3) { //公历日在春节后或就是春节当日使用下面代码进行运算 temp4-=temp3; month=0x1; month_p=0x1; //month_p为月份指向,公历日在春节前或就是春节当日month_p指向首月 flag2=get_moon_day(month_p,table_addr); //检查该农历月为大小还是小月,大月返回1,小月返回0 flag_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; else month_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世纪,年份数加100 temp1=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;void main(){ c_sun=1; year_sun=0x2; month_sun=0x11; day_sun=0x3; Conver_week(c_sun,year_sun,month_sun,day_sun); Conversion(c_sun,year_sun,month_sun,day_sun); while(1);}