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

📄 main_lsd.c

📁 用单片机的C语言实现的开机时间显示上次关机时间(存在看门狗里)
💻 C
📖 第 1 页 / 共 4 页
字号:
			{
				date2 = 9;
				date3--;
			}
			else
			    date2--;
		}	
	 
 		display( date3,8,0xB8,0x40,1 );
 		display( date2,8,0xB8,0x48,1 );
 		date4 = ( date3 << 4 ) | date2; //pass new date
 		
 		if ( Key == 4 )
 		    break;
 		else if ( Key == 3 )
 		    goto DAY0;
 		goto DATE0;
 		
   //set weekday
   DAY0: 
        
        display( 0x18,16,0xBA,0x60,0 ); //周
        Key = KeyboradScan(); 
        while ( ( Key ==0 ) | ( Key > 4 ) )
        {
        	Key = KeyboradScan();
    	}
    	delay( 10 );
 		if ( Key == 1 ) // add
 		{
 			if ( day3 == 6 )
 			    day3 = 0;
 			else
 			    day3++;
		}
		else if ( Key == 2 ) //substract
		{
			if ( day3== 0 )
			    day3 = 6;
			else
			    day3--;
		}
		
	 	 display( day3,16,0xB8,0x70,1 );
 	 		
 		if ( Key == 4 )
 		    break;
 		else if ( Key == 3 )
 		    goto HOUR0;
 		goto DAY0;
 		
 	//set weekday
    HOUR0: 
      
        display( 0x12,16,0xBA,0x60,0 ); //时
        Key = KeyboradScan();
        while ( ( Key ==0 ) | ( Key > 4 ) )
        {
        	Key = KeyboradScan();
    	}
    	delay( 10 );       
 		if ( Key == 1 ) // add
 		{
 			if ( hour3 == 2 )
 			{
 				if ( hour2 == 3 )
 				{
 					hour3 = 0;
 					hour2 = 0;
				}
				else
				    hour2++;
			}
			else if ( hour2 == 9 )
			{
				hour3++;
				hour2 = 0;
			}
			else
			    hour2++;
		}
		
		if ( Key == 2 ) //substract
		{
			if ( hour3 == 0 )
			{
				if ( hour2 == 0 )
				{
					hour3 = 2;
					hour2 = 3;
				}
				else
				    hour2--;
			}
			else if ( hour2 == 0 )
			{
				hour3--;
				hour2 = 9;
			}
			else
			    hour2--;
		}

 		display( hour3,8,0xBA,0x40,1 );
 		display( hour2,8,0xBA,0x48,1 );
 		hour4 = ( hour3 << 4 ) | hour2; //pass new hour
 		
 		if ( Key == 4 )
 		    break;
 		else if ( Key == 3 )
 		    goto MINUTE0;
 		goto HOUR0;
		
	//set minute
    MINUTE0: 
     
        display( 0x19,16,0xBA,0x60,0 ); //分
        Key = KeyboradScan();
        while ( ( Key ==0 ) | ( Key > 4 ) )
        {
        	Key = KeyboradScan();
    	} 
    	delay( 10 );
 		if ( Key == 1 ) // add
 		{
 			if ( minute3 == 5 )
 			{
 				if ( minute2 == 9 )
 				{
 					minute3 = 0;
 					minute2 = 0;
				}
				else
				    minute2++;
			}
			else if ( minute2 == 9 )
			{
				minute3++;
				minute2 = 0;
			}
			else
			    minute2++;
		}
		
		if ( Key == 2 ) //substract
		{
			if ( minute3 == 0 )
			{
				if ( minute2 == 0 )
				{
			    	minute3 = 5;
	    			minute2 = 9;					
				}
				else
				    minute2--;
			}
			else if ( minute2 == 0 )
			{
				minute3--;
				minute2 = 9;
			}
			else
			    minute2--;
		}	

 		display( minute3,8,0xBA,0x58,1 );
 		display( minute2,8,0xBA,0x60,1 );
 		minute4 = ( minute3 << 4 ) | minute2; //pass new day
 		
 		if ( Key == 4 )
 		    break;
 		else if ( Key == 3 )
 		    goto SECOND0;
 		goto MINUTE0;
 		
 	//set second
    SECOND0: 
      
        display( 0x20,16,0xBA,0x60,0 ); //秒
        Key = KeyboradScan();
        while ( ( Key ==0 ) | ( Key > 4 ) )
        {
        	Key = KeyboradScan();
    	} 
    	delay( 10 );
 		if ( Key == 1 ) // add
 		{
 			if ( second3 == 5 )
 			{
 				if ( second2 == 9 )
 				{
 					second3 = 0;
 					second2 = 0;
				}
				else
				    second2++;
			}
			else if ( second2 == 9 )
			{
				second3++;
				second2 = 0;
			}
			else
			    second2++;
		}
		
		if ( Key == 2 ) //substract
		{
			if ( second3 == 0 )
			{
				if ( second2 == 0 )
				{
			    	second3 = 5;
	    			second2 = 9;					
				}
				else
				    second2--;
			}
			else if ( second2 == 0 )
			{
				second3--;
				second2 = 9;
			}
			else
			    second2--;
		}		
 
 		display( second3,8,0xBA,0x70,1 );
 		display( second2,8,0xBA,0x78,1 );
 		second4 = ( second3 << 4 ) | second2; //pass new day
 		if ( Key == 4 )
 		    break;
 		else if ( Key == 3 )
 		    goto YEAR0;
 		goto SECOND0;
	}
}

/*****************************************************************
          The module of SettingCurrentTime function
*****************************************************************/

void SettingCurrentTime( )
{
 uchar Key;
 bit WriteInto8653;

 display( year1,8,0xB8,0x40,0 );
 display( year0,8,0xB8,0x48,0 );
 display( 0x07,16,0xB8,0x50,0 ); //年
    
 display( month1,8,0xB8,0x60,0 );
 display( month0,8,0xB8,0x68,0 );	
 display( 0x08,16,0xB8,0x70,0 ); //月  
         
 display( day1,8,0xB8,0x40,1 );
 display( day0,8,0xB8,0x48,1 );
 display( 0x00,16,0xB8,0x50,1 ); //日
    
 display( 0x09,16,0xB8,0x60,1 ); 
 display( date0,16,0xB8,0x70,1 ); //星期
    
 display(0x16,16,0xba,0x40,0); //设
 display(0x17,16,0xba,0x50,0); //置
 display(0x09,16,0xba,0x70,0); //空格
    
 display( hour1,8,0xBA,0x40,1 ); //hour
 display( hour0,8,0xBA,0x48,1 );
 display( 0x10,8,0xBA,0x50,1 ); // :
 display( minute1,8,0xBA,0x58,1 ); //minute
 display( minute0,8,0xBA,0x60,1 );
 display( 0x10,8,0xBA,0x68,1 ); // :
 display( second1,8,0xBA,0x70,1 ); //second
 display( second0,8,0xBA,0x78,1 );

 
 while (1)
    {
    //set year
    YEAR: 
        display( 0x07,16,0xBA,0x60,0 ); //年
        delay( 10 );
        Key = KeyboradScan(); 
        while ( ( Key ==0 ) | ( Key > 4 ) )
        {
        	Key = KeyboradScan();
    	}
    	delay( 10 );///////////////////////////////////
  
        if ( Key ==1 )   //add
        {
         	if ( year0 == 9 )
         	{
         	    year0 = 0;
         		if ( year1 == 9 )
         		    year1 = 0;
         		else
         		    year1++;
     		}
     		else
     		    year0++;
     	}
     	
     	else if ( Key == 2) //subtract
     	{
     		if ( year0 == 0 )
     		{
     			if ( year1 == 0 )
     			{
     				year1 = 9;
     				year0 = 9;
 				}
 				else
 				{
 					year1--;
 					year0 = 9;
				}
 			}
 			else
 			    year0--;
 		}
 		
 	 	display( year1,8,0xB8,0x40,0 );
 		display( year0,8,0xB8,0x48,0 );
 		year = ( year1 << 4 ) | year0; //pass new year
 		
 		if ( Key == 4 )
 		    break;
 		else if ( Key == 3 )
 		    goto MONTH;
 		goto YEAR;
 		 
   //set month    
   MONTH:
        display( 0x08,16,0xBA,0x60,0 ); //月       
        Key = KeyboradScan(); 
        while ( ( Key ==0 ) | ( Key > 4 ) )
        {
        	Key = KeyboradScan();
    	}
    	delay( 10 );
    
 		if ( Key == 1 ) // add
 		{
 			if ( month1 == 1 )
 			{
 				if ( month0 == 2 )
 				{
 					month1 = 0;
 					month0 = 1;
				}
				else
				    month0++;
			}
			else if ( month0 == 9 )
			{
				month1 = 1;
				month0 = 0;
			}
			else
			    month0++;			    
		} 
		
		else if ( Key == 2 ) //substract
		{
			if ( month1 == 0 )
			{
				if ( month0 == 1 )
				{
					month1 = 1;
					month0 = 2;
				}
		        else if ( month0 == 0 )
				{
					month1 = 1;
					month0 = 2;
				}				
				else
				    month0--;
			}
			else if ( month0 == 0 )
			{
				month1 = 0;
				month0 = 9;
			}
			else
			    month0--;
		}
		
	 	display( month1,8,0xB8,0x60,0 );
 		display( month0,8,0xB8,0x68,0 );
 		month = ( month1 << 4 ) | month0; //pass new month
 		
 		if ( Key == 4 )
 		    break;
 		else if ( Key == 3 )
 		    goto DAY;
 		goto MONTH;

   //set day
   DAY: 
        display( 0x00,16,0xBA,0x60,0 ); //日       
        Key = KeyboradScan(); 
        while ( ( Key ==0 ) | ( Key > 4 ) )
        {
        	Key = KeyboradScan();
    	}
    	delay( 10 );
 		if ( Key == 1 ) // add
 		{
 			if ( day1 == 3 )
 			{
 				if ( day0 == 1 )
 				{
 					day1 = 0;
 					day0 = 1;
				}
				else
				    day0++;
			}
			else if ( day0 == 9 )
			{
				day0 = 0;
				day1++;
			}
			else
			    day0++;
		}
		
		else if ( Key == 2 ) //substract
		{
			if ( day1 == 0 )
			{
				if ( day0 == 1 )
				{
					day1 = 3;
					day0 = 1;
				}
				else if ( day0 == 0 )
				{
					day1 = 3;
					day0 = 1;
				}
				else
				    day0--;
			}
			else if ( day0 == 0 )
			{
				day0 = 9;
				day1--;
			}
			else
			    day0--;
		}
		
 		display( day1,8,0xB8,0x40,1 );
 		display( day0,8,0xB8,0x48,1 );
 		day = ( day1 << 4 ) | date0; //pass new day
 		
 		if ( Key == 4 )
 		    break;
 		else if ( Key == 3 )
 		    goto DATE;
 		goto DAY;
 		
   //set weekday
   DATE: 
        display( 0x18,16,0xBA,0x60,0 ); //周
        Key = KeyboradScan(); 
        while ( ( Key ==0 ) | ( Key > 4 ) )
        {
        	Key = KeyboradScan();
    	}
    	delay( 10 );
 		if ( Key == 1 ) // add
 		{
 			if ( date0 == 6 )
 			    date0 = 0;
 			else
 			    date0++;
		}
		else if ( Key == 2 ) //substract
		{
			if ( date0== 0 )
			    date0 = 6;
			else
			    date0--;
		}
		
		display( date0,16,0xB8,0x70,1 );
 		date = date0 & 0x07; //pass new date
 		
 		if ( Key == 4 )
 		    break;
 		else if ( Key == 3 )
 		    goto HOUR;
 		goto DATE;
 		
    //set weekday
    HOUR:
        display( 0x12,16,0xBA,0x60,0 ); //时
        Key = KeyboradScan();
        while ( ( Key ==0 ) | ( Key > 4 ) )
        {
        	Key = KeyboradScan();
    	}
    	delay( 10 );       
 		if ( Key == 1 ) // add
 		{
 			if ( hour1 == 2 )
 			{
 				if ( hour0 == 3 )
 				{
 					hour1 = 0;
 					hour0 = 0;
				}
				else
				    hour0++;
			}
			else if ( hour0 == 9 )
			{
				hour1++;
				hour0 = 0;
			}
			else
			    hour0++;
		}
		
		if ( Key == 2 ) //substract
		{

⌨️ 快捷键说明

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