?? 帶農(nóng)歷.c
字號:
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
};
///月份數(shù)據(jù)表
code uchar day_code1[9]={0x0,0x1f,0x3b,0x5a,0x78,0x97,0xb5,0xd4,0xf3};
code uint day_code2[3]={0x111,0x130,0x14e};
/*
函數(shù)功能:輸入BCD陽歷數(shù)據(jù),輸出BCD陰歷數(shù)據(jù)(只允許1901-2099年)
調(diào)用函數(shù)示例:Conversion(c_sun,year_sun,month_sun,day_sun)
如:計(jì)算2004年10月16日Conversion(0,0x4,0x10,0x16);
c_sun,year_sun,month_sun,day_sun均為BCD數(shù)據(jù),c_sun為世紀(jì)標(biāo)志位,c_sun=0為21世
紀(jì),c_sun=1為19世紀(jì)
調(diào)用函數(shù)后,原有數(shù)據(jù)不變,讀c_moon,year_moon,month_moon,day_moon得出陰歷BCD數(shù)據(jù)
*/
bit c_moon;
data uchar year_moon,month_moon,day_moon,week;
/*子函數(shù),用于讀取數(shù)據(jù)表中農(nóng)歷月的大月或小月,如果該月為大返回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);}
}
}
/*
函數(shù)功能:輸入BCD陽歷數(shù)據(jù),輸出BCD陰歷數(shù)據(jù)(只允許1901-2099年)
調(diào)用函數(shù)示例:Conversion(c_sun,year_sun,month_sun,day_sun)
如:計(jì)算2004年10月16日Conversion(0,0x4,0x10,0x16);
c_sun,year_sun,month_sun,day_sun均為BCD數(shù)據(jù),c_sun為世紀(jì)標(biāo)志位,c_sun=0為21世
紀(jì),c_sun=1為19世紀(jì)
調(diào)用函數(shù)后,原有數(shù)據(jù)不變,讀c_moon,year_moon,month_moon,day_moon得出陰歷BCD數(shù)據(jù)
*/
void Conversion(bit c,uchar year,uchar month,uchar day)
{ //c=0 為21世紀(jì),c=1 為19世紀(jì) 輸入輸出數(shù)據(jù)均為BCD數(shù)據(jù)
uchar temp1,temp2,temp3,month_p;
uint temp4,table_addr;
bit flag2,flag_y;
temp1=year/16; //BCD->hex 先把數(shù)據(jù)轉(zhuǎn)換為十六進(jìn)制
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;
//定位數(shù)據(jù)表地址
if(c==0){
table_addr=(year+0x64-1)*0x3;
}
else {
table_addr=(year-1)*0x3;
}
//定位數(shù)據(jù)表地址完成
//取當(dāng)年春節(jié)所在的公歷月份
temp1=year_code[table_addr+2]&0x60;
temp1=_cror_(temp1,5);
//取當(dāng)年春節(jié)所在的公歷月份完成
//取當(dāng)年春節(jié)所在的公歷日
temp2=year_code[table_addr+2]&0x1f;
//取當(dāng)年春節(jié)所在的公歷日完成
// 計(jì)算當(dāng)年春年離當(dāng)年元旦的天數(shù),春節(jié)只會在公歷1月或2月
if(temp1==0x1){
temp3=temp2-1;
}
else{
temp3=temp2+0x1f-1;
}
// 計(jì)算當(dāng)年春年離當(dāng)年元旦的天數(shù)完成
//計(jì)算公歷日離當(dāng)年元旦的天數(shù),為了減少運(yùn)算,用了兩個表
//day_code1[9],day_code2[3]
//如果公歷月在九月或前,天數(shù)會少于0xff,用表day_code1[9],
//在九月后,天數(shù)大于0xff,用表day_code2[3]
//如輸入公歷日為8月10日,則公歷日離元旦天數(shù)為day_code1[8-1]+10-1
//如輸入公歷日為11月10日,則公歷日離元旦天數(shù)為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月為閏月,天數(shù)加1
temp4+=1;
}
//計(jì)算公歷日離當(dāng)年元旦的天數(shù)完成
//判斷公歷日在春節(jié)前還是春節(jié)后
if (temp4>=temp3){ //公歷日在春節(jié)后或就是春節(jié)當(dāng)日使用下面代碼進(jìn)行運(yùn)算
temp4-=temp3;
month=0x1;
month_p=0x1; //month_p為月份指向,公歷日在春節(jié)前或就是春節(jié)當(dāng)日month_p指向首月
flag2=get_moon_day(month_p,table_addr); //檢查該農(nóng)歷月為大小還是小月,大月返回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); //從數(shù)據(jù)表中取該年的閏月月份,如為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{ //公歷日在春節(jié)前使用下面代碼進(jìn)行運(yùn)算
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為月份指向,如果當(dāng)年有閏月,一年有十三個月,月指向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 ,運(yùn)算結(jié)束后,把數(shù)據(jù)轉(zhuǎn)換為BCD數(shù)據(jù)
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;
}
void nl()
{
Conversion(0,yy,mo,dd);
LCM_WriteDatOrCom(0,0x90);
LCM_WriteString("20");
LCM_WriteDatOrCom(1,year_moon/16+'0');
LCM_WriteDatOrCom(1,year_moon%16+'0');
LCM_WriteDatOrCom(1,'/');
LCM_WriteDatOrCom(1,month_moon/16+'0');
LCM_WriteDatOrCom(1,month_moon%16+'0');
LCM_WriteDatOrCom(1,'/');
LCM_WriteDatOrCom(1,day_moon/16+'0');
LCM_WriteDatOrCom(1,day_moon%16+'0');
}
/********************************************************************************/
void Keydone()
{
if (w == 0){ //正常走時
LCM_w_ss();//刷新 秒
}
else { //啟動調(diào)時
}
//------------------------------------------------------------------
if (KEY_3 == 0) // 設(shè)置時間
{
DelayM(20); //去抖
if(KEY_3 == 0 && w == 1) //當(dāng)是調(diào)時狀態(tài) 本鍵用于調(diào)整下一項(xiàng)
{
e++;
if (e >= 6 ){e = 0;}
Set_time(e);//調(diào)整
}
if(KEY_3 == 0 && w == 0) //當(dāng)是正常狀態(tài)時就進(jìn)入調(diào)時狀態(tài)
{
LCM_clr();//清屏
//yy=0xff;mo=0xff;dd=0xff;xq=0xff;hh=0xff;mm=0xff;ss=0xff; //各數(shù)據(jù)刷新
w=1; //進(jìn)入調(diào)時
/* LCM_WriteDatOrCom(0,0x9e);
LCM_WriteString(" [-]");
LCM_WriteDatOrCom(0,0x80);
LCM_WriteString("[Esc]");
LCM_WriteDatOrCom(0,0x85);
LCM_WriteString("[Next]");
LCM_WriteDatOrCom(0,0x98);
LCM_WriteString("[+]");*/
Set_time(e);//調(diào)整
}
while(KEY_3 == 0);//等待鍵松開
}
//------------------------------------------------------------------
if (KEY_1 == 0) // 當(dāng)在調(diào)時狀態(tài)時就退出調(diào)時
{
DelayM(20);
if(KEY_1 == 0 && w == 1){
w = 0; //退出調(diào)時
e = 0; //"下一項(xiàng)"計(jì)數(shù)器清0
}
if(KEY_1 == 0 && w == 0){
LCM_clr();//清屏
chn_disp(tab1);//顯示歡迎字
while(KEY_1 == 0);//等待鍵松開
}
LCM_clr();//清屏
//LCM_WriteString("[Dis] [Set]");
//yy=0xff;mo=0xff;dd=0xff;xq=0xff;hh=0xff;mm=0xff;ss=0xff; //各數(shù)據(jù)刷新
days(); //節(jié)日顯示
updata (); //刷新數(shù)據(jù)
LCM_w_mm();//刷新 分
nl();
while(KEY_1 == 0);//等待鍵松開
}
//------------------------------------------------------------------
if (KEY_2 == 0 && w == 1){ // 加減調(diào)整{
DelayM(20);
if(KEY_2 == 0 && w == 1){
Set_time(e);//調(diào)整
}
while(KEY_2 == 0);//等待鍵松開
}
//------------------------------------------------------------------
if (KEY_4 == 0 && w == 1){ // 加減調(diào)整
DelayM(20);
if(KEY_4 == 0 && w == 1){
Set_time(e);//調(diào)整
}
while(KEY_4 == 0);//等待鍵松開
}
//------------------------------------------------------------------
}
/*****************************************************************************/
//---主程序---//
main() {
e=0;
KEY_1 = 1;KEY_2 = 1;KEY_3 = 1;KEY_4 = 1;//初始鍵盤
yy=0xff;mo=0xff;dd=0xff;xq=0xff;hh=0xff;mm=0xff;ss=0xff; //各數(shù)據(jù)刷新
beep = 0;
DelayM(900);
beep = 1;
LCM_init();//初始化液晶顯示器
LCM_clr();//清屏
chn_disp(tab1);//顯示歡迎字
//----------|-------1-------|-------3-------|-------2-------|-------4-------|-----//標(biāo)尺
DelayM(3000); //顯示等留3秒
LCM_clr();//清屏
Init_1302();
while(1)
{
Keydone();
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -