EarlyBird2-
Thanks! I just tried it (I did NOT have them as CONstants), compiles fine but still gives me 0.00F.
Code is below for clarification.
Regards,
Steve
Code:
Positive con 0 'Bit used for + in the DS18S20
Negative con 1 'Bit used for - in the DS18S20
rawtemp var word 'Raw temp var
tempC var word 'Temp var for degrees C
tempF var word 'Temp var for degrees F
dq var byte[9] 'String of data from DS18S20
SignC var bit 'Bit for + or - for degrees C
SignF var bit 'Bit for + or - for degrees F
dummy var bit 'Temp var
ReadDS18S20:' Works, mostly.....--Thanks 'Kid' from Forum-----------------------
owout Tsensor,1,[$CC, $44] 'Send Start Temperature Conversion command
owout Tsensor,1,[$CC, $BE] 'Send Read Temperature command
owin Tsensor,0,[STR dq\9] 'Retrieve all 9 bytes of data
RawTemp.Byte0 = dq[0]
RawTemp.byte1 = dq[1]
if RawTemp.8 = 1 then 'Check if temperature is a negative reading
SignC = Negative
RawTemp.lowbyte = RawTemp.lowbyte ^ 255 'Invert data
else
SignC = Positive
endif
dummy = RawTemp.0 'Store the half degree indicator bit
TempC = ((RawTemp.lowbyte) >> 1) * 100 'Divide raw data by 2 to give real temperature
TempC = TempC + (dummy * 50) 'Add the half degree is present
if SignC = Negative then 'Only proceed if temperature is negative - doesnt work for F, fine for C
if TempC => 1770 then
SignF = Negative
TempF = (TempC + 5000) * 900
TempF = div32 500
TempF = TempF - 12200
return
else
SignF = Positive
TempF = (TempC + 5000) * 900
TempF = div32 500
TempF = 12200 - TempF
return
endif
endif
' SignF = Positive 'Sign is +
' TempF = ((TempC * 18) / 10) + 3200 'Convert from C to F
return
This what I have that does work, just not for negatives.....
Code:
ReadDS18S20:' Works, mostly.....--Thanks 'Kid' from Forum-----------------------
owout Tsensor,1,[$CC, $44] 'Send Start Temperature Conversion command
owout Tsensor,1,[$CC, $BE] 'Send Read Temperature command
owin Tsensor,0,[STR dq\9] 'Retrieve all 9 bytes of data
RawTemp.Byte0 = dq[0]
RawTemp.byte1 = dq[1]
if RawTemp.8 = 1 then 'Check if temperature is a negative reading
SignC = Negative
RawTemp.lowbyte = RawTemp.lowbyte ^ 255 'Invert data
else
SignC = Positive
endif
dummy = RawTemp.0 'Store the half degree indicator bit
TempC = ((RawTemp.lowbyte) >> 1) * 100 'Divide raw data by 2 to give real temperature
TempC = TempC + (dummy * 50) 'Add the half degree is present
' if SignC = Negative then 'Only proceed if temperature is negative - doesnt work for F, fine for C
' if TempC => 1770 then
' SignF = Negative
' TempF = (TempC + 5000) * 900
' TempF = div32 500
' TempF = TempF - 12200
' return
' else
' SignF = Positive
' TempF = (TempC + 5000) * 900
' TempF = div32 500
' TempF = 12200 - TempF
' return
' endif
' endif
SignF = Positive 'Sign is +
TempF = ((TempC * 18) / 10) + 3200 'Convert from C to F
return
Regards,
Steve
Bookmarks