I am trying to follow your code in an effort to better understand it, but I don't understand
SignC = Positive
Code:
ReadDS18S20:
owout sensor,1,[$CC, $44] ' Send Start Temperature Conversion command
owout sensor,1,[$CC, $BE] ' Send Read Temperature command
owin sensor,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
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
TempF = TempC * 18 / 10 + 3200
return
It would help if you shared the declarations of the variables used.
sensor equates to the hardware pin connected to the sensor?
RawTemp is a word?
dq is an array of 9?
dummy is a byte?
TempC is a byte?
TempF is a byte?
I don't get SignC or SignF and how you can equate to 'Positive' or 'Negative', I couldn't find a reference in the PBP manual.
Explanation would be appreciated.
Regards,
Steve
Bookmarks