微波EDA网,见证研发工程师的成长!
首页 > 研发问答 > 嵌入式设计讨论 > MCU和单片机设计讨论 > 18B20多点测温

18B20多点测温

时间:10-02 整理:3721RD 点击:
部分程序如下:
uchar code sn1[]={"0x28,0x9D,0x7A,0x04,0x00,0x00,0x80,0xB7"};//序列号
uchar code sn2[]={"0x28,0xFF,0xBF,0xEA,0xA4,0x15,0x03,0xA3"};
uchar code sn3[]={"0x28,0xFF,0xE1,0xD0,0x89,0x16,0x03,0x16"};
void match_b20rom(uchar a) //匹配ROM
    {
     char j;
     Ds18b20_WriteByte(0x55);
     if(a==1)
       {
        for(j=0;j<8;j++)
        Ds18b20_WriteByte(sn1[j]);
       }
     if(a==2)
       {
        for(j=0;j<8;j++)
        Ds18b20_WriteByte(sn2[j]);
       }
     if(a==3)
       {
        for(j=0;j<8;j++)
        Ds18b20_WriteByte(sn3[j]);
       }
    }
int Ds18b20_ReadTemp(uchar z)//读取温度
   {
    int temp0 = 0;int j;
    uchar tmh, tml;
    if(Ds18b20_Init()==1)
      {
       ds_flag=1;
       return ds_flag;
      }
    else
      {
       ds_flag=0;
       Ds18b20_Init()  ;
       if(z==1) match_b20rom(1); //选择匹配的B20
       if(z==2) match_b20rom(2);
       if(z==3) match_b20rom(3);
       //Ds18b20_WriteByte(0xcc);        //先写入转换命令跳过ROM操作命令         
       Ds18b20_WriteByte(0x44);        //温度转换命令
       j++;
       j++;
       Ds18b20_Init()  ;
       if(z==1) match_b20rom(1); //选择匹配的B20
       if(z==2) match_b20rom(2);
       if(z==3) match_b20rom(3);
       //Ds18b20_WriteByte(0xcc);     //跳过ROM操作命令
       Ds18b20_WriteByte(0xbe);     //发送读取温度命令            
       tml = Ds18b20_ReadByte();        //读取温度值共16位,先读低字节
       tmh = Ds18b20_ReadByte();        //再读高字节
       temp0 = tmh;
       temp0 <<= 8;
       temp0 |= tml;
       return temp0;
      }
    }
void main(void)
    {uint tk=0;
     int i;
     int tk1=0;      
     lcd_init();
     delay1ms(50);
     while(1)
          {tk1=Ds18b20_ReadTemp(2);
           tk=Temperature(tk1);
           // read_b20sn();
           if(ds_flag==0)
             {   
              for(i=0;i<9;i++)         
               {write_dat(dis1[i]);}
              b20display(tk) ;//显示温度
             }
             else
             {
              lcd_pos(2,0);
              for(i=0;i<6;i++)
               {write_dat(dis1[i]);}
              }
          }
    }
为什么多点测温的时候就是就是出不来?

是用12864来显示,3个18B20的DQ连到一起,显示00.006C,不知道问题出在哪里了,求大神帮忙看看。谢谢各位了

我这里有源码 需要私聊   1 0 0 2 9 2 5 0 9 4  

我毕设做的就是基于温室的多点测控系统

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top