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

📄 retime.c

📁 倒记时显示牌
💻 C
📖 第 1 页 / 共 3 页
字号:
                     if(!fifth_sure)i=51;
        		}
    		}
    	}
    }
}
/*******************************

倒计时位闪烁子程序

*******************************/
void retime_flash(void)
{
    unsigned char i;
    if(sixth_sure)
    {
        retime_ustore=retime_unit;
        retime_dstore=retime_decade;
        retime_hstore=retime_hundred;
        retime_tstore=retime_thousand;
        while(sixth_sure)
    	{
             for(i=0;i<18;i++)
        	 {
                retime_unit=10;
                retime_decade=10;
                retime_hundred=10;
                retime_thousand=10;
                day_unit=day_unitstore;
                day_decade=day_decastore;
                display();
                kbscan();
                if(!sixth_sure)i=51;
        	 }
             if(sixth_sure)
        	 {
                for(i=0;i<18;i++)
        		{
                   retime_unit=retime_ustore;
                   retime_decade=retime_dstore;
                   retime_hundred=retime_hstore;
                   retime_thousand=retime_tstore;
                   day_unit=day_unitstore;
                   day_decade=day_decastore;
                   display();
                   kbscan();
                   if(!sixth_sure)i=51;
        		}
        	 }
    	}
        if(seventh_sure)                 //第八次确认键按下,启动定时器,将各位的数据全部弹出,时钟正常显示
    	{
            seventh_sure=0;
            fen_ge=fenzhong_ge;					
            fen_shi=fenzhong_shi;
            shi_ge=xiaoshi_ge;  
            shi_shi=xiaoshi_shi;
            year_unit=year_unitstore;
            year_decade=year_decastore;
            year_hundred=year_hundstore;
            year_thousand=year_thoustore;
            month_unit=month_unitstore;
            month_decade=month_decastore;
            day_unit=day_unitstore;
            day_decade=day_decastore;
            retime_unit=retime_ustore;
            retime_decade=retime_dstore;
            retime_hundred=retime_hstore;
            retime_thousand=retime_tstore;
            TR0=1;					
    	}
    }
}
/*******************************

小时位闪烁子程序

*******************************/
void hour_flash(void)
{   
    unsigned char i;
    if(first_sure)
    {	
        TR0=0;                //关定时器,进入闪烁 
        xiaoshi_ge=shi_ge;    //保存时个位显示的数据
        xiaoshi_shi=shi_shi;  //保存时十位显示的数据
        while(first_sure)     //第一次确认键按下,在小时位闪烁
    	{	
            for(i=0;i<18;i++) //小时位不显示,其它位显示
        	{	
                shi_ge=10;
                shi_shi=10;
                display();
                kbscan();
                if(!first_sure)i=51;
    		}
            if(first_sure)
    		{
                for(i=0;i<18;i++)//小时位和其它位都显示
        		{	
                    shi_ge=xiaoshi_ge;
                    shi_shi=xiaoshi_shi;
                	display();
                	kbscan();
                    if(!first_sure)i=51;
        		}
        	}  
    	}
    }
}
/******************************

分钟位闪烁子程序

*******************************/
void min_flash(void)    
{   
    unsigned char i;
    if(second_sure)
    {	
            fenzhong_ge=fen_ge;     //保存分个位显示的数据
            fenzhong_shi=fen_shi;   //保存分十位显示的数据
            while(second_sure)      //第二次确认键按下,在分钟位闪烁
    		{
                for(i=0;i<18;i++)//分钟位不显示,其它位都显示
        		{
                	fen_ge=10;
                	fen_shi=10;
                    shi_ge=xiaoshi_ge;  //送小时个位的原始数据,避免调到小时个位不显示时的数据
                    shi_shi=xiaoshi_shi;//送小时十位的原始数据,避免调到小时十位不显示时的数据
                	display();
                	kbscan();
                    if(!second_sure)i=51;
        		}
                if(second_sure)
        		{
                    for(i=0;i<18;i++)      //分钟位和其它位都显示
        			{
                        fen_ge=fenzhong_ge;
                        fen_shi=fenzhong_shi;
                        shi_ge=xiaoshi_ge;  //送小时个位的原始数据,避免调到小时个位不显示时的数据
                        shi_shi=xiaoshi_shi;//送小时十位的原始数据,避免调到小时十位不显示时的数据
                		display();
                		kbscan();
                        if(!second_sure)i=51;
        			}
        		}	
    		}
    }
}
/*******************************

年位组合子程序

********************************/
void year_joint(void)
{   
    year_unitstore2=year_unitstore;       //保存年各位数据
    year_decastore2=year_decastore;
    year_hundstore2=year_hundstore;
    year_thoustore2=year_thoustore;
    year_jointed=year_unitstore;
    year_decastore=year_decastore<<4;
    year_decastore=year_decastore&0xf0;
    year_jointed=year_jointed+year_decastore;       //得到年的抵8位
    year_jointed=year_jointed<<8;               //将年的低8和高8互换
    year_jointed=year_jointed+year_hundstore;
    year_thoustore=year_thoustore<<4;
    year_thoustore=year_thoustore&0xf0;
    year_jointed=year_jointed+year_thoustore;   //得到年,需将其进行高8与低8互换
    year_help1=year_jointed&0xff00;
    year_help1=year_help1>>8;               	//得到年低8位
    year_help2=year_jointed&0x00ff;
    year_help2=year_help2<<8;               	//得到年高8位
    year_jointed=year_help1+year_help2;         // 得到年位
    year_unitstore=year_unitstore2;
    year_decastore=year_decastore2;
    year_hundstore=year_hundstore2;
    year_thoustore=year_thoustore2;             //弹出年各位数据
}

/*******************************

定时器0中断子程序

********************************/
void timer0(void) interrupt 1 using 1
{
    TH0=0x3c;
    TL0=0xb0;
    if((++time_num)==20)
    	{
            time_num=0;
            ++miao_ge;   //定时一秒到,秒个位加一
    	}
}   		
/******************************
 
 当秒个位加到9时进一,
 当分个位加到6时进一
 ……
 当年到9999年时全部清零.

*******************************/    
void dis_dingshi(void)  
{   
    if(miao_ge==10)    			
    {
        miao_ge=0;
        if((++miao_shi)==6)		
    	{	
            miao_shi=0;
            if((++fen_ge)==10)		
    		{
                fen_ge=0;
                if((++fen_shi)==6)
        		{
                	fen_shi=0;
                    if((--shi_num)!=0)
        			{
                        if((++shi_ge)==10)
        				{
                			shi_ge=0;
                    		++shi_shi;
        				}
        			}
                    else if(shi_num==0)
        			{
                    	shi_num=24;
                		shi_ge=0;
                		shi_shi=0;
                            if(retime_unit==0&retime_decade==0&retime_hundred==0&retime_thousand==0)//倒计时减一
        					{
            					;
        					}
            				else 
        					{
                                 if((--retime_unit)==10)
            					 {
                            	  	retime_unit=0;
                                    if((--retime_decade)==10)
            						{
                            		 	retime_decade=0;
                                    	if((--retime_hundred)==10)
            							{
                                		 	retime_hundred=0;
                                        	if((--retime_thousand)==10)
            								{
                                			 	retime_thousand=0;
            								}
            							}
            						}
            					 }
        					}

                        if((month_unit|0xfe)==0xff)     //是奇数月,日为31天
        				{	
                                    if((--day_numj)!=0)			//31天没到
                				    {	
                                		if((++day_unit)==10)
            							{
                         					day_unit=0;
                        					++day_decade;
            							}
            						}
                                    else if(day_numj==0)			//31天到了
            						{
                               			day_numj=31;
                        	   			day_unit=1;
                               			day_decade=0;
            							
                                        if((--month_num)!=0)		 //12个月没到
                			   			{	
                                    			if((++month_unit)==10)
                			   					{
                            						month_unit=0;
                            						++month_decade;
                			   					}
            							}
                                        else if(month_num==0)	 //12个月到了
            							{
                        					month_num=12;
                        					month_unit=1;
                            				month_decade=0;
                                            if((++year_unit)==10)	//年个位是否到9
            								{
                            		 	 		year_unit=0;
                                    	 		if((++year_decade)==10)
                						 		{
                            			 			year_decade=0;
                                        			if((++year_hundred)==10)
                									{
                                			 			year_hundred=0;
                                                        if((++year_thousand)==10)year_thousand=0;
                									}
                						 		}
            								}
            							}
            						}
        				}
                        else if((month_unit|0xfe)!=0xff)    //是偶数月,日为30天
        				{
                            if((--day_numo)!=0)			//30天没到
            				{	
                            	if((++day_unit)==10)
            					{
                         			day_unit=0;
                        			++day_decade;
            					}
        					}
                            else if(day_numo==0)			//30天到了
        					{
                               	if(month_unit==2)
            					{	
                            		if(day_numoo==28)
            						{	
                        				day_numo=28;
                        				day_unit=1;
                        				day_decade=0;
            						}
                                	else if(day_numoo==29)
            						{
                        				day_numo=29;
                        				day_unit=1;
                        				day_decade=0;
            						}
            					}			
                				else 
            					{	
                        			day_numj=30;
                        	   		day_unit=1;
                               		day_decade=0;
            					}
                               if((--month_num)!=0)		 //12个月没到
            				   {	
                                	if((++month_unit)==10)
                			   		{
                        				month_unit=0;
                            			++month_decade;
                			   		}
            					}
                                else if(month_num==0)	 //12个月到了
            					{
                        			month_num=12;
                        			month_unit=1;
                        			month_decade=0;
                                    if((++year_unit)==10)	//年个位是否到9
            						{
                        			 	 year_unit=0;
                                    	 if((++year_decade)==10)
            							 {
                            			 	year_decade=0;

                                    		if((++year_hundred)==10)
            								{
                            				 	year_hundred=0;
                                                if((++year_thousand)==10)year_thousand=0;
            								}
            							 }
            						}
            					}
        					}
        				}
        			}
        		}
    		}
    	}
    }
}   
/*************主程序**************/
void main(void)
{  
    TMOD=0x01;
    TH0=0x3c;
    TL0=0xb0;
    EA=1;
    ET0=1;
    TR0=1;
    while(1)
    {   
        kbscan();       //调按键扫描
        display();      //六个数码管显示
        hour_flash();   //调小时位闪烁
        min_flash();    //调分钟位闪烁
        year_flash();   //年闪烁
        month_flash();  //月闪烁
        day_flash();    //日闪烁
        retime_flash();
        dis_dingshi();  //到一秒加一,到一分加一,到一小时加一,到24点清零
    }
}

⌨️ 快捷键说明

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