| 
 
| 目前多个DS18B20的ROM读取,我发现2个的时候可以读,焊了8个就读不到了,不知道是什么原因。 uint8 DS18B201_Read_Byte(void)
 {
 uint8 i,i_u8Data=0;
 DS18B20_BIT_DIR(1);
 General_Wait(30);
 for(i=0;i<8;i++)
 {
 DS18B20_BIT_CLR;
 i_u8Data >>= 1;
 General_Wait(30);
 DS18B20_BIT_SET;
 DS18B20_BIT_DIR(0);
 General_Wait(50);
 if(DS18B20_BIT_DATA)
 {
 i_u8Data = i_u8Data | 0x80;
 }
 General_Wait(150);
 DS18B20_BIT_DIR(1);
 }
 return i_u8Data;
 }
 // 从ds18b20得到温度值,精度:0.1C,返回温度值(-550~1250),Temperature1返回浮点实际温度
 float DS18B20_Get_Temp(uint8 i)
 {
 //u8 flag;
 uint8 j;//匹配的字节
 uint8 TL, TH;
 int16 Temperature;
 float Temperature1;
 DS18B20_Reset();
 j = DS18B20_Read_DQ();
 DS18B201_Write_Byte(0xcc);// skip rom
 DS18B201_Write_Byte(0x44);// convert
 General_Wait(100);
 DS18B20_Reset();
 j =DS18B20_Read_DQ();
 
 // DS18B20_Write_Byte(0xcc);// skip rom
 //匹配ID,i为形参
 DS18B201_Write_Byte(0x55);
 for (j = 0; j < 8; j++)
 {
 DS18B201_Write_Byte(DS18B20_ID[i][j]);
 }
 DS18B201_Write_Byte(0xbe);
 TL = DS18B201_Read_Byte(); // LSB
 TH = DS18B201_Read_Byte(); // MSB
 Temperature = (TH << 8) | TL;
 Temperature1 = (float)Temperature;
 Temperature1*=0.0625;
 return Temperature1;
 }
 大家帮忙看看我的读取温度有问题吗?读到全是FFFF。ROM地址确定是对的
 | 
 |