Darrel,
Thanks for your input - with your prior knowledge of this project I thought you would be best placed to know what is going on.
OK I'll be perfectly honest, I'm not 100% sure where I would need to place the CLRWDT commands, so here is the main program loop
Code:
;-----------------------------------------------------------------------------
; ***** MAIN PROGRAMMING LOOP *****
;-----------------------------------------------------------------------------
Main:
If SetButton=0 then ; jump to programming
Gosub SetButtonRelease
goto mainmenu
endif
If DecButton=0 then
Gosub SetButtonRelease
goto lightoveride ; manual overide of light
endif
If IncButton=0 then
Gosub SetButtonRelease
goto cancelalarm ; manual overide of alarm
endif
FOR pid_Channel = 0 TO 3 ; cycle thru all sensors
GOSUB SelectSensor
GIE = 0 ; disable interrupts before 1-wire
@ DS1820_Convert ; start a temperature conversion
GIE = 1 ; enable interrupts after 1-wire
NEXT pid_Channel
;----[check for data on com port]
FOR TempWD = 0 TO 10000
IF RCIF THEN GOto coms
PauseUs 100
NEXT TempWD
;--------------------------------
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
; ---------------------------------------------------------------------------
; check lighting periods and turn lights on or off accordingly
; ---------------------------------------------------------------------------
fn = 0 ; select the first Lights
if lightover = 0 then GOSUB CheckTimes ; if manual override set to off then go compare the programed period
if lightover = 1 then progON=1 ; if manual override flag set to on then lights on flag set to 1
IF ProgON THEN ; If in the program period
IF Lights1 = 0 THEN Lights1 = 1
ELSE
IF Lights1 = 1 THEN Lights1 = 0
IF Lights1 = 0 then LCDOut $FE, $94+9," "
ENDIF
fn = 1 ; select the second Lights
if lightover = 0 then GOSUB CheckTimes ; compare the programed period
IF ProgON THEN
IF Lights2 = 0 THEN Lights2 = 1
ELSE
IF Lights2 = 1 THEN Lights2 = 0
LCDOut $FE, $94+9," "
ENDIF
IF Lights1 = 1 then LCDOut $FE, $94+9,"Light 1 ON"
IF Lights2 = 1 then LCDOut $FE, $94+9,"Light 2 ON"
if Lights1 = 1 and Lights2 = 1 then LCDOut $FE, $94+9,"Lights ON "
If Lights1 = 0 and Lights2 = 0 then LCDOut $FE, $94+9," "
; ---------------------------------------------------------------------------
; Check for night time drops - if condition matched, drop temp
; ---------------------------------------------------------------------------
fn = 0 ; select the first setting
GOSUB CheckTimes2 ; compare the programed period
IF ProgON2 THEN
SetPoints[0]=Droptemp[0] ; change the corresponding set point to the drop temperature
LCDOut $FE, $94,"Night"
ELSE
SetPoints[0]= normtemp[0] ; change the corresponding drop temperature to set point
LCDOut $FE, $94," "
ENDIF
fn = 1 ; select the second setting
GOSUB CheckTimes2 ; compare the programed period
IF ProgON2 THEN
SetPoints[1]=Droptemp[1] ; change the corresponding set point to the drop temperature
LCDOut $FE, $94,"Night"
ELSE
SetPoints[1]= normtemp[1] ; change the corresponding drop temperature to set point
LCDOut $FE, $94," "
ENDIF
fn = 2 ; select the third setting
GOSUB CheckTimes2 ; compare the programed period
IF ProgON2 THEN
SetPoints[2]=Droptemp[2] ; change the corresponding set point to the drop temperature
LCDOut $FE, $94,"Night"
ELSE
SetPoints[2]= normtemp[2] ; change the corresponding drop temperature to set point
LCDOut $FE, $94," "
ENDIF
fn = 3 ; select the fouth setting
GOSUB CheckTimes2 ; compare the programed period
IF ProgON2 THEN
SetPoints[3]=Droptemp[3] ; change the corresponding set point to the drop temperature
LCDOut $FE, $94,"Night"
ELSE
Setpoints[3]= normtemp[3] ; change the corresponding drop temperature to set point
LCDOut $FE, $94," "
ENDIF
;----[Flash Star on LCD]-------------------------------------------------------
If alarm=1 then
LCDOUT $FE,$80 + 18,("*"&FlashStar*$FF)|(" "&~(FlashStar*$FF)) ; flash a star to show sample time, but used to indicate Alarm settings monitored
FlashStar = !FlashStar
endif
;-----------------------------------------------------------------------------
; ***** MAIN PROGRAMMING LOOP END *****
GOTO Main
;-----------------------------------------------------------------------------
Could you advise me ??
Thanks
Bookmarks