CONVERT_T
Delay70us20
while1
ifI
itDs18b20
cou
ter0breakelsecou
terifcou
terERR_COUNTER为DS18B20出现故障
连续3次初始化失败,即认为DS18B20出
跳过读序号列号的操作启动温度转换
延时至少500us,以供温度转换
连续3次初始化失败,即认
fretur
0
WriteByteSKIP_ROMWriteByteREAD_SCRAT
跳过读序号列号的操作读取温度寄存器等(共可读9个寄存器)
ReadScrattempBuff9
if0CRC8tempBuff9
if0tempBuff10x80
为正温度
tempDattempBuff10x070x100tempBuff0
else
tempDat0xFFtempBuff10x070x1000x100tempBuff0
tempDattempDat
prTemperaturetempDat00625
retur
TRUE
retur
FALSE
FUNCTIONNAMEGetDS18B20Temperature
CREATEDATE2009817CREATEDBYXSFUNCTION采样3次求均值作为温度值
MODIFYDATE2009817
fINPUT温度储存的地址
RETURN正常为1,故障为0BOOLGetDS18B20TemperaturefloatpgTemperature
UCHARiUCHARcou
ter0floattempDat0floattempVal0
fori0i3
ifReadTemptempDat
tempValtempDatcou
ter0ielsecou
terifcou
terERR_COUNTER为故障,并返回
retur
FALSE
连续10次温度采样错误,则判断
pgTemperaturetempVal3Se
dStr