C51寫的公歷轉農歷和星期_第1頁
C51寫的公歷轉農歷和星期_第2頁
已閱讀5頁,還剩5頁未讀 繼續免費閱讀

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領

文檔簡介

1、c51寫的公歷轉農歷和星期 wannianli /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 表示春節的公歷月份,b

2、it4-0 表示春節的公歷日期 */ code uchar year_code597 = 0x04,0xae,0x53, 0x0a,0x57,0x48, 0x55,0x26,0xbd, 0x0d,0x26,0x50, 0x0d,0x95,0x44, 0x46,0xaa,0xb9, 0x05,0x6a,0x4d, 0x09,0xad,0x42, 0x24,0xae,0xb6, 0x04,0xae,0x4a, 0x6a,0x4d,0xbe, 0x0a,0x4d,0x52, 0x0d,0x25,0x46, 0x5d,0x52,0xba, 0x0b,0x54,0x4e, 0x0d,0x6a,0x43,

3、 0x29,0x6d,0x37, 0x09,0x5b,0x4b, 0x74,0x9b,0xc1, 0x04,0x97,0x54, 0x0a,0x4b,0x48, 0x5b,0x25,0xbc, 0x06,0xa5,0x50, 0x06,0xd4,0x45, 0x4a,0xda,0xb8, 0x02,0xb6,0x4d, 0x09,0x57,0x42, 0x24,0x97,0xb7, 0x04,0x97,0x4a, 0x66,0x4b,0x3e, /1901 0 /1902 3 /1903 6 /1904 9 /1905 12 /1906 15 /1907 18 /1908 21 /1909 /

4、1910 /1911 /1912 /1913 /1914 /1915 /1916 /1917 /1918 /1919 /1920 /1921 /1922 /1923 /1924 /1925 /1926 /1927 /1928 /1929 /1930 wannianli 0x0d,0x4a,0x51, 0x0e,0xa5,0x46, 0x56,0xd4,0xba, 0x05,0xad,0x4e, 0x02,0xb6,0x44, 0x39,0x37,0x38, 0x09,0x2e,0x4b, 0x7c,0x96,0xbf, 0x0c,0x95,0x53, 0x0d,0x4a,0x48, 0x6d,

5、0xa5,0x3b, 0x0b,0x55,0x4f, 0x05,0x6a,0x45, 0x4a,0xad,0xb9, 0x02,0x5d,0x4d, 0x09,0x2d,0x42, 0x2c,0x95,0xb6, 0x0a,0x95,0x4a, 0x7b,0x4a,0xbd, 0x06,0xca,0x51, 0x0b,0x55,0x46, 0x55,0x5a,0xbb, 0x04,0xda,0x4e, 0x0a,0x5b,0x43, 0x35,0x2b,0xb8, 0x05,0x2b,0x4c, 0x8a,0x95,0x3f, 0x0e,0x95,0x52, 0x06,0xaa,0x48, 0

6、x7a,0xd5,0x3c, 0x0a,0xb5,0x4f, 0x04,0xb6,0x45, 0x4a,0x57,0x39, 0x0a,0x57,0x4d, 0x05,0x26,0x42, 0x3e,0x93,0x35, 0x0d,0x95,0x49, 0x75,0xaa,0xbe, 0x05,0x6a,0x51, 0x09,0x6d,0x46, 0x54,0xae,0xbb, 0x04,0xad,0x4f, /1931 /1932 /1933 /1934 /1935 /1936 /1937 /1938 /1939 /1940 /1941 /1942 /1943 /1944 /1945 /19

7、46 /1947 /1948 /1949 /1950 /1951 /1952 /1953 /1954 /1955 /1956 /1957 /1958 /1959 /1960 /1961 /1962 /1963 /1964 /1965 /1966 /1967 /1968 /1969 /1970 /1971 /1972 wannianli 0x0a,0x4d,0x43, 0x4d,0x26,0xb7, 0x0d,0x25,0x4b, 0x8d,0x52,0xbf, 0x0b,0x54,0x52, 0x0b,0x6a,0x47, 0x69,0x6d,0x3c, 0x09,0x5b,0x50, 0x0

8、4,0x9b,0x45, 0x4a,0x4b,0xb9, 0x0a,0x4b,0x4d, 0xab,0x25,0xc2, 0x06,0xa5,0x54, 0x06,0xd4,0x49, 0x6a,0xda,0x3d, 0x0a,0xb6,0x51, 0x09,0x37,0x46, 0x54,0x97,0xbb, 0x04,0x97,0x4f, 0x06,0x4b,0x44, 0x36,0xa5,0x37, 0x0e,0xa5,0x4a, 0x86,0xb2,0xbf, 0x05,0xac,0x53, 0x0a,0xb6,0x47, 0x59,0x36,0xbc, 0x09,0x2e,0x50,

9、 0x0c,0x96,0x45, 0x4d,0x4a,0xb8, 0x0d,0x4a,0x4c, 0x0d,0xa5,0x41, 0x25,0xaa,0xb6, 0x05,0x6a,0x49, 0x7a,0xad,0xbd, 0x02,0x5d,0x52, 0x09,0x2d,0x47, 0x5c,0x95,0xba, 0x0a,0x95,0x4e, 0x0b,0x4a,0x43, 0x4b,0x55,0x37, 0x0a,0xd5,0x4a, 0x95,0x5a,0xbf, /1973 /1974 /1975 /1976 /1977 /1978 /1979 /1980 /1981 /1982

10、 /1983 / /1984 /1985 /1986 /1987 /1988 /1989 /1990 /1991 /1992 /1993 /1994 /1995 /1996 /1997 /1998 /1999 294 /2000 297 /2021 /2021 /2021 /2021 /2021 /2021 /2021 /2021 /2021 /2021 /2021 /2021 /2021 /2021 wannianli 0x04,0xba,0x53, 0x0a,0x5b,0x48, 0x65,0x2b,0xbc, 0x05,0x2b,0x50, 0x0a,0x93,0x45, 0x47,0x

11、4a,0xb9, 0x06,0xaa,0x4c, 0x0a,0xd5,0x41, 0x24,0xda,0xb6, 0x04,0xb6,0x4a, 0x69,0x57,0x3d, 0x0a,0x4e,0x51, 0x0d,0x26,0x46, 0x5e,0x93,0x3a, 0x0d,0x53,0x4d, 0x05,0xaa,0x43, 0x36,0xb5,0x37, 0x09,0x6d,0x4b, 0xb4,0xae,0xbf, 0x04,0xad,0x53, 0x0a,0x4d,0x48, 0x6d,0x25,0xbc, 0x0d,0x25,0x4f, 0x0d,0x52,0x44, 0x5

12、d,0xaa,0x38, 0x0b,0x5a,0x4c, 0x05,0x6d,0x41, 0x24,0xad,0xb6, 0x04,0x9b,0x4a, 0x7a,0x4b,0xbe, 0x0a,0x4b,0x51, 0x0a,0xa5,0x46, 0x5b,0x52,0xba, 0x06,0xd2,0x4e, 0x0a,0xda,0x42, 0x35,0x5b,0x37, 0x09,0x37,0x4b, 0x84,0x97,0xc1, 0x04,0x97,0x53, 0x06,0x4b,0x48, 0x66,0xa5,0x3c, 0x0e,0xa5,0x4f, /2021 /2021 /20

13、21 /2021 /2021 /2021 /2021 /2022 /2023 /2024 /2025 /2026 /2027 /2028 /2029 /2030 /2031 /2032 /2033 /2034 /2035 /2036 /2037 /2038 /2039 /2040 /2041 /2042 /2043 /2044 /2045 /2046 /2047 /2048 /2049 /2050 /2051 /2052 /2053 /2054 /2055 /2056 wannianli 0x06,0xb2,0x44, 0x4a,0xb6,0x38, 0x0a,0xae,0x4c, 0x09,

14、0x2e,0x42, 0x3c,0x97,0x35, 0x0c,0x96,0x49, 0x7d,0x4a,0xbd, 0x0d,0x4a,0x51, 0x0d,0xa5,0x45, 0x55,0xaa,0xba, 0x05,0x6a,0x4e, 0x0a,0x6d,0x43, 0x45,0x2e,0xb7, 0x05,0x2d,0x4b, 0x8a,0x95,0xbf, 0x0a,0x95,0x53, 0x0b,0x4a,0x47, 0x6b,0x55,0x3b, 0x0a,0xd5,0x4f, 0x05,0x5a,0x45, 0x4a,0x5d,0x38, 0x0a,0x5b,0x4c, 0

15、x05,0x2b,0x42, 0x3a,0x93,0xb6, 0x06,0x93,0x49, 0x77,0x29,0xbd, 0x06,0xaa,0x51, 0x0a,0xd5,0x46, 0x54,0xda,0xba, 0x04,0xb6,0x4e, 0x0a,0x57,0x43, 0x45,0x27,0x38, 0x0d,0x26,0x4a, 0x8e,0x93,0x3e, 0x0d,0x52,0x52, 0x0d,0xaa,0x47, 0x66,0xb5,0x3b, 0x05,0x6d,0x4f, 0x04,0xae,0x45, 0x4a,0x4e,0xb9, 0x0a,0x4d,0x4

16、c, 0x0d,0x15,0x41, /2057 /2058 /2059 /2060 /2061 /2062 /2063 /2064 /2065 /2066 /2067 /2068 /2069 /2070 /2071 /2072 /2073 /2074 /2075 /2076 /2077 /2078 /2079 /2080 /2081 /2082 /2083 /2084 /2085 /2086 /2087 /2088 /2089 /2090 /2091 /2092 /2093 /2094 /2095 /2096 /2097 /2098 wannianli 0x2d,0x92,0xb5, ; /

17、月份數據表 /2099 code uchar day_code19=0x0,0x1f,0x3b,0x5a,0x78,0x97,0xb5,0xd4,0xf3; code uint day_code23=0x111,0x130,0x14e; /* 函數功能:輸入 bcd 陽歷數據,輸出 bcd 陰歷數據(只允許 1901-2099 年) 調用函數示例:conversion(c_sun,year_sun,month_sun,day_sun) 如:計算 2021 年 10 月 16 日 conversion(0,0x4,0x10,0x16); c_sun,year_sun,month_sun,day_

18、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; switc h (m

19、onth_p) case 1:temp=year_codetable_addr0x08; if (temp=0)return(0);else return(1); case 2:temp=year_codetable_addr0x04; if (temp=0)return(0);else return(1); case 3:temp=year_codetable_addr0x02; if (temp=0)return(0);else return(1); case 4:temp=year_codetable_addr0x01; if (temp=0)return(0);else return(

20、1); case 5:temp=year_codetable_addr+10x80; if (temp=0) return(0);else return(1); case 6:temp=year_codetable_addr+10x40; if (temp=0)return(0);else return(1); case 7:temp=year_codetable_addr+10x20; if (temp=0)return(0);else return(1); case 8:temp=year_codetable_addr+10x10; if (temp=0)return(0);else re

21、turn(1); case 9:temp=year_codetable_addr+10x08; if (temp=0)return(0);else return(1); case 10:temp=year_codetable_addr+10x04; wannianli if (temp=0)return(0);else return(1); case 11:temp=year_codetable_addr+10x02; if (temp=0)return(0);else return(1); case 12:temp=year_codetable_addr+10x01; if (temp=0)

22、return(0);else return(1); case 13:temp=year_codetable_addr+20x80; if (temp=0)return(0);else return(1); /* 函數功能:輸入 bcd 陽歷數據,輸出 bcd 陰歷數據(只允許 1901-2099 年) 調用函數示例:conversion(c_sun,year_sun,month_sun,day_sun) 如:計算 2021 年 10 月 16 日 conversion(0,0x4,0x10,0x16); c_sun,year_sun,month_sun,day_sun 均為 bcd 數據,c_

23、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) 據 uchar temp1,temp2,temp3,month_p; uint temp4,table_addr; bit flag2,flag_y; temp1=year/16; temp2=year%16; year=temp1*10+temp2; temp1=

24、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; /bcd-hex 先把數據轉換為十六進制 /c=0 為 21 世紀,c=1 為 19 世紀 輸入輸出數據均為 bcd 數 wannianli /定位數據表地址完成 /取當年春節所在的公歷月份 temp1=year_codetable_addr+20x60

25、; temp1=_cror_(temp1,5); /取當年春節所在的公歷月份完成 /取當年春節所在的公歷日 temp2=year_codetable_addr+20x1f; /取當年春節所在的公歷日完成 / 計算當年春年離當年元旦的天數,春節只會在公歷 1 月或 2 月 if(temp1=0x1) temp3=temp2-1; else temp3=temp2+0x1f-1; / 計算當年春年離當年元旦的天數完成 /計算公歷日離當年元旦的天數,為了削減運算,用了兩個表 /day_code19,day_code23 /假如公歷月在九月或前,天數會少于 0xff,用表 day_code19, /在

26、九月后,天數大于 0xff,用表 day_code23 /如輸入公歷日為 8 月 10 日,則公歷日離元旦天數為 day_code18-1+10-1 /如輸入公歷日為 11 月 10 日,則公歷日離元旦天數為 day_code211-10+10-1 if (month10) temp4=day_code1month-1+day-1; else temp4=day_code2 month-10+day-1; if (month0x2)(year%0x4=0) /假如公歷月大于 2 月并且該年的 2 月為閏月,天數加 1 temp4+=1; /計算公歷日離當年元旦的天數完成 /推斷公歷日在春節前還

27、是春節后 if (temp4=temp3) /公歷日在春節后或就是春節當日使用下面代碼進行運算 temp4-=temp3; wannianli 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_codetable_add

28、r0xf0; 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_codetable_addr0xf0; temp2=_cror_(temp2,4); if (temp2=0) month_p=0xc; else wannianli month_p=0xd; / /

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經權益所有人同意不得將文件中的內容挪作商業或盈利用途。
  • 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
  • 6. 下載文件中如有侵權或不適當內容,請與我們聯系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論