after a long test phase I found out, that it would be nice to have the possibility to get negativ or positiv sign before the temperature.
This information is stored in the DS18S20 Scratchpad Byte 1. If all bits are 0 then we have a positive temperature and when all bits are 1 then we have a negative temperature. So I overloaded the GetTemp function with the following:
Code: Select all
{
****************************************************************************
* Name : GetTemp (OVERLOAD) *
* Purpose : Read the device temperature (pSign = 0 means negativ) *
****************************************************************************
}
Public Sub GetTemp(ByRef pTemp As ShortInt, ByRef pFraction As Byte,ByRef pSign As Byte)
OW.WaitForHigh
ReadSP
pTemp = FSP(0).AsWord >> 1
pFraction = (FSP(0) And $01) * 5
If (FSP(1)) = $FF Then
psign = 0
Else
psign = 1
End If
End Sub
Code: Select all
{
*****************************************************************************
* Name : GetTempAsStrWithSign *
* Purpose : Read device temperature and return as formatted string with sign*
*****************************************************************************
}
Public Function GetTempAsStrWithSign() As String
Dim TempA As ShortInt
Dim TempB, Sign As Byte
Dim s As String
GetTemp(TempA, TempB, Sign)
If sign = 0 Then
s = "-"
Else
s = "+"
End If
Result = s + DecToStr(TempA) + "." + DecToStr(TempB)
End Function
Maybe you would integrate it in your next update!?
Best wishes
CS