Eugeniu, below are some ideas on how to modify your code with the help of an LCD. This should provide all the info for the conversion, decoding, and displaying of the temp based on the DS18S20 (which matches your previous posted table). All based on your code, SKIMASK's suggestions, and readily available code on the forum.
modifications to variables
Code:
Cold_Bit VAR temperature.Bit11 ' Sign-Bit for +/- Temp. 1 = Below 0 deg C
Half_Deg_Bit VAR temperature.Bit0 ' 0.5deg Bit
Sign VAR temperature.HIGHBYTE ' +/- sign for temp display
temperature_int VAR temperature.LOWBYTE ' integer part of temperature
temperature_dec VAR BYTE ' fractional part of temperature
digit var byte[5]
reading temperature (this is not better than what you had, just short and simple)
Code:
'read temperature
OWOut DQ, 1, [$CC, $44] ' Start temperature conversion
pause 1000 ' Wait max conversion time
OWOut DQ, 1, [$CC, $BE] ' Read the temperature
OWIn DQ, 0, [temperature_int, sign] ' Store temperature on variable
storing raw temperature on EEPROM
Code:
'store raw value of temperature in EEPROM (like SKIMASK suggested)
adr = 24
i2cwrite i2cdat, i2cclk, $a0, adr,[sign]
adr = 25
i2cwrite i2cdat, i2cclk, $a0, adr,[temperature_int]
reading raw temperature from EEPROM
Code:
'read raw temperature from EEPROM
adr = 24
i2cread i2cdat, i2cclk, $a0, adr, sign
adr = 25
i2cread i2cdat, i2cclk, $a0, adr, temperature_int
decoding temperature (including negative temperatures)
Code:
'decode temperature as needed (this will decode both positive and negative temperatures)
IF Cold_bit = 1 THEN ' If Cold_Bit = 1, negative temperature
Sign = "-"
temperature_int = (255 - temperature_int) + 1 ' 2s Complement
ELSE ' If Cold_Bit = 0, positive temperature
Sign = "+"
ENDIF
temperature_int = temperature_int / 2 ' Strip LSB from temperature reading
IF Half_Deg_Bit = 1 ' If Half_Deg_Bit = 1, add half degree to result
temperature_dec = 5
ELSE
temperature_dec = 0
ENDIF
displaying decoded temperature on LCD
Code:
'to display temperature on LCD
lcdout sign , DEC2 (temperature_int) , "," , DEC2 (temperature_dec)
storing decoded temperature digits
Code:
'to extract digits
digit[5] = temperature_int dig 2
digit[4] = temperature dig 1
digit[3] = temperature dig 0
digit[2] = ","
digit[1] = temperature_dec dig 0
digit[0] = 0
P.S. When posting use the "code" tags to wrap the code and display it nice and tidy. Also use the "quote" tags when quoting somebody; again it displays nice and tidy.
Bookmarks