Hello.
I'm using the melabs sample code for DS18B20 and it works fine.
However, as it states:
Code:
OWOut DQ, 1, [$CC, $44] ' Start temperature conversion
waitloop:
OWIn DQ, 4, [count_remain] ' Check for still busy converting
If count_remain = 0 Then waitloop
OWOut DQ, 1, [$CC, $BE] ' Read the temperature
OWIn DQ, 0, [temperature.LOWBYTE, temperature.HIGHBYTE, Skip 4, count_remain, count_per_c]
' Calculate temperature in degrees C to 2 decimal places (not valid for negative temperature)
temperature = (((temperature >> 1) * 100) - 25) + (((count_per_c - count_remain) * 100) / count_per_c)
What should be fixed there to display negative temperature properly?
As I've read DS18B20 datasheet, negative temperature output will always have 4 MSB bits set to 1111. But what's wrong with the above conversion formula?
Bookmarks