Hi Avra, hello Neil,
I have shortened the calculations of the LM/DS 75 a little. Since the data comes in in 2-complement, I use an integer for reading in and I suggest the following routine: This way the decimals AND the negative temperatures are covered automatically. (tested it in my fridge..)
I have shortened the calculations of the LM/DS 75 a little. Since the data comes in in 2-complement, I use an integer for reading in and I suggest the following routine: This way the decimals AND the negative temperatures are covered automatically. (tested it in my fridge..)
Code
Initialize Sequence:
I2Cout(cLM75adr,1,$00); // Initialize the DS75 with
// $60 = 12 Bit, $40 = 11 Bit,
// $20 = 10 Bit, $00 = 9 Bit
I2Cout(cLM75adr,0); // Set default reading to temperature register
function GetTemperature (lLM75adr : Byte): Float; // We read the temperature of the I²C chip here
Var
lTmp : Integer;
Begin
I2Cinp(lLM75adr,lTmp); // Load the 2-Complement directely into an Integer.
lTmp := Swap (lTmp); // Now swap Lo- and Hibyte (they come in reverse order)
Return(float(lTmp)/256); // and calculate the temperature
End;
I2Cout(cLM75adr,1,$00); // Initialize the DS75 with
// $60 = 12 Bit, $40 = 11 Bit,
// $20 = 10 Bit, $00 = 9 Bit
I2Cout(cLM75adr,0); // Set default reading to temperature register
function GetTemperature (lLM75adr : Byte): Float; // We read the temperature of the I²C chip here
Var
lTmp : Integer;
Begin
I2Cinp(lLM75adr,lTmp); // Load the 2-Complement directely into an Integer.
lTmp := Swap (lTmp); // Now swap Lo- and Hibyte (they come in reverse order)
Return(float(lTmp)/256); // and calculate the temperature
End;