Hey Group, and Bruce
Below are two snippets of code from Bruce's website Rentron http://www.rentron.com/PicBasic/one-wire3.htm
Thank you Bruce for the code... It works great by the way.
However I can not figure out a portion of it...
I have eliminated the parts that send Debug Data and the parts that do deg C conversion. I just need a routine that returns deg F.
Here is a section of the code as Bruce posted it...
Code:
Convert_Temp: ' +32.0 to +257 F
IF Cold_Bit = Real_Cold THEN Yikes ' If Cold_Bit = 1, it's below "0" deg C
Sign = "+"
Dummy = 625 * R_Temp ' Multiply to load internal registers with 32-bit value
TempC = DIV32 10 ' Use Div32 value to calculate precise deg C
Dummy = 1125 * R_Temp
TempF = DIV32 100
IF TempF >6795 THEN ' Over 99.5 deg F..?
TempF = TempF + 3200
SEROUT2 DISP,BAUD, [INS,LINE1, " TempF = ",Sign,DEC TempF DIG 4,_
DEC TempF DIG 3,DEC TempF DIG 2,".",DEC2 TempF,Deg,"F "]
ELSE
TempF = TempF + 3200
SEROUT2 DISP,BAUD, [INS,LINE1, " TempF = ",Sign,DEC TempF DIG 3,_
DEC TempF DIG 2,".",DEC2 TempF,Deg,"F "]
ENDIF
TempC = (R_Temp & $0FF0) >> 4 ' Mask middle 8-bits, shift into lower byte
Float = ((R_Temp.Lowbyte & $0F) * 625) ' Lower 4-bits of result * 625
SEROUT2 DISP,BAUD, [INS,LINE2, " TempC = ",Sign,DEC TempC,".",DEC Float,Deg,"C "]
SEROUT2 DISP,BAUD, [INS,LINE4, "Raw", IBIN16 R_Temp]
RETURN
Here is that same portion of code cleaned up for my needs...
Code:
Convert_Temp: ' +32.0 to +257 F
IF Cold_Bit = Real_Cold THEN Yikes ' If Cold_Bit = 1, it's below "0" deg C
Sign = "+"
Dummy = 1125 * R_Temp
TempF = DIV32 100
IF TempF >6795 THEN ' Over 99.5 deg F..?
TempF = TempF + 3200
ELSE
TempF = TempF + 3200
ENDIF
RETURN ' with TempF loaded with current temp in deg F
My question surrounds this section of the code... This If/Then/Else looks redundant. But If I remove one of them then the code does not work. Why??
Works:
IF TempF >6795 THEN ' Over 99.5 deg F..?
TempF = TempF + 3200
ELSE
TempF = TempF + 3200
ENDIF
RETURN ' with TempF loaded with current temp in deg F
Does not Work(returns too low of a value):
IF TempF >6795 THEN ' Over 99.5 deg F..?
TempF = TempF + 3200
RETURN ' with TempF loaded with current temp in deg F
Thanks
Bookmarks