導航:首頁 > 操作系統 > 51單片機加陰歷日期

51單片機加陰歷日期

發布時間:2023-03-29 13:40:43

㈠ 跪求個利用51單片機1602顯示屏DS1302做的萬年歷c編程序,帶有公歷,農歷,星期,時間功能,一定要有農歷

農歷計算方式,
///月份數據表
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;
}

㈡ 能分享一下關於51單片機製作的萬年歷課設嗎,要求能顯示陰歷,陽歷,星期,時間,其他功能不要有,謝謝

陰歷,陽歷
都有,時間
AT89c51+DS1302+數碼管頌指顯示+獨立按祥亂鍵控制交互謹櫻檔
哈哈
可以分屏顯示或者

㈢ 想用單片機設計一個萬年歷,如何實現陽歷到農歷的轉換最好是給出思路和相關程序。

<%
' 用途:
' 當前日期計算該日期的農歷天乾地支及當年屬相
' ##-------------------------------------------##
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) = 46
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
%>

㈣ 關於51單片機哪款適合做電子時鍾

STC8952足夠了,網上有現成的萬年歷51,包括時間,日期,(陰歷)節氣都有,當然鬧鍾也是有的,代碼也非常小,你不一定要去看那個代碼,
實際上就是告訴你寫出這個程序代碼不需要很大的空間,52完全是夠了,速度方面52足夠強了,再去買ds1302晶元,其它的也可以,不買都行,上面萬年歷那個就可以實現這個功能,+顯示屏
淘寶上大量都可以選擇。

㈤ 用51單片機設計萬年歷系統 要求 1.實時顯示當前的時間、包括時分秒 2.實時顯示日期,包括年、月、日;

我有個做好的可以實現1,2,3,4,6,7的功肆薯讓能,要不??? 至於腦中自己加段程序就OK 了 ,相信你可以完成。。。 需要的話留下裂局郵箱 有仿手晌真文件 和程序 全套 。。。

㈥ 基於51單片機製作萬年歷,用數碼管,定時器,不用時鍾晶元,不用液晶,怎麼做求大神解,原理圖和C程序

基於51單片機製作萬年歷,用兩個8位一體的共陰數碼管,顯示日期和時間。數碼管位選用兩片74HC138,便於動態掃描顯示,又節省引腳。用3個按鍵調時,K1為選擇調時狀態,K2為加1鍵,K3為減1鍵。

模擬圖如下:

㈦ 51單片機運用ds1302進行陽歷與農歷的轉換,求高手解答,謝謝。

1302隻是一個時鍾晶元培螞,農歷的轉換配帶埋和1302沒任何關系。是單片機從1302中讀出日期後按行襪一定規則換算的

㈧ 那位網友見過這款用51單片機製作數字萬年歷嗎

這年代想要分享是不可能了 除非是花錢 本人手上也沒這代碼

㈨ 急求 51單片機的萬年歷課設電路圖及代碼 謝謝

別人沒事,翻幾天資料給你寫論文,你覺得可能嘛?反正我是不會說我學電子信息工程的,我不會做51單片機那些電子自動化的東西的

㈩ 用51單片機製作可以顯示年月日時分秒的萬年歷,有電路圖和匯編語言程序。

可以,有1602LCD就可以

記得採納啊

閱讀全文

與51單片機加陰歷日期相關的資料

熱點內容
安卓手機微信發不出視頻怎麼弄 瀏覽:229
壓縮機專用工具 瀏覽:575
qtcreator可以編譯cp嗎 瀏覽:405
小項目是雲伺服器還是本地好 瀏覽:14
墨痕齋是什麼游戲的伺服器 瀏覽:942
word文件如何壓縮大小 瀏覽:279
遵義聯通伺服器地址是什麼 瀏覽:29
ansys約束命令流 瀏覽:814
解壓軟體電腦版如何下載 瀏覽:791
閃電匕首演算法球 瀏覽:692
linuxredis停止命令 瀏覽:670
大麥賬號怎麼加密 瀏覽:113
穿越火線怎麼找伺服器 瀏覽:526
秘密加密社交軟體app 瀏覽:256
c語言編譯器怎麼找文件 瀏覽:836
數學不好能編程嗎 瀏覽:254
微雲里的視頻加密 瀏覽:41
3大加密貨幣交易平台 瀏覽:647
鈑金激光切割機編程 瀏覽:496
vivo手機手電筒app在哪裡 瀏覽:787