DS18B20 and ReadTemp12 ?

manie

Senior Member
The DS18B20 gives good readings if you want only whole degress in Centigrade. After searching the fora(ums??) I just want to confirm I understood correctly. To get higher resolution temperature readings you have to use a WORD variable(12bits) - fine. The calculation to get 1 decimal (0.1 deg C) from this will then be:
readtemp12 pinx,temp
sign= 43 ; = "+"
temp= temp*10 / 16 ; x10 = 1 decimal(0.1) resolution
whole= temp / 10
deci = temp // 10

'now send WHOLE and "." and "DECI" to firmware chip and LCD...
'-----------------------------------------------------------------
Negative temp's requires the inverse & 4095 +1 as below:

readtemp12 pinx,temp
sign= 43 ; ="+"
IF temp> 2048 THEN ; below zero...
sign= 45 ; ="-"
temp= INV temp
temp= temp AND 4095 + 1 ;mask off top 4 bits,add 1 for correction
ENDIF
I understand the INV(ert) bit. Can someone please explain what happens with the "AND" then "+1" part. Is that not the same as +4096 (12bits) ? What correction is made by adding 1 later ?
 

MBrej

Member
The AND command is bitwise masking rather than addition, see here. After the bitwise operation is completed 1 is then added. This line and the one above converts the value sent from the sensor which is in twos complement into the equivalent non negative integer.

Matt
 
Top