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

📄 temperature.c

📁 STM32实现定时加热
💻 C
字号:
#include <stm32f10x_lib.h>
#include "sys.h"
#include "usart.h"		
#include "delay.h"	
#include "led.h" 
#include "key.h"
#include "exti.h"
#include "timer.h"
#include "lcd.h"	   
#include "rtc.h"
#include "wkup.h"
#include "remote.h"
#include "ds18b20.h"
#include "switch.h"
#include "temperature.h"
#include"settimer.h"
int maxtemp1=100; //必须在.C文件中定义,否则会出现Symbol flagu multiply defined (by uart0.o and main.o)错误
int mintemp1=0;//全局变量设置,初始化最大温度和最小温度
int set_timer_temp[10];
int midtemp=50;
int tempkeep=0;
int  judge()
{
	u8 key;
	while(1)
		{
			if(Remote_Rdy)
				{
				   	key=Remote_Process();
					if(key==226)  return 1;
				   	else return 0;
				}
		}
}
//功能:红外输入
//范围:输入0-9
// i代表需要输入的数据位数,全局变量set_timer_temp[]存储
//函数具备确认和删除功能
//确认功能:ALIENTEK  确认  其他除删除键无效
//可实现实时删除修改数据
void get_remote(int i)
{	
    
    u8	key;
    int j=0;
	Remote_Rdy=0;
	LCD_Fill(0,304,240,320,WHITE);//
	LCD_ShowString(8,304, "input:");
	while(1)
	{
		 	if(Remote_Rdy)
		{
			key=Remote_Process();
			//LCD_ShowNum(86,130,key,3,16);//显示键值
		//	 printf("key==%d\n\n",key);
		//	LCD_ShowNum(186,130,Remote_Cnt,3,16);//显示按键次数	
		  
			switch(key)
			{
			
				case 56:
				 if(j<i)
				 {
					LCD_ShowString(60+j*8,304, "8     ");
				//	 printf("8 \n\n");
				set_timer_temp[j]=8;j++;
				}
					break;	
				case 104:
				 if(j<i)
		  		{
					LCD_ShowString(60+j*8,304, "1     ");
					 // printf("1\n\n");
					 set_timer_temp[j]=1; j++;
			   }
					break;
				case 152:
				 if(j<i)
				   {
					LCD_ShowString(60+j*8,304, "2     ");
					 // printf("2 \n\n");
					 set_timer_temp[j]=2; j++;
					 }
					break;
				case 176:
				if(j<i)
				{
					LCD_ShowString(60+j*8,304, "3     ");
					// printf("3 \n\n");
					set_timer_temp[j]=3; j++;
				}
					break;
				case 48:
				if(j<i)
				{
					LCD_ShowString(60+j*8,304, "4     ");
				  // printf("4  \n\n");
				  set_timer_temp[j]=4; j++;
				  }
					break;
				case 24:
				 if(j<i)
				 {
					LCD_ShowString(60+j*8,304, "5     ");
					   // printf("5   \n\n");
					   set_timer_temp[j]=5; j++;
			   }
					break;
				case 122:
					  if(j<i)
		        {
					LCD_ShowString(60+j*8,304, "6     ");
                //	printf("6    \n\n");
				set_timer_temp[j]=6; j++;
				}
					break;
				case 16:
						 if(j<i)
		                {
						LCD_ShowString(60+j*8,304, "7     ");
						// printf("7  \n\n");
						set_timer_temp[j]=7; j++;
						 }
					break;
				case 90:
				 	  if(j<i)
		  			{
					LCD_ShowString(60+j*8,304, "9     ");
				//	printf("9  \n\n");
			    	set_timer_temp[j]=9; j++;
					 }
					break;
				case 66:
					   if(j<i)
		             {
					 LCD_ShowString(60+j*8,304, "0     ");
				      set_timer_temp[j]=0; j++;
				   	  }
					break;
				case 82:
					//LCD_ShowString(86,150, "DELETE");
					//printf("DELETE    \n\n");
				//	LCD_ShowString(20,304, "Delete:");
					//LCD_ShowNum(80,304,set_timer_temp[j-1],1,16);
					 if(j>0) 
					 {
					  set_timer_temp[j-1]=0; j--;
					  LCD_Fill(60+j*8,304,240,320,WHITE);
					  }
					break;	

			//	default: LCD_ShowString(60,168, "unuseful operation!");break; //执行了但是意义不大
			     }
			LCD_Fill(60+j*8,304,240,320,WHITE);//
			if(j>=i) 
			{  
			
		    	 LCD_ShowString(120,304,"please sure!");
				 if(judge()==1)	break;
			}
		}		
	}
}
//功能:1,设置最高和最低温度  2,显示温度
//红外遥控实现
void set_temperature()
{	 
     u8 key;
    short temp;
	int sum;
    Remote_Rdy=0;
	LCD_Clear(WHITE);	
    while(1)
	{
	      temp=DS18B20_Get_Temp();
		  if(temp<0)
		  {
				temp=-temp;
				LCD_ShowChar(156,8,'-',16,0);//显示负号	
		  }						 
		 LCD_ShowString(30,8,"Now temperature:");
         LCD_ShowNum(164,8,temp/10,2,16);//显示温度值	 
		 LCD_ShowChar(180,8,'.',16,0);//显示负号
		 LCD_ShowNum(188,8,temp%10,1,16);//显示温度值
		 //printf("温度:%d %d",temp/10,temp%10);
	    LCD_ShowChar(204,8,'C',16,0);//显示摄氏度
		LCD_ShowString(60,28,"Input your choice!");
	    LCD_ShowString(60,48,"1,set max temperature");
		LCD_ShowString(60,68,"2,set min temperature");
		if(Remote_Rdy)
		{	  
		    key=Remote_Process();
			if(key==104)
			{
		    	LCD_Fill(0,108,240,148,WHITE);
			    LCD_ShowString(0,88,"set max temperature:(for 089):");
				Remote_Rdy=0;
				get_remote(3);
				sum=set_timer_temp[0]*100+set_timer_temp[1]*10+set_timer_temp[2];
				//LCD_ShowNum(60,108,sum,3,16);
			//	LCD_ShowString(60,128,"Please sure!(ALIENK)");
			//	if(judge())	
			//	{   
				   
				   if(sum>mintemp1)
				   {   
				    LCD_Fill(0,108,240,148,WHITE);
				    maxtemp1=sum;LCD_ShowNum(60,108,sum,3,16);LCD_ShowString(60,128,"Finish max temp");
				//	LCD_Fill(0,148,,320,WHITE);
					LCD_Fill(0,304,240,320,WHITE);
					}
				   else
				    {
					LCD_Fill(0,108,240,148,WHITE);
				    LCD_ShowString(60,108,"Max temp failed!");
					LCD_Fill(0,304,240,320,WHITE);
				   }
				//	delay_1s(2);
			//	}
			//		else 
			//	{
			//		LCD_ShowString(60,148, "Error!exit !");
			//		delay_1s(2);
			//		break;
			//	}
			}
			else if(key==152)
			{
				LCD_ShowString(0,148,"set min temperature:(for 000):");
				LCD_Fill(0,168,240,208,WHITE);
				Remote_Rdy=0;
				get_remote(3);
				sum=set_timer_temp[0]*100+set_timer_temp[1]*10+set_timer_temp[2];
			//	LCD_ShowNum(60,168,sum,3,16);
				//LCD_ShowString(60,208,"Please sure!(ALIENK)");
			//	if(judge())	
				//{   
				   if(maxtemp1>sum)
				   {  
				   mintemp1=sum; 
				   LCD_Fill(0,168,240,208,WHITE);
				   LCD_ShowNum(60,168,sum,3,16);
				   LCD_ShowString(60,188,"Finish min temp");
				   LCD_Fill(0,304,240,320,WHITE);	   
				   }
				   else 
				   { 
				   	LCD_Fill(0,168,240,208,WHITE);
				    LCD_ShowString(60,168," Min temp failed!");	
					LCD_Fill(0,304,240,320,WHITE);
				  //  delay_1s(2);
				   }
				  
				//}
				//	else 
			//	{
				//	LCD_ShowString(60,228, "Error!exit !");
				//	delay_1s(2);
				//	break;
			//	}
		}
		      	 else  if(key==82)
				 {
					 LCD_Fill(0,88,240,320,WHITE);
				 	 LCD_ShowString(60,148,"exit operation!");
					// LCD_ShowString(60,168,"operation again ?");
					 LCD_ShowString(60,168,"ALIENK(yes) else(no)");
					 if(judge()==1) { LCD_Clear(WHITE); break;}
				     else LCD_Clear(WHITE);
				 }
				 else Remote_Rdy=0;
		 }
	}	 	
} 
 //功能:设置延迟时间
void set_temper_time()
{ 
   	
	int sum;
   	LCD_Clear(WHITE);
	LCD_ShowString(30,8,"set disinfectant time");
    LCD_ShowString(30,28,"  000min-999min");
	Remote_Rdy=0;
	get_remote(3);
	sum=set_timer_temp[0]*100+set_timer_temp[1]*10+set_timer_temp[2];
	LCD_ShowNum(60,48,sum,3,16);
	LCD_ShowString(0,68,"Finish disinfectant time!");
	//LCD_ShowString(0,88,"1,set gain ; else sure");
 /*   while(1)
	{		
	        	Remote_Rdy=0;//消除干扰
	            if(Remote_Rdy)
			{
				key=Remote_Process();
				if(key==104)
				{
					LCD_ShowString(30,8,"set disinfectant time");
                    LCD_ShowString(30,28,"  000min-999min");
					get_remote(3);
					sum=set_timer_temp[0]*100+set_timer_temp[1]*10+set_timer_temp[2];
					LCD_ShowNum(60,48,sum,3,16);
					LCD_ShowString(84,48,"min");
					LCD_ShowString(0,68,"Finish disinfectant time!");
					LCD_ShowString(0,88,"1,set gain ; else sure");
				}
				else
				{
					 LCD_Fill(0,68,240,320,WHITE);
				 	 LCD_ShowString(60,148,"exit operation!");
					// LCD_ShowString(60,168,"operation again ?");
					 LCD_ShowString(60,168,"ALIENK(yes) else(no)");
					 if(judge()==1) { LCD_Clear(WHITE); break; }
				                 
			   }
	    }	
		}  */
     LCD_Clear(WHITE);
	 LCD_ShowString(30,160,"disinfecting!");
	 LCD_ShowString(30,180,"time:");
	 LCD_ShowNum(75,180,sum,3,16);
	 LCD_ShowString(107,180,"min");
	 SWITCH1=1;
	 delay_minuter(sum);
	 LCD_ShowString(30,180,"disinfect finished!");
	 LCD_ShowString(30,200,"prepare for  standby!");
	 SWITCH1=0;
	 WARN=0;
	 delay_1s(10);
	 Sys_Standby();//待机函数		 
}
void temp_keeptimer()
{
	int sum;
    tempkeep=1;
   	LCD_Clear(WHITE);
	LCD_ShowString(0,8,"set temperatue keep time");
    LCD_ShowString(30,28,"000C-999C");
	Remote_Rdy=0;
	get_remote(3);
	sum=set_timer_temp[0]*100+set_timer_temp[1]*10+set_timer_temp[2];
	LCD_ShowNum(60,48,sum,3,16);
	midtemp=sum;
	LCD_ShowString(0,68,"Finish disinfectant time!");
	delay_1s(2);
   LCD_Clear(WHITE);
}


⌨️ 快捷键说明

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