⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 多功能电子时钟 c程序.c

📁 ourdev_479323
💻 C
📖 第 1 页 / 共 5 页
字号:
                    0x0A,0x4d,0x4C,    //2097
                    0x0d,0x15,0x41,    //2098
                    0x2d,0x92,0xB5,    //2099
};
///月份数据表
code uchar date_code1[9]={0x0,0x1f,0x3b,0x5a,0x78,0x97,0xb5,0xd4,0xf3};
code uint date_code2[3]={0x111,0x130,0x14e};

bit c_moon;
data uchar year_moon,month_moon,date_moon,week;

bit get_moon_date(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 date)           //
{
    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=date/16;
    temp2=date%16;
    date=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; 

    if(temp1==0x1){  
        temp3=temp2-1;  
    }  
    else{
        temp3=temp2+0x1f-1;        
    }

    if (month<10){ 
        temp4=date_code1[month-1]+date-1;
    }
    else{
        temp4=date_code2[month-10]+date-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_date(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_date(month_p,table_addr);
            if(flag2==0)temp1=0x1d;
            else temp1=0x1e;
        }
        date=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; //

        flag_y=0;
        flag2=get_moon_date(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_date(month_p,table_addr);
            if(flag2==0)temp1=0x1d;
            else temp1=0x1e;
         }
        date=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=date/10;
    temp1=_crol_(temp1,4);
    temp2=date%10;
    date_moon=temp1|temp2;
}

void nl()                                               //
{
	unsigned char   yy1,yy2;
	if(cen==0x19)  {cen_m=1;}
	if(cen==0x20)  {cen_m=0;}
	Conversion(cen_m,year,month,date);
	lcm_w_test(0,0x85);
	lcm_w_test(1,month_moon/16+'0');
	lcm_w_test(1,month_moon%16+'0');
	lcm_w_test(1,'-');
	lcm_w_test(1,date_moon/16+'0');
	lcm_w_test(1,date_moon%16+'0');
	yy1=(year_moon/16)*10+year_moon%16;
	yy2=yy1%12;
	switch(yy2)
	{
	  case 0: lcm_w_test(0,0x83);lcm_w_word("龙");
	          break;
	  case 1: lcm_w_test(0,0x83);lcm_w_word("蛇");
	          break;
	  case 2: lcm_w_test(0,0x83);lcm_w_word("马");
	          break;
	  case 3: lcm_w_test(0,0x83);lcm_w_word("羊");
	          break;
	  case 4: lcm_w_test(0,0x83);lcm_w_word("猴");
	          break;
	  case 5: lcm_w_test(0,0x83);lcm_w_word("鸡");
	          break;
	  case 6: lcm_w_test(0,0x83);lcm_w_word("狗");
	          break;
	  case 7: lcm_w_test(0,0x83);lcm_w_word("猪");
	          break;
	  case 8: lcm_w_test(0,0x83);lcm_w_word("鼠");
	          break;
	  case 9: lcm_w_test(0,0x83);lcm_w_word("牛");
	          break;
	  case 10: lcm_w_test(0,0x83);lcm_w_word("虎");
	          break;
	  case 11: lcm_w_test(0,0x83);lcm_w_word("兔");
	          break;
	}
}

/*主程序---------------------------------------------------------------------*/
main() 
{
	uchar e=0,r=0,t=0;
	K1=1;K2=1;K3=1;K4=1;                //
	rt=0;
	rr=0;
	InitialSound();                      //初始音乐
	beep=1;
	LCM_BLA=1;                          //背光灯开
	bt=1;
	ds_int();                         //初始化DS12CR887
	lcm_init();                       //初始化液晶显示器
	lcm_clr();                       //清屏
	welcome();                       //显示欢迎信息
	DelayM(3000);                     //显示停留3秒
	lcm_clr();
	welcome2();
	Play(Music_happy,0,3,300);           //
	beep=1;                          //
	DelayM(421);
	lcm_clr();                        //
	Disp_Img(GN);               //调入一幅图画
	DelayM(4210);
	lcm_clr();                    //清屏
	while(1)                         //
	{
		if (w == 0 && r ==0 )	//正常走时
		{   
			lcm_w_year();   //显示年
			lcm_w_month();	//显示月 
			lcm_w_date();	//显示日
			lcm_w_day();	//显示星期
			lcm_w_hour();	//显示时
			lcm_w_min();	//显示分
			lcm_w_sec();	//显示秒
			days();          //
			BLA_delay();     //
			ring();         //
			if(hour==0x6 && min==0x30 && sec==0x0) {lcm_clr();Disp_Img(GM);DelayM(4210);lcm_clr();}  //
			if(hour==0x0 && min==0x0 && sec==0x0)  {lcm_clr();Disp_Img(GN);DelayM(4210);lcm_clr();}  //
		}
		else {;}//否则启动调时或调铃
	
		if (K1 == 0) // 设置时间
	    {
	    	DelayM(20);	   //按键消抖
			if(K1 == 0 && w == 1 && r ==0)  //当是调时状态 本键用于调整下一项
			{
				e++;
				if (e >= 7 )
				{
					e = 0;  
				}
				Set_time(e);//调整				
			}			
			if(K1 == 0 && w == 0 && r ==0)  //当是正常状态时就进入调时状态
			{
				lcm_clr();//清屏
				w=1;	  //进入调时				
				Set_time(e);//调整
			}
			if(K1 == 0 && w == 0 && r ==1)  //当是正常状态时就进入调时状态
			{
				w = 0;//清屏
				e = 0;				
				r = 0;
				t = 0;
				lcm_clr();
			}
	       	while(K1 == 0);//等待键松开 
		}
	
		if (K2 == 0) // 当在调时状态时就退出调时
	    {
			DelayM(20);//按键消抖
			if(K2 == 0 && w == 0 && r ==1) 
			{				
				t++;
				if (t >= 8 )
				{
					t = 0;  
				}
                Set_ring(t);
			}
			if(K2 == 0 && w == 0 && r ==0)
			{				
				lcm_clr();//清屏
				r=1;	  //进入调时				
				Set_ring(t);//调整									
			}
			if(K2 == 0 && w == 1 && r ==0)
			{				
				w = 0;	  //退出调时
				e = 0;		//"下一项"计数器清0
				r = 0;
				t = 0;
				lcm_clr();
				lcm_w_year();   //显示年
				lcm_w_month();	//显示月 
				lcm_w_date();	//显示日
				lcm_w_day();	//显示星期
				lcm_w_hour();	//显示时
				lcm_w_min();	//显示分
				lcm_w_sec();	//显示秒
				BLA_delay();
			}
			while(K2 == 0);//等待键松开  
		}
	
		if (K3 == 0)//加调整
		{ 
	   		DelayM(20);//按键消抖
	   		if(K3 == 0 && w == 1 && r ==0)
			{				
				Set_time(e);//调整
			}
	   		if(K3 == 0 && w == 0 && r ==1)
			{				
				Set_ring(t);//调整
			}
	   		while(K3 == 0);//等待键松开
		}
	
		if (K4 == 0) //减调整
		{       	
	   		DelayM(20);//按键消抖
	   		if(K4 == 0 && w == 1 && r ==0)
			{				
				Set_time(e);//调整
			}
	   		if(K4 == 0 && w == 0 && r ==1)
			{				
				Set_ring(t);//调整
			}
	   		while(K4 == 0);//等待键松开
		} 
	}	
}
//调试
//走时,设时,温度,背光,光灯自动熄灭,闹铃设置,闹铃,生日提醒
//还差农历,生日歌
//全部完成

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -