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

📄 system_alarm.c

📁 基于单片机的烟叶烘烤过程温湿度报警系统(含proteus原理图和c源程序):在LCD1602上实时显示时钟
💻 C
📖 第 1 页 / 共 3 页
字号:
	  {
	    delay_LCM(30);
		if(P1!=0xff)
		  {	
			xx=P1;
			switch(xx)
			{
				case 0xef:set_adj();break;               //11101111,P1.4
				case 0xdf:inc_key();break;               //11011111,P1.5
				case 0xbf:dec_key();break;               //10111111,P1.6
				default:break;
			}
		  }
		
	  }
  
}

/**************设定工作模式子函数****************/

void set_adj(void)
{
	delay_LCM(100);
	set++;
    if(set>2)set=0;
		
}

/****************按键加法子函数******************/

void inc_key(void)
{
	delay_LCM(100);
		
	switch(set)
	{
		case 1:hour++;   if(hour>=23)hour=23;    break;
		case 2:minite++; if(minite>=59)minite=59;break;
		default:break;
	}
		
}

/****************按键减法子函数*****************/

void dec_key(void)
{
	delay_LCM(100);
	
	switch(set)
	{
		case 1:hour--;  if(hour<=0)hour=0;    break;
		case 2:minite--;if(minite<=0)minite=0;break;
		default:break;
	}
		
}

/***************定时器t0初始化*******************/

void init_timer0(void)
{
	 TMOD=0x01;                                  //time0为定时器,方式1
     TH0=0x3c;                                   //预置计数初值
     TL0=0xb0;
     EA=1;   								
     ET0=1;          											
     TR0=1;          		
}

/***********定时器t0中断子函数**************/

void timer0(void) interrupt 1 using 0          //定时器0方式1,50ms中断一次
{
     TH0=0x3c;
     TL0=0xb0;
     mstcnt++;
     if(mstcnt>=20 )  {seconde++; mstcnt=0; }
	 if(seconde>=60)  {minite++;  seconde=0;}
	 if(minite>=60 )  {hour++; runtime++; minite=0; }
	 if(hour>=24   )  {hour=0;}
	 keyscan( );                               //按键扫描
}

/*****************系统报警子函数***************************/
/*查询ISD1420_RECLED管脚的放音结束标志EOC,瞬间的低电平*/
/*调试时基本正确,但是,会发生突发的不稳定的报警*/
/**********************************************************/

void playup(void)                          //语音提示温度上升过快
{    
	RED_ALARM=0;
	PLAYE_ADDR=0x11;
  	 _nop_();
	PLAYE_ADDR=0x10;
	delay_LCM(2000);                        //等待放音结束           
	RED_ALARM=1;
		
}

void playdown(void)	                       //语音提示温度上升过慢
{	                    	
	RED_ALARM=0;
	PLAYE_ADDR=0x21;
	_nop_();
	PLAYE_ADDR=0x20;
    delay_LCM(2000);                       //等待放音结束
	RED_ALARM=1;

}
	
void playconst(void)                      //语音提示恒温控制
{
	RED_ALARM=0;
	PLAYE_ADDR=0x31;
	_nop_();
	PLAYE_ADDR=0x30;
	delay_LCM(1000);                      //等待放音结束
	RED_ALARM=1;
		  
}

/*****************系统报警子函数****************************/
           

void system_alarm(void)
{
	switch(runtime)	
	{
		case 0x00:   if(temp==20)
						{
							delay_LCM(alarm_delay_time);              
							if(temp==20) playconst();    
					    }
                                                           break;
		case 0x01:   if(temp>21)
						{
							delay_LCM(alarm_delay_time);             
							if(temp>21) playup();    
					    }
                                                                				
				     if(temp<21)      
						{
							delay_LCM(alarm_delay_time);              
							if(temp<21) playdown();    
					    }
                                                           break;
 		case 0x02:   if(temp>22) 
			            {
							delay_LCM(alarm_delay_time);              
							if(temp>22) playup();    
					    }
                                                           
                     if(temp<22)
                                            
						{
							delay_LCM(alarm_delay_time);
							if(temp<22) playdown();    
						}
                                                           break;
		case 0x03:   if(temp>23)      
						{
							delay_LCM(alarm_delay_time);             
							if(temp>23) playup();    
					    }
				     if(temp<23)  
					   {
							delay_LCM(alarm_delay_time);             
						   if(temp<23) playdown();    
					    }									break;
		case 0x04:   if(temp>24)  
						{
							delay_LCM(alarm_delay_time);             
							if(temp>24)playup();    
					    }    
				     if(temp<24)
 						{						
							delay_LCM(alarm_delay_time);             
						   if(temp<24) playdown();    
					    }									break;    
		case 0x05:   if(temp>25) 
                       {
						     delay_LCM(alarm_delay_time);             
							if(temp>25)playup();    
					    }    
				     if(temp<25)  
						{						
							delay_LCM(alarm_delay_time);              
						   if(temp<25) playdown();    
					    }									break;   	   		   
		case 0x06:   if(temp>26) 
						{
							delay_LCM(alarm_delay_time);             
							if(temp>26) playup();    
					    }         
				     if(temp<26)     
				     	{						
						   delay_LCM(alarm_delay_time);             
						    if(temp<26) playdown();    
					    }									break; 
		case 0x07:   if(temp>27)  
						{
						    delay_LCM(alarm_delay_time);             
							if(temp>27)playup();    
					    }               
				     if(temp<27)   
				     	{						
						    delay_LCM(alarm_delay_time);             
						    if(temp<27) playdown();    
					    }									break; 
		case 0x08:   if(temp>28)   
						{
							delay_LCM(alarm_delay_time);              
							if(temp>28) playup();    
					    }          
				     if(temp<28)   
				     	{						
						   delay_LCM(alarm_delay_time);             
						    if(temp<28) playdown();    
					    }									break;
		case 0x09:   if(temp>29) 
						{
							delay_LCM(alarm_delay_time);             
							if(temp>29) playup();    
					    }             
				     if(temp<29)  
				     	{						
						    delay_LCM(alarm_delay_time);              
						    if(temp<29) playdown();    
					    }									break;   
		case 0x0a:   if(temp>30)  
						{
							delay_LCM(alarm_delay_time);             
							if(temp>30) playup();    
					    }                
				     if(temp<30) 
				     	{						
						    delay_LCM(alarm_delay_time);             
						    if(temp<30) playdown();    
					    }									break;   

		case 0x0b:   if(temp>31) 
						{
							delay_LCM(alarm_delay_time);              
							if(temp>31) playup();    
					    }                      
				     if(temp<31)  
				     	{						
						   delay_LCM(alarm_delay_time);              
						    if(temp<31) playdown();    
					    }									break;   
		case 0x0c:   if(temp>32) 
						{
							delay_LCM(alarm_delay_time);              
							if(temp>32) playup();    
					    }                
				     if(temp<32)      
				     	{						
						    delay_LCM(alarm_delay_time);              
						    if(temp<32) playdown();    
					    }									break; 
		case 0x0d:   if(temp>33) 
						{
							delay_LCM(alarm_delay_time);              
							if(temp>33) playup();    
					    }                
				     if(temp<33)      
				     	{						
						    delay_LCM(alarm_delay_time);             
						    if(temp<33) playdown();    
					    }		                            break;
		case 0x0e:   if(temp>34) 
						{
						    delay_LCM(alarm_delay_time);              
							if(temp>34) playup();    
					    }             
				     if(temp<34)
				     	{						
						    delay_LCM(alarm_delay_time);              
						    if(temp<33) playdown();    
					    }		                            break;
		case 0x0f:   if(temp>35)  
						{
							delay_LCM(alarm_delay_time);              
							if(temp>35) playup();    
					    }                   
				     if(temp<35)
						{						
						    delay_LCM(alarm_delay_time);              
						    if(temp<33) playdown();    
					    }		                             break;
		case 0x10:   if(temp>36)   
						{
							delay_LCM(alarm_delay_time);             
							if(temp>36) playup();    
					    }                      
				     if(temp==36)                            //恒温提示
						{					 	 
						    delay_LCM(alarm_delay_time);              
						    if(temp==36) playconst();    
					    }		                  
		                                               
				     if(temp<36)
						{						
						    delay_LCM(alarm_delay_time);              
						    if(temp<36) playdown();    
					    }		                             break;             
	   	case 0x12:   if(temp>36.5) 
						{
							delay_LCM(alarm_delay_time);              
							if(temp>36.5) playup();    
					    }                                
				     if(temp<36.5)  
						{						
						    delay_LCM(alarm_delay_time);              
						    if(temp<36.5) playdown();    
					    }	                                 break;
		case 0x13:   if(temp>37)   
						{
							delay_LCM(alarm_delay_time);              
							if(temp>37) playup();    
					    }                           
				     if(temp<37) 
						{						
						    delay_LCM(alarm_delay_time);              
						    if(temp<37) playdown();    
					    }		                              break;   
	    case 0x14:   if(temp>37.5)
						{
							delay_LCM(alarm_delay_time);              
							if(temp>37.5) playup();    
					    }                           
				     if(temp<37.5)  
						{						
						    delay_LCM(alarm_delay_time);              
						    if(temp<37.5) playdown();    
					    }		                              break; 
		case 0x15:   if(temp>38)   
						{
							delay_LCM(alarm_delay_time);              
							if(temp>38) playup();    
					    }                             
				     if(temp<38)
						{						
						   delay_LCM(alarm_delay_time);              
						    if(temp<38) playdown();    
					    }		                              break;      
		case 0x16:   if(temp>38.5)  
						{
							delay_LCM(alarm_delay_time);              
							if(temp>38.5) playup();    
					    }            
				     if(temp<38.5) 
						{						
						    delay_LCM(alarm_delay_time);              
						    if(temp<38.5) playdown();    
					    }		                              break;
		case 0x17:   if(temp>39)  
						{
							delay_LCM(alarm_delay_time);              
							if(temp>39) playup();    
					    }                       
				     if(temp<39) 
						{						
						    delay_LCM(alarm_delay_time);              
						    if(temp<39) playdown();    
					    }	                                   break;
		case 0x18:   if(temp>39.5) 
						{
							delay_LCM(alarm_delay_time);              
							if(temp>39.5) playup();    
					    }           
				     if(temp<39.5)
						{						
						    delay_LCM(alarm_delay_time);             

⌨️ 快捷键说明

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