??
字號:
;**************************************
;公農歷算法
;*************************************
CONvert: MOV A,time_year ;將年月日轉化為HEX 格式
MOV B,#16
DIV AB
MOV CONvert_yeAr,B
MOV B,#10
MUL AB
ADD A,CONvert_yeAr
MOV CONvert_yeAr,A
MOV A,time_month
MOV C,ACC.7
MOV f0,C ;f0暫存世紀標志,僅用于數據表定位
CLR ACC.7
JNB ACC.4,CON_02
CLR ACC.4 ;ACC.4 為1 表示大于10 月
ADD A,#10
CON_02: MOV CONvert_mONth,A
MOV A,time_date
MOV B,#16
DIV AB
MOV CONvert_dAte,B
MOV B,#10
MUL AB
ADD A,CONvert_dAte
MOV CONvert_dAte,A
MOV dptr,#mONth_dAtA ;以下定位本年數據在表格中的位置
MOV A,CONvert_yeAr
JB f0,CON_06 ;當前為19 世紀年跳轉
ADD A,#100 ;從19 世紀起定義表格起始年,20 世紀要加100 年
CON_06: CLR C
SUBB A,#stArt_yeAr
MOV B,#3 ;表格每年3 字節
MUL AB
ADD A,dpl
MOV dpl,A
MOV A,B
ADDC A,dph
MOV dph,A
MOV A,#2
MOVC A,@A+dptr ;讀本年表格最后一字節(春節日期)
CLR ACC.7 ;ACC.7 是閏年第13 個月大小,在此不用
MOV B,#32
DIV AB
MOV temp_Byte1,A ;春節月份
MOV temp_Byte2,B ;春節日
; 以下計算當前日期距元旦天數
MOV temp_Byte3,#0 ;設距元旦天數高位為0
MOV A,CONvert_mONth
CJNE A,#10,CON_08
CON_08: JC CON_09 ;9月以前日子數小于256 天,高字節為0(9 月份過去的整月為8 個月)
MOV temp_Byte3,#1
CON_09: MOV A,CONvert_yeAr
ANL A,#03h ;ACC 為除4 的余數
JNZ CON_10 ;轉常年處理
; 年除4 余數為0 是閏年
MOV A,CONvert_mONth
LCALL get_ruN_dAys_lOw ;取得閏年過去月的天數的低字節
SJMP CON_12
CON_10: MOV A,CONvert_mONth
LCALL get_dAys_lOw ;取得常年過去月的天數的低字節
CON_12: MOV B,CONvert_dAte
DEC B ;因為日期從1 日起,而不是0 日起
ADD A,B ;過去的整月天數加當月天數
MOV temp_Byte4,A
JNC CON_14
INC temp_Byte3 ;temp_Byte3,temp_Byte4 分別為公歷年過去的天數的高低字節
; 以下求春節距元旦天數,因肯定小于256 天所以只用一字節表示
CON_14: MOV A,temp_Byte1
LCALL get_dAys_lOw ;春節不會在3 月份,不用考慮閏年
DEC A ;因為日期從1 日起
ADD A,temp_Byte2
MOV temp_Byte5,A ;temp_Byte5,為春節距元旦天數
MOV A,CONvert_mONth
CJNE A,temp_Byte1,CON_20 ;轉換月與春節月比較
MOV A,CONvert_dAte
CJNE A,temp_Byte2,CON_20 ;轉換日與春節日比較
CON_20: JC CON_22
LJMP CON_60 ;當前日大于等于春節日期,公歷年與農歷年同年份
CON_22: MOV A,CONvert_yeAr ;不到春節,農歷年比公歷年低一年
JNZ CON_24
MOV A,#100 ;年有效數0-99
CON_24: DEC A
MOV CONvert_yeAr,A
MOV A,dpl
CLR C
SUBB A,#3
MOV dpl,A
JNC CON_26
DEC dph ;表格指針指向上一年
CON_26: MOV A,temp_Byte5
CLR C
SUBB A,temp_Byte4
MOV temp_Byte3,A ;temp_Byte3 中為當前日離春節的天數
MOV CONvert_mONth,#12 ;農歷月為12 月
CLR f0 ;1901-2099 年沒有閏12 月,清閏月標志
CLR A
MOVC A,@A+dptr
ANL A,#0f0h
SWAP A;
MOV temp_Byte4,A ;temp_Byte4 中為閏月
JZ CON_30 ;沒有閏月轉移
MOV A,#2 ;有閏月,取第13 個月天數
MOVC A,@A+dptr
MOV C,ACC.7
MOV A,#1
MOVC A,@A+dptr
RLC A ;ACC 中為最后6 個月的大小值
SJMP CON_34
CON_30: MOV A,#1
MOVC A,@A+dptr ;ACC 中為最后6 個月的大小值
CON_34: MOV temp_Byte5,A
CON_40: MOV A,temp_Byte5
RRC A
MOV temp_Byte5,A
JC CON_42
MOV B,#29 ;小月29 天
SJMP CON_44
CON_42: MOV B,#30 ;大月30 天
CON_44: MOV A,temp_Byte3
CLR C
SUBB A,B
JZ CON_46 ;正好夠減,就是農歷日1 日
JNC CON_50
;不夠減一月天數,結束農歷月調整
CPL A ;求補取絕對值
INC A
CON_46: INC A ;加1 即為農歷日
MOV B,#10 ;轉換并保存農歷日,月,年
DIV AB
SWAP A
ORL A,B
MOV CONvert_dAte,A
MOV A,CONvert_mONth
MOV B,#10
DIV AB
SWAP A
ORL A,B
MOV C,f0
MOV ACC.7,C
MOV CONvert_mONth,A
MOV A,CONvert_yeAr
MOV B,#10
DIV AB
SWAP A
ORL A,B
MOV CONvert_yeAr,A
RET ;結束轉換
CON_50: MOV temp_Byte3,A ;temp_Byte3 存減去一月后的天數
JB f0,CON_52 ;是閏月,前推一月,月份不減
DEC CONvert_mONth;
CON_52: MOV A,CONvert_mONth
CJNE A,temp_Byte4,CON_54
CPL f0 ;當前月與閏月相同,更改閏月標志
CON_54: SJMP CON_40
CON_60: MOV A,temp_Byte4 ;春節日小于當前日,農歷年同公歷年
CLR C
SUBB A,temp_Byte5
MOV temp_Byte4,A
JNC CON_62
DEC temp_Byte3 ;temp_Byte3 temp_Byte4 中為公歷日離春節的天數
CON_62: MOV CONvert_mONth,#1 ;農歷月為1 月
CLR A
MOVC A,@A+dptr
MOV temp_Byte5,A
ANL A,#0f0h
SWAP A;
XCH A,temp_Byte5 ;temp_Byte5 中為閏月,ACC 為當年農歷表第一字節
CLR f0 ;第一個月肯定不是閏月
ANL A,#0fh
MOV temp_Byte1,A
MOV A,#1
MOVC A,@A+dptr
MOV temp_Byte2,A
ANL A,#0f0h
ORL A,temp_Byte1
SWAP A
MOV temp_Byte1,A
MOV A,#2
MOVC A,@A+dptr
MOV C,ACC.7
MOV A,temp_Byte2
ANL A,#0fh
SWAP A
MOV ACC.3,C;
MOV temp_Byte2,A ;以上temp_Byte1,temp_Byte2 各BIT 存農歷年大小
CON_70: MOV A,temp_Byte2
RLC A
MOV temp_Byte2,A
MOV A,temp_Byte1
RLC A
MOV temp_Byte1,A
JC CON_72
MOV B,#29 ;小月29 天處理
SJMP CON_74
CON_72: MOV B,#30 ;大月30 天
CON_74: MOV A,temp_Byte4
CLR C
SUBB A,B
JNC CON_78 ;低字節夠減跳轉
MOV B,A ;低字節不夠減, B 暫存減后結果,
MOV A,temp_Byte3
JZ CON_76 ;高字節為0,不夠減
DEC temp_Byte3
MOV temp_Byte4,B
SJMP CON_80
CON_76: MOV A,temp_Byte4 ;不夠減結束月調整
LJMP CON_46 ;轉日期加1 后,處理并保存轉換后農歷年月日
CON_78: MOV temp_Byte4,A ;temp_Byte3 temp_Byte4 天數為減去一月后天數
CON_80: MOV A,CONvert_mONth
CJNE A,temp_Byte5,CON_82
CPL f0 ;當前月與閏月相同,更改閏月標志
JNB f0,CON_82 ;更改標志后是非閏月,月份加1
SJMP CON_70
CON_82: INC CONvert_mONth;
SJMP CON_70
get_dAys_lOw:
MOVC A,@A+PC ;取得常年過去月的天數的低字節
RET
DB 0,31,59,90,120,151,181,212,243,17,48,78
get_ruN_dAys_lOw:
MOVC A,@A+PC ;取得閏年過去月的天數的低字節
RET
DB 0,31,60,91,121,152,182,213,244,18,49,79
mONth_dAtA:
;公歷年對應的農歷數據,每年三字節,
;格式第一字節BIT7-4 位表示閏月月份,值為0 為無閏月,BIT3-0 對應農歷第1-4 月的大小
;第二字節BIT7-0 對應農歷第5-12 月大小,第三字節BIT7 表示農歷第13 個月大小
;月份對應的位為1 表示本農歷月大(30 天),為0 表示小(29 天).
;第三字節BIT6-5 表示春節的公歷月份,BIT4-0 表示春節的公歷日期
DB 004h,0Aeh,053h; 1901;
DB 00Ah,057h,048h; 1902
DB 055h,026h,0Bdh; 1903
DB 00dh,026h,050h; 1904
DB 00dh,095h,044h; 1905
DB 046h,0AAh,0B9h; 1906
DB 005h,06Ah,04dh; 1907
DB 009h,0Adh,042h; 1908
DB 024h,0Aeh,0B6h; 1909
DB 004h,0Aeh,04Ah; 1910
DB 06Ah,04dh,0Beh; 1911
DB 00Ah,04dh,052h; 1912
DB 00dh,025h,046h; 1913
DB 05dh,052h,0BAh; 1914
DB 00Bh,054h,04eh; 1915
DB 00dh,06Ah,043h; 1916
DB 029h,06dh,037h; 1917
DB 009h,05Bh,04Bh; 1918
DB 074h,09Bh,0C1h; 1919
DB 004h,097h,054h; 1920
DB 00Ah,04Bh,048h; 1921
DB 05Bh,025h,0BCh; 1922
DB 006h,0A5h,050h; 1923
DB 006h,0d4h,045h; 1924
DB 04Ah,0dAh,0B8h; 1925
DB 002h,0B6h,04dh; 1926
DB 009h,057h,042h; 1927
DB 024h,097h,0B7h; 1928
DB 004h,097h,04Ah; 1929
DB 066h,04Bh,03eh; 1930
DB 00dh,04Ah,051h; 1931
DB 00eh,0A5h,046h; 1932
DB 056h,0d4h,0BAh; 1933
DB 005h,0Adh,04eh; 1934
DB 002h,0B6h,044h; 1935
DB 039h,037h,038h; 1936
DB 009h,02eh,04Bh; 1937
DB 07Ch,096h,0Bfh; 1938
DB 00Ch,095h,053h; 1939
DB 00dh,04Ah,048h; 1940
DB 06dh,0A5h,03Bh; 1941
DB 00Bh,055h,04fh; 1942
DB 005h,06Ah,045h; 1943
DB 04Ah,0Adh,0B9h; 1944
DB 002h,05dh,04dh; 1945
DB 009h,02dh,042h; 1946
DB 02Ch,095h,0B6h; 1947
DB 00Ah,095h,04Ah; 1948
DB 07Bh,04Ah,0Bdh; 1949
DB 006h,0CAh,051h; 1950
DB 00Bh,055h,046h; 1951
DB 055h,05Ah,0BBh; 1952
DB 004h,0dAh,04eh; 1953
DB 00Ah,05Bh,043h; 1954
DB 035h,02Bh,0B8h; 1955
DB 005h,02Bh,04Ch; 1956
DB 08Ah,095h,03fh; 1957
DB 00eh,095h,052h; 1958
DB 006h,0AAh,048h; 1959
DB 07Ah,0d5h,03Ch; 1960
DB 00Ah,0B5h,04fh; 1961
DB 004h,0B6h,045h; 1962
DB 04Ah,057h,039h; 1963
DB 00Ah,057h,04dh; 1964
DB 005h,026h,042h; 1965
DB 03eh,093h,035h; 1966
DB 00dh,095h,049h; 1967
DB 075h,0AAh,0Beh; 1968
DB 005h,06Ah,051h; 1969
DB 009h,06dh,046h; 1970
DB 054h,0Aeh,0BBh; 1971
DB 004h,0Adh,04fh; 1972
DB 00Ah,04dh,043h; 1973
DB 04dh,026h,0B7h; 1974
DB 00dh,025h,04Bh; 1975
DB 08dh,052h,0Bfh; 1976
DB 00Bh,054h,052h; 1977
DB 00Bh,06Ah,047h; 1978
DB 069h,06dh,03Ch; 1979
DB 009h,05Bh,050h; 1980
DB 004h,09Bh,045h; 1981
DB 04Ah,04Bh,0B9h; 1982
DB 00Ah,04Bh,04dh; 1983
DB 0ABh,025h,0C2h; 1984
DB 006h,0A5h,054h; 1985
DB 006h,0d4h,049h; 1986
DB 06Ah,0dAh,03dh; 1987
DB 00Ah,0B6h,051h; 1988
DB 009h,037h,046h; 1989
DB 054h,097h,0BBh; 1990
DB 004h,097h,04fh; 1991
DB 006h,04Bh,044h; 1992
DB 036h,0A5h,037h; 1993
DB 00eh,0A5h,04Ah; 1994
DB 086h,0B2h,0Bfh; 1995
DB 005h,0ACh,053h; 1996
DB 00Ah,0B6h,047h; 1997
DB 059h,036h,0BCh; 1998
DB 009h,02eh,050h; 1999
DB 00Ch,096h,045h; 2000
DB 04dh,04Ah,0B8h; 2001
DB 00dh,04Ah,04Ch; 2002
DB 00dh,0A5h,041h; 2003
DB 025h,0AAh,0B6h; 2004
DB 005h,06Ah,049h; 2005
DB 07Ah,0Adh,0Bdh; 2006
DB 002h,05dh,052h; 2007
DB 009h,02dh,047h; 2008
DB 05Ch,095h,0BAh; 2009
DB 00Ah,095h,04eh; 2010
DB 00Bh,04Ah,043h; 2011
DB 04Bh,055h,037h; 2012
DB 00Ah,0d5h,04Ah; 2013
DB 095h,05Ah,0Bfh; 2014
DB 004h,0BAh,053h; 2015
DB 00Ah,05Bh,048h; 2016
DB 065h,02Bh,0BCh; 2017
DB 005h,02Bh,050h; 2018
DB 00Ah,093h,045h; 2019
DB 047h,04Ah,0B9h; 2020
DB 006h,0AAh,04Ch; 2021
DB 00Ah,0d5h,041h; 2022
DB 024h,0dAh,0B6h; 2023
DB 004h,0B6h,04Ah; 2024
DB 069h,057h,03dh; 2025
DB 00Ah,04eh,051h; 2026
DB 00dh,026h,046h; 2027
DB 05eh,093h,03Ah; 2028
DB 00dh,053h,04dh; 2029
DB 005h,0AAh,043h; 2030
DB 036h,0B5h,037h; 2031
DB 009h,06dh,04Bh; 2032
DB 0B4h,0Aeh,0Bfh; 2033
DB 004h,0Adh,053h; 2034
DB 00Ah,04dh,048h; 2035
DB 06dh,025h,0BCh; 2036
DB 00dh,025h,04fh; 2037
DB 00dh,052h,044h; 2038
DB 05dh,0AAh,038h; 2039
DB 00Bh,05Ah,04Ch; 2040
DB 005h,06dh,041h; 2041
DB 024h,0Adh,0B6h; 2042
DB 004h,09Bh,04Ah; 2043
DB 07Ah,04Bh,0Beh; 2044
DB 00Ah,04Bh,051h; 2045
DB 00Ah,0A5h,046h; 2046
DB 05Bh,052h,0BAh; 2047
DB 006h,0d2h,04eh; 2048
DB 00Ah,0dAh,042h; 2049
DB 035h,05Bh,037h; 2050
DB 009h,037h,04Bh; 2051
DB 084h,097h,0C1h; 2052
DB 004h,097h,053h; 2053
DB 006h,04Bh,048h; 2054
DB 066h,0A5h,03Ch; 2055
DB 00eh,0A5h,04fh; 2056
DB 006h,0B2h,044h; 2057
DB 04Ah,0B6h,038h; 2058
DB 00Ah,0Aeh,04Ch; 2059
DB 009h,02eh,042h; 2060
DB 03Ch,097h,035h; 2061
DB 00Ch,096h,049h; 2062
DB 07dh,04Ah,0Bdh; 2063
DB 00dh,04Ah,051h; 2064
DB 00dh,0A5h,045h; 2065
DB 055h,0AAh,0BAh; 2066
DB 005h,06Ah,04eh; 2067
DB 00Ah,06dh,043h; 2068
DB 045h,02eh,0B7h; 2069
DB 005h,02dh,04Bh; 2070
DB 08Ah,095h,0Bfh; 2071
DB 00Ah,095h,053h; 2072
DB 00Bh,04Ah,047h; 2073
DB 06Bh,055h,03Bh; 2074
DB 00Ah,0d5h,04fh; 2075
DB 005h,05Ah,045h; 2076
DB 04Ah,05dh,038h; 2077
DB 00Ah,05Bh,04Ch; 2078
DB 005h,02Bh,042h; 2079
DB 03Ah,093h,0B6h; 2080
DB 006h,093h,049h; 2081
DB 077h,029h,0Bdh; 2082
DB 006h,0AAh,051h; 2083
DB 00Ah,0d5h,046h; 2084
DB 054h,0dAh,0BAh; 2085
DB 004h,0B6h,04eh; 2086
DB 00Ah,057h,043h; 2087
DB 045h,027h,038h; 2088
DB 00dh,026h,04Ah; 2089
DB 08eh,093h,03eh; 2090
DB 00dh,052h,052h; 2091
DB 00dh,0AAh,047h; 2092
DB 066h,0B5h,03Bh; 2093
DB 005h,06dh,04fh; 2094
DB 004h,0Aeh,045h; 2095
DB 04Ah,04eh,0B9h; 2096
DB 00Ah,04dh,04Ch; 2097
DB 00dh,015h,041h; 2098
DB 02dh,092h,0B5h; 2099
DB 00dh,053h,049h; 2100
;以下子程序用于從當前公歷日期,推算星期,
;入口:time_yeAr,time_month ,time_date ,定義公歷年月日,BCD 碼,其中月的
;BIT7 表示世紀,0 表示20 世紀,1 表示19 世紀,與PCF8563 一致
;出口 time_week, 0-6 表示星期日-星期六,與PCF8563 一致,程序不改變入口數據
;使用資源:ACC,B,psw,temp_Byte1,temp_Byte2,temp_Byte3
GetWeek: MOV A,time_yeAr
MOV B,#16
DIV AB
MOV temp_Byte1,B
MOV B,#10
MUL AB
ADD A,temp_Byte1
MOV temp_Byte1,A ;temp_Byte1=年
MOV A,time_month
JB ACC.7,getw02
MOV A,#100
ADD A,temp_Byte1
MOV temp_Byte1,A ;20世紀年+100
MOV A,time_month
CLR ACC.7
getw02: JNB ACC.4,getw04
ADD A,#10
CLR ACC.4
getw04: MOV temp_Byte2,A ;temp_Byte2=月
MOV A,time_date
MOV B,#16
DIV AB
MOV temp_Byte3,B
MOV B,#10
MUL AB
ADD A,temp_Byte3
MOV temp_Byte3,A ;temp_Byte3=日
MOV A,temp_Byte1;
ANL A,#03h
JNZ getw10 ;非閏年轉移
MOV A,temp_Byte2
CJNE A,#3,getw06
getw06: JNC getw10 ;月大于2 轉移
DEC temp_Byte3 ;份小于等于2,又是閏年,日減1
getw10: MOV A,temp_Byte2;
LCALL get_CorreCt ;取月校正表數據
ADD A,temp_Byte1
MOV B,#7
DIV AB ;B放年加校正日數之和后除7 的余數不先做這一步
;有可能數據溢出
MOV A,temp_Byte1
ANL A,#0fCh
RR A
RR A ;以上年除4 即閏年數
ADD A,B
ADD A,temp_Byte3
MOV B,#7
DIV AB
MOV time_week,B
RET
get_COrreCt:
MOVC A,@A+PC
RET
DB 0,3,3,6,1,4,6,2,5,0,3,5
xing:db 0FEH,060H,0DAH,0F2H,066H,0B6H,0BEH,
TAB:DB 0FCH,060H,0DAH,0F2H,066H
DB 0B6H,0BEH,0E0H,0FEH,0F6H
chxie_ds1302: mov r0,#sec
mov r7,#7
setb psw.5
lcall rwrtc
ret
dingshi :MOV r0,#70h
mov r7,#02h
setb psw.5
lcall rwrtc
MOV A,70H
CJNE A,HOUR,DINGSHI1
RET
DINGSHI1:MOV A,71H
CJNE A,#MIN,OUT4
CLR P0.6
OUT4 : ret
END
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -