Hope the following help
Initialization
Code:
;----[DS1820 Options]----Value----Default-----------------------------------
DEFINE DS1820_DECIMALS 1 ' 1
DEFINE DS1820_VERIFYCRC YES ' NO
DEFINE DS18B20_ONLY YES ' NO
INCLUDE "DT18x20.pbp" ' Include DT18x20 module
Code:
FOR Bvar = 0 to 3 ; assume all sensors are working
SensorActive(Bvar) = 1
NEXT Bvar
FOR pid_Channel = 0 TO 3 ; Set # of bits in resolution
GOSUB SelectSensor ; for all sensors
GIE = 0 ; disable interrupts before 1-wire
@ DS1820_Resolution 12
GIE = 1 ; enable interrupts after 1-wire
NEXT pid_Channel
LOW HeaterOut1 ; set heater pins Output to off
LOW HeaterOut2
LOW HeaterOut3
LOW HeaterOut4
Low Lights1 ; set lighting pins to off
Low Lights2
GOSUB SendPWRstat
The subroutine referred to above
Code:
SendPWRstat:
Bvar = 0
Bvar.0 = ChannelPWR(0)
Bvar.1 = ChannelPWR(1)
Bvar.2 = ChannelPWR(2)
Bvar.3 = ChannelPWR(3)
RETURN
Now for the main part
Code:
FOR pid_Channel = 0 TO 3 ; cycle thru all sensors
GOSUB SelectSensor
DS1820_Error = 0 ; clear any previous errors
DS1820_Flags = 0 ; clear status flags
GIE = 0 ; disable interrupts before 1-wire
@ DS1820_Stat ; check the sensors status
GIE = 1 ; enable interrupts after 1-wire
PAUSEUS 20
IF !DS1820_Done THEN SensorError ; if it's not done by now, error
GIE = 0 ; disable interrupts before 1-wire
@ DS1820_Read ; get the temperature result
GIE = 1 ; enable interrupts after 1-wire
GOSUB Check4Zeros
DS1820_Flags = 0
GIE = 0 ; disable interrupts before 1-wire
@ DS1820_Stat
GIE = 1 ; enable interrupts after 1-wire
IF (DS1820_Error = 0) AND DS1820_Done THEN ; if there were no errors
Temperatures(pid_Channel) = TempC
pid_Error = SetPoints(pid_Channel) - TempC
GOSUB PID
IF pid_Out.15 THEN pid_Out = 0 ; only keep positive values
IF ChannelPWR(pid_Channel) THEN
HeaterDrives(pid_Channel) = pid_Out
ELSE
HeaterDrives(pid_Channel) = 0
ENDIF
IF Temperatures(pid_Channel) > alarmhigh(pid_Channel) and Alarm = 1 then AlarmPin = 1
IF Temperatures(pid_Channel) > alarmhigh(pid_Channel) and Alarm = 0 then AlarmPin = 0
IF Temperatures(pid_Channel) <= alarmhigh(pid_Channel) then AlarmPin = 0
IF Temperatures(pid_Channel) <= alarmlow(pid_Channel) then AlarmPin = 0
if Temperatures(pid_Channel) < alarmlow(pid_Channel) and Alarm = 1 then AlarmPin = 1
if Temperatures(pid_Channel) < alarmlow(pid_Channel) and Alarm = 0 then AlarmPin = 0
GOSUB ShowLCD
ELSE
SensorError:
HeaterDrives(pid_Channel) = 0 ; turn off heater if sensor's bad
SensorActive(pid_Channel) = 0
GOSUB ShowError ; display error message
ENDIF
NEXT pid_Channel
The other two parts you may be interested in is the checking and displaying sections
Code:
AllZeros VAR Bit
Check4Zeros:
AllZeros = 1
FOR Bvar = 0 TO 8
IF DS1820_Buffer(Bvar) != 0 THEN AllZeros = 0
NEXT Bvar
IF AllZeros THEN DS1820_CRCfailed = 1
;------------------------------------------------------------------------------
;----[show output on LCD]-------------------------------------------------------
ShowLCD:
LOOKUP pid_Channel,[$80,$C0,$89,$C9],Bvar ; Find location
LCDOUT $FE,Bvar,DEC1 pid_Channel+1,"= " ; print to LCD
TempWD = TempC : GOSUB TempToLCD ; display TempC
LCDOUT $DF ; deg symbol
and the select sensor sub
Code:
SelectSensor:
SELECT CASE pid_Channel
CASE 0 : @ DS1820_Select _TempSensor1 ; Select the DS18x20 pin
CASE 1 : @ DS1820_Select _TempSensor2
CASE 2 : @ DS1820_Select _TempSensor3
CASE 3 : @ DS1820_Select _TempSensor4
END SELECT
RETURN
If you need more drop me an e-mail or I can post up more snipets
Bookmarks