多个DS18B20并联,求指导!

2020-02-04 09:12发布

哪位大侠做过多个DS18B20并联?希望能给予指导,不会走太多弯路。
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
该问题目前已经被作者或者管理员关闭, 无法添加新回复
50条回答
zhxzhx
1楼-- · 2020-02-09 10:45
DFH, 00H, 00H, 03H, AAH, 84H, C4H, 28H
你的顺序反了,应该是
28H,C4H,84H,AAH,03H,00H,00H,DFH
还应该有一个CRC的校验
lvwenjie
2楼-- · 2020-02-09 11:12
 精彩回答 2  元偷偷看……
zhxzhx
3楼-- · 2020-02-09 14:46
你的程序成功了吗?
我给你个搜索程序吧
/*搜索过程的程序代码*/
#define FALSE 0
#define TRUE 1
//bit OWFirst(unsigned char select);
bit OWSearch(unsigned char select);
unsigned char docrc8(unsigned char value);

idata  char LastDiscrepancy;
bit LastDeviceFlag;
idata unsigned char crc8;

//--------------------------------------------------------------------------
// Perform the 1-Wire Search Algorithm on the 1-Wire bus using the existing
// search state.
// Return TRUE : device found, ROM number in ROM_NO buffer
// FALSE : device not found, end of search
//
bit OWSearch(unsigned char select)
{
idata unsigned char id_bit_number;
idata unsigned char last_zero, rom_byte_number;
bit search_result;
bit id_bit, cmp_id_bit;
idata unsigned char rom_byte_mask;
bit search_direction;
id_bit_number = 1;
last_zero = 0;
rom_byte_number = 0;
rom_byte_mask = 1;
search_result = 0;
crc8 = 0;
if (!LastDeviceFlag)
{
OWInit(select);
if (!flag)
{
LastDiscrepancy = 0;
LastDeviceFlag = FALSE;
return FALSE;
}
OWWriteByte(0xF0,select);
do
{
id_bit = OWReadBit(select,0);  //0
cmp_id_bit = OWReadBit(select,0); //0
if ((id_bit == 1) && (cmp_id_bit == 1)) //11
  {_nop_();
   break;
  }
else
  {
   if (id_bit != cmp_id_bit)    //10 01
     search_direction = id_bit; // bit write value for search
   else
     {                          //00
       if (id_bit_number < LastDiscrepancy)
           search_direction = ((temp_buff[rom_byte_number] & rom_byte_mask) > 0);
       else
           search_direction = (id_bit_number == LastDiscrepancy);
       if (search_direction == 0)
          {last_zero = id_bit_number;
          }
      }

   if (search_direction == 1)
     temp_buff[rom_byte_number] |= rom_byte_mask;
   else
     temp_buff[rom_byte_number] &= ~rom_byte_mask;

   OWWriteBit(search_direction,select);

   id_bit_number++;

   rom_byte_mask <<= 1;

   if (rom_byte_mask == 0)
    {docrc8(temp_buff[rom_byte_number]); // accumulate the OWCRC
     rom_byte_number++;
     rom_byte_mask = 1;
    }
  }
}
while(rom_byte_number < 8); // loop until through all ROM bytes 0-7

if (!((id_bit_number < 65) || (crc8 != 0)))
  {LastDiscrepancy = last_zero;
   if (LastDiscrepancy == 0)
     LastDeviceFlag = TRUE;
   search_result = TRUE;
  }
}
if (!search_result || !temp_buff[0])
{LastDiscrepancy = 0;
  LastDeviceFlag = FALSE;
  search_result = FALSE;
  }
return search_result;
}

unsigned char docrc8(unsigned char value)
{
crc8 = CrcTable[crc8 ^ value];
return crc8;
}
zhxzhx
4楼-- · 2020-02-09 15:11
这是使用方法
没有的部分你自己过滤吧,
我这个程序是可以选择多个IO口的,SElect定义的,你不要理它,具体的DS18b20读写,你应该知道的
void scan1820(unsigned char select)
{bit rslt;
idata unsigned char i,cnt;
float idata ls;
unsigned int idata lsi;
cnt = 0;
LastDiscrepancy = 0;
LastDeviceFlag = FALSE;
rslt=OWSearch(select);
PTT=0;
while (rslt)
{
  cnt++;
  putbyte('0');
  putbyte('x');
  puthex(select);
  putbyte(',');
  putbyte('0');
  putbyte('x');
  puthex(temp_buff[0]);
  putbyte(',');
  putbyte('0');
  putbyte('x');
  puthex(temp_buff[1]);
  putbyte(',');
  putbyte('0');
  putbyte('x');
  puthex(temp_buff[2]);
  putbyte(',');
  putbyte('0');
  putbyte('x');
  puthex(temp_buff[3]);
  putbyte(',');
  putbyte('0');
  putbyte('x');
  puthex(temp_buff[4]);
  putbyte(',');
  putbyte('0');
  putbyte('x');
  puthex(temp_buff[5]);
  putbyte(',');
  putbyte('0');
  putbyte('x');
  puthex(temp_buff[6]);
  putbyte(',');
  putbyte('0');
  putbyte('x');
  puthex(temp_buff[7]);
  putbyte(',');
  putbyte('/');
  putbyte('/');
  putbyte(' ');
  putbyte('=');
  putbyte(' ');
  DOG=~DOG;
  ls=0;
  if (temp_buff[0]==0x28)        //DS18B20
    {OWInit (select);
     OWWriteByte(0xcc,select);   //skip rom
     OWWriteByte(0x44,select);   //Temperature convert
     ls=gettemp(select);
     }
  if (temp_buff[0]==0xA6)       //DS2438
    {inid=0;
     OWInit (select);
     OWWriteByte(0xcc,select);   //skip rom
     OWWriteByte(0x4E,select);
     OWWriteByte(0x00,select);
     OWWriteByte(0x00,select);

     OWInit (select);
     OWWriteByte(0xcc,select);   //skip rom
     OWWriteByte(0x48,select);
     OWWriteByte(0x00,select);
     delay(250);
     OWInit (select);
     OWWriteByte(0xcc,select);   //skip rom
     OWWriteByte(0xB4,select);   //Temperature convert

     ls=getvol(select);
     }
  ls*=10;
  lsi=ls;
  putint(lsi);
  putbyte(' ');
  putbyte(':');
  putbyte(' ');
  putint(inid/256);
  putbyte(' ');
  putint(inid & 0xFF);
  putbyte(' ');
  putint(cnt);

  putbyte(0x0d);
  putbyte(0x0a);
  rslt = OWSearch(select);
}
PTT=1;
}
zhxzhx
5楼-- · 2020-02-09 15:42
putbyte 是串口发送,PTT是485的收发控制,可以不理他

?带行号的程序是怎么出来的?
lvwenjie
6楼-- · 2020-02-09 16:04
zhxzhx 发表于 2012-4-16 15:38
你的程序成功了吗?
我给你个搜索程序吧
/*搜索过程的程序代码*/

成功了,不过时间挺长的

一周热门 更多>