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);}
}
}
void Conversion(bit c,uchar year,uchar month,uchar day)
{ //c=0 為21世紀(jì),c=1 為20世紀(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é)只會(huì)在公歷1月或2月
if(temp1==0x1){
temp3=temp2-1;
}
else{
temp3=temp2+0x1f-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則該年無(wú)閏月
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; //
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;
}
/*///////////農(nóng)歷轉(zhuǎn)換分界線 */
void festival()//顯示節(jié)日函數(shù)
{
if ( yue == 1 && ri == 1 ){ print(0x80," New Year's Day ");print(0x40,"Happy New Year!!"); }//1月
else if (month_moon== 0x01 && day_moon == 0x01 ){print(0x80,"Happy New Year!!");print(0x40,"Spring Festival!"); }
else if (month_moon== 0x01 && day_moon == 0x15 ){print(0x80," yuan xiao jie: ");print(0x40,"Lantern Festival"); }//元宵節(jié)
else if ( yue == 2 && ri == 2 ){ print(0x80," World Wetlands ");print(0x40," Day "); }//2月
else if ( yue == 2 && ri == 14 ){ print(0x80," Today is: ");print(0x40,"Valentine's Day!"); }
else if ( yue == 3 && ri == 8 ){ print(0x80," International ");print(0x40," Women' Day "); }
else if ( yue == 3 && ri == 12 ){ print(0x80," Today is: ");print(0x40,"China Arbor Day "); }
//else if ( yue == 3 && ri == 14 ){ print(0x80," Today is: ");print(0x40," White Day "); }
else if ( yue == 3 && ri == 15 ){ print(0x80," World Consumer ");print(0x40," Right Day "); }
else if ( yue == 3 && ri == 17 ){ print(0x80," International ");print(0x40," sailing day "); }
else if ( yue == 3 && ri == 21 ){ print(0x80," Today is: ");print(0x40,"World Forest Day"); }
else if ( yue == 3 && ri == 22 ){ print(0x80," Today is: ");print(0x40,"World Water Day "); }
//if ( yue == 3 && ri == 23 ){ print(0x80,"World Meteorolo-");print(0x40," gical Day "); }
//if ( yue == 3 && ri == 24 ){ print(0x80,"World Tubercul-");print(0x40," osis Day "); }
else if ( yue == 4 && ri == 1 ){ print(0x80," Today is: ");print(0x40,"April Fools' Day"); }//4
else if ( yue == 4 && ri == 5 ){ print(0x80," Ching Ming ");print(0x40," Festival "); }
else if ( yue == 4 && ri == 7 ){ print(0x80," Today is: ");print(0x40,"World Health Day"); }
else if ( yue == 4 && ri == 8 ){ print(0x80," Today is: ");print(0x40," Easter Day "); }
else if (month_moon== 0x05 && day_moon == 0x05 ){print(0x80,"the Dragon-Boat ");print(0x40," Festival "); }
else if ( yue == 5 && ri == 1 ){ print(0x80," International ");print(0x40," Labour Day "); }//5
else if ( yue == 5 && ri == 4 ){ print(0x80," Chinese Youth ");print(0x40," Day "); }
else if ( yue == 5 && ri == 8 ){ print(0x80,"World Red-Cross ");print(0x40," Day "); }
else if ( yue == 5 && ri == 12 ){ print(0x80," International ");print(0x40," Nurse Day "); }
else if ( yue == 5 && ri == 5 ){ print(0x80," Mother's Day ");print(0x40," is coming! "); }
else if ( yue == 5 && ri == 15 ){ print(0x80," International ");print(0x40," Family Day "); }
else if ( yue == 5 && ri == 31 ){ print(0x80,"World No-Smoking");print(0x40," Day "); }
else if ( yue == 6 && ri == 1 ){ print(0x80," International ");print(0x40," Children's Day "); }//6
else if ( yue == 6 && ri == 5 ){ print(0x80," International ");print(0x40,"Environment Day "); }
else if ( yue == 6 && ri == 26 ){ print(0x80," International ");print(0x40,"Against Drug Day"); }
//else if ( yue == 6 && ri == 6 ){ print(0x80," National Eyes "); print(0x40," Caring Day "); }
else if ( yue == 6 && ri == 13 ){ print(0x80," Father's Day ");print(0x40," is coming! "); }
else if ( yue == 7 && ri == 1 ){ print(0x80," The return of ");print(0x40," Hong Kong Day "); }//7
else if ( yue == 7 && ri == 7 ){ print(0x80," Anti-Japanese ");print(0x40,"War memorial day"); }
else if ( yue == 7 && ri == 11 ){ print(0x80,"World Population");print(0x40," Day "); }
else if (month_moon== 0x08 && day_moon == 0x15 ){ print(0x80," the Mid-Autumn ");print(0x40," Festival "); }
else if ( yue == 8 && ri == 1 ){ print(0x80," Today is: ");print(0x40," the Army Day "); }//8
else if ( yue == 8 && ri == 8 ){ print(0x80," Chinese man ");print(0x40," Festival "); }
else if ( yue == 8 && ri == 15 ){ print(0x80," The victory of ");print(0x40," war anniversary"); }
else if (month_moon== 0x09 && day_moon == 0x09 ){ print(0x80,"the Double Ninth");print(0x40," Festival "); }
else if ( yue == 9 && ri == 10 ){ print(0x80," Today is: ");print(0x40," Teacher's Day "); }//9
//else if ( yue == 9 && ri == 20 ){ print(0x80," International ");print(0x40,"Teeth-loving Day"); }
else if ( yue == 9 && ri == 27 ){ print(0x80," World Tourism ");print(0x40," Day "); }
else if ( yue == 10 && ri == 1 ){ print(0x40," Today is: ");print(0x40," National Day "); }//10
else if ( yue == 10 && ri == 4 ){ print(0x80," Today is: ");print(0x40,"World Animal Day"); }
else if ( yue == 10 && ri == 24 ){ print(0x80," United Nations ");print(0x40," Day "); }
else if ( yue == 11 && ri == 10 ){ print(0x80," Today is: ");print(0x40,"World Youth Day "); }//11
else if ( yue == 11 && ri == 11 ){ print(0x80,"Today is 1,1,1..");print(0x40," One's Day "); }//光棍節(jié)
else if ( yue == 11 && ri == 17 ){ print(0x80," The student ");print(0x40," section "); }
else if (month_moon== 0x12 && day_moon == 0x08 ){ print(0x80,"the laba Rice P-");print(0x40,"orridge Festival"); }
else if (month_moon== 0x12 && day_moon == 0x15 ){ print(0x80," guo xiao nian ");print(0x40," a lunar year "); }
//if (month_moon== 0x12 && day_moon == 0x29 ){ print(" 臘月二十九 "); }
else if (month_moon== 0x12 && day_moon == 0x30 ){ print(0x80," Today is: ");print(0x40," New Year's Eve "); }
else if ( yue == 12 && ri == 1 ){ print(0x80," Today is: ");print(0x40," World AIDS Day "); }//12
//if ( yue == 12 && ri == 23 ){ print(" 明晚平安夜 "); }
else if ( yue == 12 && ri == 24 ){print(0x80,"Tonight is "); print(0x40,"The Silent Night"); }
else if ( yue == 12 && ri == 25 ){print(0x80,"Merry Christmas!"); print(0x40," Christmas Day "); }
else if ( yue == 12 && ri == 31 ){ print(0x80," The last day ");print(0x40," of the year "); }
else{
print(0x40," ...(*^_^*)... ");//顯示笑臉。。。
//print(0x40," ...0(n_n)0... ");
print(0x80,"Have a Good Day!");
}
}
if(15<=miao)/*當(dāng)秒大于15時(shí)才顯示*/
{
if(((miao/10==1)||(miao/10==3))&&(miao%10>=5))
{
switch(flag/100)//取出溫度的十位數(shù)
{
case 0:print(0x80,"Pretty cold now!");
break;
case 1:print(0x80,"little cold now!");
break;
case 2:print(0x80,"It is warm now. ");
break;
case 3:print(0x80,"It's hot !!! ");
break;
case 4:print(0x80,"Very very hot!!!");
break;
case 5:print(0x80,"Very very hot!!!");
break;
case 6:print(0x80,"Very very hot!!!");
break;
}
print(0x80,"It is warm now. ");
print(0x40," : : ");
writetemp(9,flag);//顯示溫度,第二行顯示
writetime(6,miao);//顯示出秒
writetime(3,fen);//顯示出分
writetime(0,shi);//顯示出時(shí),第二行第一個(gè)開始
}
if(((miao/10==2)||(miao/10==4))&&(miao%10>=5))/*25-30 45-50*/
{
if((5<=shi)&&(shi<=11)) flagT=1;//5-11時(shí)為早上
if((11<shi)&&(shi<=14)) flagT=2;//11-14為中午
if((14<shi)&&(shi<=18)) flagT=3;//14-18為下午
if((18<shi)||(shi<5)) flagT=4;//18-24或者0-5為晚上
switch(flagT)//分段時(shí)間
{
case 1:print(0x80," Good Morning! ");
break;
case 2:print(0x80," Good Noon! ");
break;
case 3:print(0x80,"Good afternoon! ");
break;
case 4:print(0x80," Good night! ");
break;
}
print(0x40," : : ");
writetemp(9,flag);//顯示溫度,第二行顯示
writetime(6,miao);//顯示出秒
writetime(3,fen);//顯示出分
writetime(0,shi);//顯示出時(shí),第二行第一個(gè)開始
}
if(((30<=miao)&&(miao<35))||((50<=miao)&&(miao<54)))//30-35 50-54
{//else改為范圍
festival();//選擇顯示節(jié)日
}
}
}
void timer1() interrupt 3//任務(wù):計(jì)時(shí)用作報(bào)時(shí)
{
TH1=(65536-50000)/256;//中斷后重新賦初值
TL1=(65536-50000)%256;
count++;//計(jì)算時(shí)間
if(alarmflag==1)//設(shè)置鍵按下才有效
{
if(fen==0 && miao<4)
{
count++;
ledcount=count/10;//分開時(shí)間段
switch(ledcount)
{
case 0:Gled=0;Yled=1;break;//從零開始
case 1:Gled=1;Yled=0;break;
case 2:Gled=0;Yled=1;break;
case 3:Gled=1;Yled=0;break;
case 4:Gled=0;Yled=0;break;
case 5:Gled=1;Yled=1;break;
case 6:Gled=0;Yled=0;break;
case 7:Gled=0;Yled=0;count=0;break;//在這里面清零
}
}
else if(fen==30 && miao<2)
{
Gled=0;
Yled=0;
}
else {
Gled=1;
Yled=1;
}
}
} 作者: zl2168 時(shí)間: 2016-10-22 10:09
這種冗長(zhǎng)而沒頭沒腦的程序,哪位“大神”有耐心給予“指教”?你以為“大神”真的是大神么?你以為“大神”都坐在那里很空么?