Code:
Busy VAR BIT ' Busy Status-Bit
Raw VAR WORD ' RAW Temperature readings
TempF VAR WORD ' Temp in deg F
Dummy VAR BYTE ' Dummy for Div32
ID VAR BYTE[8] ' Array storage variable for 64-bit ROM code
sensor VAR BYTE
hexbyte VAR byte
col VAR BYTE
TankOffSet var byte
;*** MAIN TANK TEMP**********************************************************
ReadTankTemp:
TEMPSENSOR = 1
GOSUB Begin
MTtemp = TempF
RETURN
;**************************************************************************
Begin:
sensor= TEMPSENSOR 'I am reading 5 DS18b20 sensors...
FOR hexbyte=0 TO 7 'each sensor address is 8 bytes
GOSUB GetID 'go look up each sensors address
ID[hexbyte]=col 'load the ID array with the retrieved address byte
NEXT hexbyte 'go get the rest of the address bytes
OWOUT DQ, 1, [$55,STR ID\8,$44] 'instructs sensors to match[$55] this[ID] rom code and
'initiates[$44] temperature conversion on matching sensor
CkAgn:
OWIN DQ, 4, [Busy] ' Check for still busy converting
IF Busy = 0 THEN CkAgn ' Still busy?, then loop
OWOUT DQ,1,[$55,STR ID\8,$BE] 'instructs sensors to match[$55] this[ID] and start sending back scratchpad[$BE]
OWIN DQ, 2, [Raw.LOWBYTE,Raw.HIGHBYTE]' Read two temperature bytes, then end communications
; Dummy = 1125 * Raw
; TempF = DIV32 100
RETURN
GetID:
SELECT CASE sensor
CASE 1 :LOOKUP hexbyte,[$28,$A0,$44,$EA,$03,$00,$00,$02], col 'MAIN TANK SENSOR
CASE 2 :LOOKUP hexbyte,[$28,$2F,$44,$EA,$03,$00,$00,$CC], col 'SUMP TANK SENSOR
CASE 3 :LOOKUP hexbyte,[$28,$D4,$17,$EA,$03,$00,$00,$9D], col 'SALT RES TEMP
CASE 4 :LOOKUP hexbyte,[$28,$96,$35,$EA,$03,$00,$00,$FD], col '?? TEMP
CASE 5 :LOOKUP hexbyte,[$28,$45,$F8,$24,$03,$00,$00,$82], col 'AMBIANT AIR TEMP
END SELECT
RETURN
And to display the temperature on the LCD:
Code:
SEROUT TX, T9600,["TANK TEMP"]
GOSUB ReadTankTemp
SEROUT TX, T9600,[$FE, $0C, 2,12] ; SET CURSOR TO ROW2 COL12
MTtemp = (MTtemp + 3200) + tankoffset
SEROUT2 TX, 84, [DEC MTtemp DIG 3,DEC MTtemp DIG 2,".",DEC2 MTtemp,$DF,"F"]
Bookmarks