18b20单总线的多机,查询出来序列后,匹配要怎么写,最好有人提供一下代码,下面是我匹配的代码,总线上有两个18b20,但是烧进单片机后显示是有问题的
DS18B20_Init();
DS18B20_Write_Byte(0xcc);
DS18B20_Write_Byte(0x44);
delay_ms(1000);
// DS18B20_Rst();
delay_us(80);
DS18B20_Write_Byte(0x55);
delay_us(80);
DS18B20_Write_Byte(0x28);
DS18B20_Write_Byte(0xaa);
DS18B20_Write_Byte(0x99);
DS18B20_Write_Byte(0xee);
DS18B20_Write_Byte(0x04);
DS18B20_Write_Byte(0x00);
DS18B20_Write_Byte(0x00);
DS18B20_Write_Byte(0x0b);
temperature1=DS18B20_Get_Temp();
if(temperature1<0)
{
LCD_ShowChar(60+40,150,'-',16,0); //显示负号
temperature1=-temperature1; //转为正数
}else LCD_ShowChar(60+40,150,' ',16,0); //去掉负号
LCD_ShowNum(60+40+8,150,temperature1/10,2,16); //显示正数部分
LCD_ShowNum(60+40+32,150,temperature1%10,1,16); //显示小数部分
DS18B20_Init();
// DS18B20_Write_Byte(0xcc);
// DS18B20_Write_Byte(0x44);
// delay_us(80);
// DS18B20_Rst();
DS18B20_Write_Byte(0x55);
delay_us(80);
DS18B20_Write_Byte(0x28);
DS18B20_Write_Byte(0x56);
DS18B20_Write_Byte(0x9d);
DS18B20_Write_Byte(0x02);
DS18B20_Write_Byte(0x04);
DS18B20_Write_Byte(0x00);
DS18B20_Write_Byte(0x00);
DS18B20_Write_Byte(0x40);
temperature2=DS18B20_Get_Temp();
if(temperature2<0)
{
LCD_ShowChar(60+40,170,'-',16,0); //显示负号
temperature2=-temperature2; //转为正数
}else LCD_ShowChar(60+40,170,' ',16,0); //去掉负号
LCD_ShowNum(60+40+8,170,temperature2/10,2,16); //显示正数部分
LCD_ShowNum(60+40+32,170,temperature2%10,1,16); //显示小数部分
|