代码如下,在获取高八位赋值给TH后,又执行左移8位,这样高八位不就被清零了吗?这还怎么计算温度啊?
//从DS18B20中得到温度

short DS18B20_Get_Temp(void)
{
u8 temp;
u8 TL,TH;
short tem;
DS18B20_Start (); // ds1820 start convert
DS18B20_Rst();
DS18B20_Check();
DS18B20_Write_Byte(0xcc); // skip rom
DS18B20_Write_Byte(0xbe); // convert
TL=DS18B20_Read_Byte(); // LSB
TH=DS18B20_Read_Byte(); // MSB
if(TH>7)
{
TH=~TH;
TL=~TL;
temp=0; //
}else temp=1; //

tem=TH;
//高八位赋值给tem

tem<<=8; //
左移后tem全为0,高八位的值存哪去了???求指点啊
tem+=TL; //
tem=(float)tem*0.625; //
if(temp)return tem; //
else return -tem;
}
一周热门 更多>