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

📄 复件 main(还差串口通信没做).c

📁 这是一个多点温度测量系统
💻 C
字号:
#include "AT89X52.H"
#include "1602S51.H"
#include "DS18B20S51.H"
unsigned char tt[16]={"I:  .   II:  .  "};
unsigned char PP[16]={"III:  .         "};

unsigned char timecount=0;
unsigned int TesTemperature1=0;//实测得到温度  4位,到达千
unsigned int TesTemperature2=0;//实测得到温度
unsigned int TesTemperature3=0;//实测得到温度
unsigned char ID_choose=0;     //测量路号选择,0--三路同时 1--第一路 2--第二路 3--第三路
 unsigned int sst;
void initTimer(void); //初始化定时器0
int translate(unsigned int uiData,unsigned char ID);
void Key_Scan(void);//按键扫描
void main()
{
   // initTimer();
  //  TR0=1;
  //  ET0=1;
  //  EA=1;    //开总中断
 
    init_LCD();   //初始化LCD----来自1602S51.H文件
 
   display(0x80,tt,16);  //界面显示
   display(0xC0,PP,16);
  while(1)
   {
        display(0x80,tt,16);  //界面显示
        display(0xC0,PP,16);
        Key_Scan();
        switch(ID_choose)
	   {
	      case 0:   //三路同时测
				     sst=Read_Temperature(1);   //第一路
				     TesTemperature1=translate(sst,1);	    
       
				     sst=Read_Temperature(2);   //第二路
				     TesTemperature2=translate(sst,2);	

				     sst=Read_Temperature(3);   //第三路
				     TesTemperature3=translate(sst,3);	
		             break;
		  case 1: 
				     sst=Read_Temperature(1);   //第一路
				     TesTemperature1=translate(sst,1);	
		             break;
	      case 2: 
				     sst=Read_Temperature(2);   //第二路
				     TesTemperature2=translate(sst,2);
		             break;
		  case 3: 
				     sst=Read_Temperature(3);   //第三路
				     TesTemperature3=translate(sst,3);	
		             break;	   
		  default:break;
	   }

   }
  
}
/*
void initTimer(void) //初始化定时器0
{
 TMOD=0x1;    //工作方式1
 TH0=0x3c;    //定时50ms 
 TL0=0xb0;
}
*/
/*
void timer0(void) interrupt 1 using 0	//定时50ms
{
 
 
//  unsigned int sst;
  timecount++;
  

  if(timecount==25) //0.5秒扫一个
   {  
     timecount=0;
    
      switch(ID_choose)
	   {
	      case 0:   //三路同时测
				     sst=Read_Temperature(1);   //第一路
				     TesTemperature1=translate(sst,1);	    
       
				     sst=Read_Temperature(2);   //第二路
				     TesTemperature2=translate(sst,2);	

				     sst=Read_Temperature(3);   //第三路
				     TesTemperature3=translate(sst,3);	
		             break;
		  case 1: 
		             break;
	      case 2: 
		             break;
		  case 3: 
		             break;	   
		  default:break;
	   }
	   
   }
 TH0=0x3c;
 TL0=0xb0;

}
*/
//--------------------------------------------------------
//把读到的温度放到要显示缓存中
//输入:uiData 读到的数值 ID是温度的路号1表是第一路,2表示第二路,3表示第三路
//输出:通过给相应的数组赋值,达到输出
int translate(unsigned int uiData,unsigned char ID)
 {

	unsigned int uiInteger;					//数据的整数部分
	unsigned int uiDecimal;					//数据的小数部分
	unsigned int uiBai;						//显示温度的百位
 	unsigned int uiShi;						//显示温度的十位
 	unsigned int uiGe;						//显示温度的个位
 	unsigned int uiShi_d;					//显示温度的十分位
 	unsigned int uiBai_d;					//显示温度的百分位
// 	unsigned int uiQian_d;					//显示温度的千分位
	unsigned int uiResidue;					//数据的余数,作除法
	
	uiInteger = 0;
	uiDecimal = 0;
	
	if(uiData & 0x0400)
		uiInteger += 64;					//转换为整数部分
	if(uiData & 0x0200)
		uiInteger += 32;
	if(uiData & 0x0100)
		uiInteger += 16;
	if(uiData & 0x0080)
		uiInteger += 8;
	if(uiData & 0x0040)
		uiInteger += 4;
	if(uiData & 0x0020)
		uiInteger += 2;
	if(uiData & 0x0010)
		uiInteger += 1;
	
	if(uiData & 0x0008)
		uiDecimal += 5000;					//转换为小数部分
	if(uiData & 0x0004)
		uiDecimal += 2500;
	if(uiData & 0x0002)
		uiDecimal += 1250;
	if(uiData & 0x0001)
		uiDecimal += 625;
	
	 uiBai = uiInteger/100;					//小数点前面部分
	uiResidue = uiInteger%100;
	uiInteger = uiResidue;
	  uiShi = uiInteger/10;
	uiResidue = uiInteger%10;
	  uiGe = uiResidue;
	
	  uiShi_d = uiDecimal/1000;				//小数点后面部分
	uiResidue = uiDecimal%1000;
	uiDecimal = uiResidue;
	  uiBai_d = uiDecimal/100;
	uiResidue = uiDecimal%100;
	uiDecimal = uiResidue;

	
	//显示
  
   switch(ID)
    { 
       case 1:  
			 	tt[2]=uiShi+'0' ;
			 	tt[3]=uiGe+'0' ;
			 //	tt[4]='.';
			 	tt[5]= uiShi_d+'0';
			 	tt[6]= uiBai_d+'0' ;
                 break;
       case 2:  
			 	tt[11]=uiShi+'0' ;
			 	tt[12]=uiGe+'0' ;
			 //	tt[13]='.';
			 	tt[14]= uiShi_d+'0';
			 	tt[15]= uiBai_d+'0' ;
                 break;
       case 3:   
			 	PP[4]=uiShi+'0' ;
			 	PP[5]=uiGe+'0' ;
			 //	PP[6]='.';
			 	PP[7]= uiShi_d+'0';
			 	PP[8]= uiBai_d+'0' ;
                 break;
       default:break;
        
    }

  
 	return uiShi*1000+uiGe*100+uiShi_d*10+uiBai_d  ;
	 }



 void Key_Scan(void)//按键扫描
 {
   P2_0=1;
   P2_1=1;
   P2_2=1;
   P2_3=1;
   if(P2_0==0)
    {
	   delay_ms(1);
       if(P2_0==0)
	    {
		   ID_choose=0;
		}
	}

   if(P2_1==0)
    {
	   delay_ms(1);
       if(P2_1==0)
	    {
		   ID_choose=1;
		}
	}
   if(P2_2==0)
    {
	   delay_ms(1);
       if(P2_2==0)
	    {
		   ID_choose=2;
		}
	}
   if(P2_3==0)
    {
	   delay_ms(1);
       if(P2_3==0)
	    {
		   ID_choose=3;
		}
	}
 }

⌨️ 快捷键说明

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