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

📄 main.c.bak

📁 此程序用于恒温箱控制
💻 BAK
字号:
 
#include <stdarg.h>///add,03-8-22,自定义printf
#include "main.h"
#include "x5045.h"   
#include "i2c.h"      
          
void            	T0_int();
void            	init_CPU(); 
 
void x9318(bit ud, uchar dat);
 
void reset_5045();

 
uchar  t50ms;
 
uchar t1s1,t1s2;
uint idata realtimetemp ;
 
uint  pre_comparetemp;
uchar  same_tempcha_times;

uchar  adj_hot_times,Hot_times ,temp2=0,heat_value=0;
idata uint readdata[3];
idata uint settemp;
 bit heat_bit;
 
 
 
void main()
 {
     
      uchar   readtemptimes=0 ,  i; 
           
      uint comparetemp=0,max  ; 
        
//	compairtemp=0;
	pre_comparetemp=0;
	same_tempcha_times=0;	        
	adj_hot_times=7;
         
        P11=1;
        init_CPU();
        WRSR_25045();
        write_7416C(0x00);     
        REST_DOG();
        i=Byte_Read(0,10);
        if(i!=10) reset_5045(); 
         settemp=180;             
          //write_7416T( 0,0x02,tem_value1 );
         //write_7416T( 0,0x03,tem_value1+6);              
           P37=1;          
           x9318(0,100);
           x9318(1,8);
           delay(5);                          
       while(1)
         {          
           REST_DOG();          
          if(t1s1>0 )
           { 
            t1s1=0;
           readdata[readtemptimes]=read_7416(0x00); 
            readtemptimes+=0x01;
 	      
 	       if(readtemptimes>0x02)	         	       
 	        { 
 	           readtemptimes=0;
 	           max=readdata[0];
 	           if(readdata[0]>readdata[1]) {readdata[0]=readdata[1];readdata[1]=max;}
 	           else max=readdata[1];
 	           if(max>readdata[2]) {readdata[1]=readdata[2];readdata[2]=max;}
 	           //else max=readdata[2];
 	           max=readdata[0];
 	           if(readdata[0]>readdata[1]) {readdata[0]=readdata[1];readdata[1]=max;}
 	            realtimetemp =readdata[1];                    	
                  t1s2=0;
                  while(t1s2!=2){};
                   if(settemp>=realtimetemp )
 	                 {
 	                  comparetemp=settemp-realtimetemp ;
 	                  if(comparetemp>160)
			     	{Hot_times=70;}
			 
		          else if(comparetemp>=0x80)
		         	 
			  	     { 
			          Hot_times=0x32;
			        
				}
			  else if(comparetemp>=0x10)
			  	{
			  	  if(comparetemp>=pre_comparetemp)
			  	            {
			  	              same_tempcha_times++; 
			                     if(same_tempcha_times>=0x06)
			                     	{adj_hot_times++;same_tempcha_times=0;pre_comparetemp=comparetemp;}
			  	            }
			          else  
			                    {
			                    	pre_comparetemp=comparetemp;same_tempcha_times=0;
			                    }
			  	 comparetemp&=0x00000f0;                    
 	                          switch(comparetemp)
 	                          
			  	           {   
			  	           	 
			  	                                  	
					      case 0x70: {Hot_times=(adj_hot_times+10);};break;
			  	                                  	
					      case 0x60: {Hot_times=(adj_hot_times+9);};break;
			  	                                  	
					      case 0x50: {Hot_times=(adj_hot_times+8);};break;		
			  	                                  						
			                      case 0x40: {Hot_times=(adj_hot_times+7);};break;
			  	                                  	
	                                      case 0x30: {Hot_times=(adj_hot_times+6);};break;
			  	                                  	
					      case 0x20: {Hot_times=(adj_hot_times+5);};break;
			  	                                  	
		                             case 0x10:  {Hot_times=(adj_hot_times+4);};break;
			  	                                  	
				             default:_nop_();
					    }
			         } 			         
			  else if(comparetemp>=1)
			 
			   {
			   	 if(comparetemp>=pre_comparetemp)
			  	            {
			  	              same_tempcha_times++; 
			                     if(same_tempcha_times>= 0x15)
			                     	{adj_hot_times++;same_tempcha_times=0;pre_comparetemp=comparetemp;}
			  	            }
			          else  
			                    {
			                    	pre_comparetemp=comparetemp;same_tempcha_times=0;
			                    }
			  	if((comparetemp<=0xf)&&(comparetemp>10))
                      	             {Hot_times=(adj_hot_times+3);}
                      	         else    if((comparetemp<=10)&&(comparetemp>6))
                      	             {Hot_times=(adj_hot_times+2);}
				 else if((comparetemp<=6 )&&(comparetemp>3))
				    	      {Hot_times=adj_hot_times+1;}
				else Hot_times=(adj_hot_times);         
			 
			    }
			    else Hot_times=(adj_hot_times-1);      
			     
			 }           			              
	             else  
		  	{
		  	if(Hot_times>7)
		  	 {	
		  	 comparetemp=realtimetemp-settemp;		          
			  if(comparetemp>0x70)
			  	{Hot_times=8;}
			 
			  else if(comparetemp>=0x10)
			  	{if(comparetemp>=pre_comparetemp)
			  	            {same_tempcha_times++; 
			                     if(same_tempcha_times>=0x06)
			                     	{adj_hot_times--;same_tempcha_times=0;pre_comparetemp=comparetemp;}
			  	            }
			         else  {pre_comparetemp=comparetemp;same_tempcha_times=0;}
			          comparetemp&=0x00000f0;     
			  	  switch(comparetemp)
			  	  
			  	            {
			  	           // case  0x80:     Hot_times=(adj_hot_times-18);break;
			  	            case  0x70:     Hot_times=(adj_hot_times-13);break;
                                             case  0x60:     Hot_times=(adj_hot_times-12);break;
					     case  0x50:     Hot_times=(adj_hot_times-11);break;
					     case  0x40:     Hot_times=(adj_hot_times-10);break;
					     case  0x30:     Hot_times=(adj_hot_times-9);break;
					     case  0x20:     Hot_times=(adj_hot_times-8);break;
					     case  0x10:     Hot_times=(adj_hot_times-7);break;
						default:_nop_();
			  	  	    }
			  	}
			  else if(comparetemp>=2)	
			  {
			  	      if(comparetemp>=pre_comparetemp)
			  	            {same_tempcha_times++; 
			                     if(same_tempcha_times>= 0x15)
			                    {adj_hot_times--;same_tempcha_times=0;pre_comparetemp=comparetemp;}
			  	            }
			         else  {pre_comparetemp=comparetemp;same_tempcha_times=0;}
			    	if((comparetemp<=0xf)&&(comparetemp>10))
			  	             Hot_times=(adj_hot_times-6);
			  	 else if((comparetemp<= 10)&&(comparetemp>6))
			            	      Hot_times=(adj_hot_times-5);           
			         else if((comparetemp<= 6)&&(comparetemp>3))
			            	      Hot_times=(adj_hot_times-4);
                                  else Hot_times=(adj_hot_times-3);
                                     
			  }  
			  else Hot_times=(adj_hot_times-2);
			  }//if(Hot_times>15)
			 }//else
	     if( (Hot_times<71)&&(Hot_times>7))	
	     { 
	      if (Hot_times>heat_value)
              {temp2=Hot_times-heat_value; heat_bit=1;}
                else 
             {temp2=heat_value-Hot_times; heat_bit=0; }
                heat_value=Hot_times;
                 x9318(heat_bit,temp2);
             }
	   }//if(t1s2)	 
	 }//if(t1s1)
       } //while(1)	           
     }
void init_CPU()
{
 
	/*SCON=0x50;*/
	TMOD=0x21; // T1:baut,T0:Time 16bit
	TCON=0x50; // TR0,TR1=1.低电平触发,IT0=IT1=0; 
	TH1=0xfd;TL1=0xfd;PCON=0; // Uart Baut=9600
    	TH0=0x4c;TL0=0x00;  // T0=50ms
	//T2CON=0x04; // T2:Time 16bit
	//RCAP2H=0x00;RCAP2L=0x00;
	IE=0x92; //开全局中断,定时器0。串口中断。/关两个外部中断EX0=EX1=0;
	IP=0x10; // UART高
	//AUXR=0x00;//内部XRAM,ALE为1/6FOSC,AUXR=0x10外部XRAM
	AUXR=0x01; //ALE IS common 
}
 
 
 
void T0_int() interrupt 1 using 2
{	TR0=0;
	TH0=0x4c;
	TL0=0x00; // T0=50ms
	t50ms++;
	t1s2++; 	
	if(t50ms>=20)
	{
		t50ms=0;		
		t1s1++;	
		t1s2++; 
	}
	//if(t1s2>=20)
	//{    
		//t1s2=0;	
		//flagtemp=0; 
	//}
	
	
	TR0=1;
}
 
void x9318(bit ud, uchar dat)
  {
    CS=0;
    if(ud) UD=1;//为UP
     else  UD=0;//为DOWN
      
     	for(;dat>0;dat--) 
     	{
     	  INC=1;
     	  delay(1);
     	  INC=0;
     	   delay(1);
     	 } 
     	 INC=1;
     	 delay(1);
     	  CS=1;
     		
  }
void delay(uint dat)      //延时秒位单位
 { 
  
 	 uchar i;
        while(dat--)
        {
        	WDT=1;
           	for(i=0;i<120;i++)
           	{;}
        }
  
 }
 
void reset_5045()
  { 
  	uchar i;
  	for(i=0;i<9;i++)
  	 {
  	 Byte_Write(0,i,0);	
  	 }	
  	 Byte_Write(0,10,10);	
  	  x9318(0,100);
   }	



 

 
 
 
 

⌨️ 快捷键说明

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