Home
Circuits
Microcontrollers
Dual Digital Thermometer

Description
Partlist
Files
Circuits
Microcontrollers
Dual Digital Thermometer
Dual Digital Thermometer
Based on PIC16F877 and DS1820
This thermometer is a simple thermometer using DS1820 thermal probes that have a tolerance within 0.5°C.
I originally wanted a thermometer to monitor temperatures on my over clocked Video Card. Below are some pictures, schematic and PCB layout for the thermometer. The code I used wasn't written by me. It was downloaded from Warburtech (labeled "onewire.bas" near the bottom) and modified to display 2 temperatures instead of one temperature in Celsius and Fahrenheit. Some of the ports were also changed. The modified code I used can be downloaded below. The Circuitmaker 2000 PCB layout can also be downloaded below.
This is my thermometer with the LCD un-socketed. The three holes seen to the left of the 14pin SIP are for a potentiometer if the display you use requires a contrast control. My display did not have this function so I did not have to put a potentiometer on it. However all the connections are there, so if you need a pot for your display one just needs to be soldered in.
This is the picture again of the Thermometer without the display in place. This shot shows how the thermal probes and power are connected.
Here is the display running with probe 1 sitting next to it monitoring ambient house temperature, and the second probe left in the fridge for a couple minutes.
Copyright 2006 Barret R. de Visser
This thermometer is a simple thermometer using DS1820 thermal probes that have a tolerance within 0.5°C.
I originally wanted a thermometer to monitor temperatures on my over clocked Video Card. Below are some pictures, schematic and PCB layout for the thermometer. The code I used wasn't written by me. It was downloaded from Warburtech (labeled "onewire.bas" near the bottom) and modified to display 2 temperatures instead of one temperature in Celsius and Fahrenheit. Some of the ports were also changed. The modified code I used can be downloaded below. The Circuitmaker 2000 PCB layout can also be downloaded below.
This is my thermometer with the LCD un-socketed. The three holes seen to the left of the 14pin SIP are for a potentiometer if the display you use requires a contrast control. My display did not have this function so I did not have to put a potentiometer on it. However all the connections are there, so if you need a pot for your display one just needs to be soldered in.
This is the picture again of the Thermometer without the display in place. This shot shows how the thermal probes and power are connected.
Here is the display running with probe 1 sitting next to it monitoring ambient house temperature, and the second probe left in the fridge for a couple minutes.
Copyright 2006 Barret R. de Visser
Partlist
Files
Comments
Apr 14 2007 20:40
NIKO
Error in the code source! LCD DATA port:
'pour la GESTION du LCD
'lignes données
DEFINE LCD_DREG PORTB 'LCD DATA port: PORTB and not PORTD!
DEFINE LCD_DBIT 4 'LCD data starting bit =4à7 (0 ou 4)
'lignes RS (register select)
DEFINE LCD_RSREG PORTE 'LCD register select port
DEFINE LCD_RSBIT 0 'LCD register select bit ligne RS sur PORTE.0
'lignes Enable port (la ligne E du LCD)
DEFINE LCD_EREG PORTE 'LCD enable port
DEFINE LCD_EBIT 1 'LCD enable bit PORTE.1
'lignes R/W
Low PORTE.2 ' LCD R/W line =low in PORTE.2 (R/W)=0, car pas utilisé !
'fin déclaration des lignes pour la gestion du LCD
'pour la GESTION du LCD
'lignes données
DEFINE LCD_DREG PORTB 'LCD DATA port: PORTB and not PORTD!
DEFINE LCD_DBIT 4 'LCD data starting bit =4à7 (0 ou 4)
'lignes RS (register select)
DEFINE LCD_RSREG PORTE 'LCD register select port
DEFINE LCD_RSBIT 0 'LCD register select bit ligne RS sur PORTE.0
'lignes Enable port (la ligne E du LCD)
DEFINE LCD_EREG PORTE 'LCD enable port
DEFINE LCD_EBIT 1 'LCD enable bit PORTE.1
'lignes R/W
Low PORTE.2 ' LCD R/W line =low in PORTE.2 (R/W)=0, car pas utilisé !
'fin déclaration des lignes pour la gestion du LCD
Apr 16 2007 11:00
Jospfh
Thanks a lot NIKO!
I hope you will send me the modified code soon, so I can add it to the files for this circuit!
I hope you will send me the modified code soon, so I can add it to the files for this circuit!
Apr 22 2007 19:11
NIKO
' Regulation d'un chauffe eau solaire avec gestion LCD (4bits HD44780LCD)
' Nicolas RISTOVSKI, code source modifié
DEFINE OSC 20 ' frequence du quartz = 4MHz
trisc = %01111111 'Set all of portC to inputs except C.7 (7...0)
temperature VAR WORD ' variable Temperature storage cuve
temperature1 VAR WORD ' variable Temperature1 storage panneaux solaires
flag VAR WORD ' flag , variable consigne temp. delta=10°C
flag=0 ' flag=1 ssi température ext. > cuve+10°C
count_remain VAR BYTE ' Count remaining
count_per_c VAR BYTE ' Count per degree C
DQ VAR PORTC.0 ' One-wire data pin storage cuve , sonde DS1820
DQ1 VAR PORTC.1 ' one-wire data pin panneaux solaires , sonde DS1820
OUTPUT PORTC.7 'au cas ou , on force portC.7 en sortie
POMPE VAR PORTC.7 ' PORTC.7 affecté pour activation POMPE
POMPE=0 ' C.7=0 (POMPE est à l'arret)
ID VAR BYTE[8] ' Array storage variable for 64-bit ROM code DS1820 cuve
ID1 VAR BYTE[8] ' Array storage variable for 64-bit ROM code DS1820 solaire
'pour la GESTION du LCD
'lignes données
DEFINE LCD_DREG PORTB 'LCD DATA port: PORTB
DEFINE LCD_DBIT 4 'LCD data starting bit =4à7 (0 ou 4)
'lignes RS (register select)
DEFINE LCD_RSREG PORTE 'LCD register select port
DEFINE LCD_RSBIT 0 'LCD register select bit ligne RS sur PORTE.0
'lignes Enable port (la ligne E du LCD)
DEFINE LCD_EREG PORTE 'LCD enable port
DEFINE LCD_EBIT 1 'LCD enable bit PORTE.1
'lignes R/W
Low PORTE.2 ' LCD R/W line =low in PORTE.2 (R/W)=0, car pas utilisé !
'fin déclaration des lignes pour la gestion du LCD
ADCON1 = 7 ' Set PORTA et PORTE à digital
'presntation
LCDOut $fe, 1, "Thermostat 1820"
'PAUSE 500
LCDOut $fe, 1, "par RISTOVSKI"
LCDOUT $FE, $C0 , "Nicolas..."
'PAUSE 500
LCDOut $fe, 1, "Autoscan sondes"
LCDOUT $FE, $C0, "DS1820 ..."
PAUSE 500
'Identification des capteurs DS1820
OWOUT DQ, 1, [$33] ' Issue Read ROM command sonde cuve
OWOUT DQ1, 1, [$33] ' Issue Read ROM command sonde solaire
OWIN DQ, 0, [STR ID\8]' Read 64-bit device data into the 8-byte array "ID"
OWIN DQ1, 0, [STR ID1\8]' Read 64-bit device data into the 8-byte array "ID1"
'Affiche capteur cuve
IF (ID[0] = $28) OR (ID[0] = $22) THEN
LCDOut $fe, 1, "Cuve Sonde OK"
PAUSE 500
LCDOut $fe, $C0,HEX2 ID[1],HEX2 ID[2],HEX2 ID[3],HEX2 ID[4],HEX2 ID[5],HEX2 ID[6],"h"
PAUSE 500
ELSE
LCDOut $fe, 1, "Cuve Sonde HS"
PAUSE 500
ENDIF
'Affiche capteur solaire
IF (ID1[0] = $28) OR (ID1[0] = $22) THEN
LCDOut $fe, 1, "Sonde Solaire OK"
PAUSE 500
LCDOut $fe,$C0,HEX2 ID1[1],HEX2 ID1[2],HEX2 ID1[3],HEX2 ID1[4],HEX2 ID1[5],HEX2 ID1[6],"h"
PAUSE 500
ELSE
LCDOut $fe, 1, "Sonde Solaire HS"
PAUSE 500
ENDIF
mainloop: OWOut DQ, 1, [$CC, $44] ' Start temperature conversion
OWOut DQ1, 1, [$CC, $44]
waitloop: OWIn DQ, 4, [count_remain] ' Check for still busy converting
OWIn DQ1, 4, [count_remain]
IF count_remain = 0 Then waitloop
'OWOUT ,1 = send reset pulse after data 1 wire
'OWIN ,1 = send reset pulse before data 1 wire
'LCDOUT $FE, 1 Clear display
OWOut DQ, 1, [$CC, $BE] ' Read the temperature DS1820
OWIn DQ, 0, [temperature.LOWBYTE, temperature.HIGHBYTE, Skip 4, count_remain, count_per_c]
temperature = (((temperature >> 1) * 100) - 25) + (((count_per_c - count_remain) * 100) / count_per_c)
LCDOut $fe, 1, "Cuve: ", DEC (temperature / 100), ".", DEC2 temperature, %11011111, "C"
OWOut DQ1, 1, [$CC, $BE] ' Read the temperature1 DS1820
OWIn DQ1, 0, [temperature1.LOWBYTE, temperature1.HIGHBYTE, Skip 4, count_remain, count_per_c]
temperature1 = (((temperature1 >> 1) * 100) - 25) + (((count_per_c - count_remain) * 100) / count_per_c)
LCDOut $fe, $c0 , "Solar: ", DEC (temperature1 / 100), ".", DEC2 temperature1, %11011111, "C"
Pause 500 ' Affichage pendant 1/2 seconde
IF POMPE=0 then
LCDOut $fe, 1, "POMPE OFF-LINE"
PAUSE 500
ENDIF
IF POMPE=1 then
LCDOut $fe, 1, "POMPE ON-LINE"
PAUSE 500
ENDIF
'PORTC.7 Activation de la pompe en PORTC.7 ?
IF (temperature1) >= (temperature+10) then 'si sun >= cuve+10° , pompe=1 et flag=1
POMPE=1
FLAG=1
ENDIF
IF (temperature1) >= (temperature) AND FLAG=1 then 'si sun >= cuve , et flag=1, alors pompe=1
POMPE=1
ELSe
pompe=0
ENDIF
IF (temperature1) < (temperature) AND FLAG=1 then 'si sun < cuve , pompe=0
POMPE=0
Flag=0
ENDIF
IF (temperature1) < (3) then 'risque de gel , pompe=0 car sinon la pompe casse
POMPE=0
FLAG=0
ENDIF
IF (temperature1) < (3) then
LCDOut $fe, 1, "MODE GEL a T<3°C"
PAUSE 500
ENDIF
GoTo mainloop ' boucle infinie
' Nicolas RISTOVSKI, code source modifié
DEFINE OSC 20 ' frequence du quartz = 4MHz
trisc = %01111111 'Set all of portC to inputs except C.7 (7...0)
temperature VAR WORD ' variable Temperature storage cuve
temperature1 VAR WORD ' variable Temperature1 storage panneaux solaires
flag VAR WORD ' flag , variable consigne temp. delta=10°C
flag=0 ' flag=1 ssi température ext. > cuve+10°C
count_remain VAR BYTE ' Count remaining
count_per_c VAR BYTE ' Count per degree C
DQ VAR PORTC.0 ' One-wire data pin storage cuve , sonde DS1820
DQ1 VAR PORTC.1 ' one-wire data pin panneaux solaires , sonde DS1820
OUTPUT PORTC.7 'au cas ou , on force portC.7 en sortie
POMPE VAR PORTC.7 ' PORTC.7 affecté pour activation POMPE
POMPE=0 ' C.7=0 (POMPE est à l'arret)
ID VAR BYTE[8] ' Array storage variable for 64-bit ROM code DS1820 cuve
ID1 VAR BYTE[8] ' Array storage variable for 64-bit ROM code DS1820 solaire
'pour la GESTION du LCD
'lignes données
DEFINE LCD_DREG PORTB 'LCD DATA port: PORTB
DEFINE LCD_DBIT 4 'LCD data starting bit =4à7 (0 ou 4)
'lignes RS (register select)
DEFINE LCD_RSREG PORTE 'LCD register select port
DEFINE LCD_RSBIT 0 'LCD register select bit ligne RS sur PORTE.0
'lignes Enable port (la ligne E du LCD)
DEFINE LCD_EREG PORTE 'LCD enable port
DEFINE LCD_EBIT 1 'LCD enable bit PORTE.1
'lignes R/W
Low PORTE.2 ' LCD R/W line =low in PORTE.2 (R/W)=0, car pas utilisé !
'fin déclaration des lignes pour la gestion du LCD
ADCON1 = 7 ' Set PORTA et PORTE à digital
'presntation
LCDOut $fe, 1, "Thermostat 1820"
'PAUSE 500
LCDOut $fe, 1, "par RISTOVSKI"
LCDOUT $FE, $C0 , "Nicolas..."
'PAUSE 500
LCDOut $fe, 1, "Autoscan sondes"
LCDOUT $FE, $C0, "DS1820 ..."
PAUSE 500
'Identification des capteurs DS1820
OWOUT DQ, 1, [$33] ' Issue Read ROM command sonde cuve
OWOUT DQ1, 1, [$33] ' Issue Read ROM command sonde solaire
OWIN DQ, 0, [STR ID\8]' Read 64-bit device data into the 8-byte array "ID"
OWIN DQ1, 0, [STR ID1\8]' Read 64-bit device data into the 8-byte array "ID1"
'Affiche capteur cuve
IF (ID[0] = $28) OR (ID[0] = $22) THEN
LCDOut $fe, 1, "Cuve Sonde OK"
PAUSE 500
LCDOut $fe, $C0,HEX2 ID[1],HEX2 ID[2],HEX2 ID[3],HEX2 ID[4],HEX2 ID[5],HEX2 ID[6],"h"
PAUSE 500
ELSE
LCDOut $fe, 1, "Cuve Sonde HS"
PAUSE 500
ENDIF
'Affiche capteur solaire
IF (ID1[0] = $28) OR (ID1[0] = $22) THEN
LCDOut $fe, 1, "Sonde Solaire OK"
PAUSE 500
LCDOut $fe,$C0,HEX2 ID1[1],HEX2 ID1[2],HEX2 ID1[3],HEX2 ID1[4],HEX2 ID1[5],HEX2 ID1[6],"h"
PAUSE 500
ELSE
LCDOut $fe, 1, "Sonde Solaire HS"
PAUSE 500
ENDIF
mainloop: OWOut DQ, 1, [$CC, $44] ' Start temperature conversion
OWOut DQ1, 1, [$CC, $44]
waitloop: OWIn DQ, 4, [count_remain] ' Check for still busy converting
OWIn DQ1, 4, [count_remain]
IF count_remain = 0 Then waitloop
'OWOUT ,1 = send reset pulse after data 1 wire
'OWIN ,1 = send reset pulse before data 1 wire
'LCDOUT $FE, 1 Clear display
OWOut DQ, 1, [$CC, $BE] ' Read the temperature DS1820
OWIn DQ, 0, [temperature.LOWBYTE, temperature.HIGHBYTE, Skip 4, count_remain, count_per_c]
temperature = (((temperature >> 1) * 100) - 25) + (((count_per_c - count_remain) * 100) / count_per_c)
LCDOut $fe, 1, "Cuve: ", DEC (temperature / 100), ".", DEC2 temperature, %11011111, "C"
OWOut DQ1, 1, [$CC, $BE] ' Read the temperature1 DS1820
OWIn DQ1, 0, [temperature1.LOWBYTE, temperature1.HIGHBYTE, Skip 4, count_remain, count_per_c]
temperature1 = (((temperature1 >> 1) * 100) - 25) + (((count_per_c - count_remain) * 100) / count_per_c)
LCDOut $fe, $c0 , "Solar: ", DEC (temperature1 / 100), ".", DEC2 temperature1, %11011111, "C"
Pause 500 ' Affichage pendant 1/2 seconde
IF POMPE=0 then
LCDOut $fe, 1, "POMPE OFF-LINE"
PAUSE 500
ENDIF
IF POMPE=1 then
LCDOut $fe, 1, "POMPE ON-LINE"
PAUSE 500
ENDIF
'PORTC.7 Activation de la pompe en PORTC.7 ?
IF (temperature1) >= (temperature+10) then 'si sun >= cuve+10° , pompe=1 et flag=1
POMPE=1
FLAG=1
ENDIF
IF (temperature1) >= (temperature) AND FLAG=1 then 'si sun >= cuve , et flag=1, alors pompe=1
POMPE=1
ELSe
pompe=0
ENDIF
IF (temperature1) < (temperature) AND FLAG=1 then 'si sun < cuve , pompe=0
POMPE=0
Flag=0
ENDIF
IF (temperature1) < (3) then 'risque de gel , pompe=0 car sinon la pompe casse
POMPE=0
FLAG=0
ENDIF
IF (temperature1) < (3) then
LCDOut $fe, 1, "MODE GEL a T<3°C"
PAUSE 500
ENDIF
GoTo mainloop ' boucle infinie
Apr 26 2007 21:10
NIKO
' Thermostat differentiel avec delta = 10°C
' Si Solair>=Cuve+10 alors POMPE=1 sinon POMPE=0
' Regulation d'un chauffe eau solaire avec gestion LCD (4bits HD44780LCD)
' Nicolas RISTOVSKI, code source modifié v4
'PIC 16F877 , PIC BASIC PRO v2.47
'
DEFINE OSC 20 ' frequence du quartz = 20MHz
trisc = %01111111 'Set all of portC to inputs except C.7 (7...0)
temperature VAR WORD ' variable Temperature storage cuve
temperature1 VAR WORD ' variable Temperature1 storage panneaux solaires
flag VAR WORD ' flag , variable consigne temp. delta=10°C
flag=0 ' flag=1 ssi température ext. > cuve+10°C
count_remain VAR BYTE ' Count remaining
count_per_c VAR BYTE ' Count per degree C
count_remain1 VAR BYTE ' Count remaining1
count_per_c1 VAR BYTE ' Count per degree C1
DQ VAR PORTC.0 ' One-wire data pin storage cuve , sonde DS1820
DQ1 VAR PORTC.1 ' one-wire data pin panneaux solaires , sonde DS1820
OUTPUT PORTC.7 'au cas ou , on force portC.7 en sortie
POMPE VAR PORTC.7 ' PORTC.7 affecté pour activation POMPE
POMPE=0 ' C.7=0 (POMPE est à l'arret)
ID VAR BYTE[8] ' Array storage variable for 64-bit ROM code DS1820 cuve
ID1 VAR BYTE[8] ' Array storage variable for 64-bit ROM code DS1820 solaire
'pour la GESTION du LCD
'lignes données
DEFINE LCD_DREG PORTB 'LCD DATA port: PORTB
DEFINE LCD_DBIT 4 'LCD data starting bit =4à7 (0 ou 4)
'lignes RS (register select)
DEFINE LCD_RSREG PORTE 'LCD register select port
DEFINE LCD_RSBIT 0 'LCD register select bit ligne RS sur PORTE.0
'lignes Enable port (la ligne E du LCD)
DEFINE LCD_EREG PORTE 'LCD enable port
DEFINE LCD_EBIT 1 'LCD enable bit PORTE.1
'lignes R/W
Low PORTE.2 ' LCD R/W line =low in PORTE.2 (R/W)=0, car pas utilisé !
'fin déclaration des lignes pour la gestion du LCD
ADCON1 = 7 ' Set PORTA et PORTE à digital
'presentation
LCDOut $fe, 1, "Thermostat 1820"
'PAUSE 500
LCDOut $fe, 1, "par RISTOVSKI"
LCDOUT $FE, $C0 , "Nicolas..."
'PAUSE 500
LCDOut $fe, 1, "scan des sondes"
LCDOUT $FE, $C0, "DS1820 ..."
PAUSE 500
'Identification des capteurs DS1820
OWOUT DQ, 1, [$33] ' Issue Read ROM command sonde cuve
OWOUT DQ1, 1, [$33] ' Issue Read ROM command sonde solaire
OWIN DQ, 0, [STR ID\8]' Read 64-bit device data into the 8-byte array "ID"
OWIN DQ1, 0, [STR ID1\8]' Read 64-bit device data into the 8-byte array "ID1"
'Affiche capteur cuve
IF (ID[0] = $28) OR (ID[0] = $22) OR (ID[0] = $10) THEN
LCDOut $fe, 1, "Cuve Sonde OK"
PAUSE 500
LCDOut $fe, $C0,HEX2 ID[1],HEX2 ID[2],HEX2 ID[3],HEX2 ID[4],HEX2 ID[5],HEX2 ID[6],"h"
PAUSE 500
ELSE
LCDOut $fe, 1, "Cuve Sonde HS"
PAUSE 500
ENDIF
'Affiche capteur solaire
IF (ID1[0] = $28) OR (ID1[0] = $22) OR (ID[0] = $10) THEN
LCDOut $fe, 1, "Sonde Solaire OK"
PAUSE 500
LCDOut $fe,$C0,HEX2 ID1[1],HEX2 ID1[2],HEX2 ID1[3],HEX2 ID1[4],HEX2 ID1[5],HEX2 ID1[6],"h"
PAUSE 500
ELSE
LCDOut $fe, 1, "Sonde Solaire HS"
PAUSE 500
ENDIF
LCDOut $fe, 1, " "
mainloop: OWOut DQ, 1, [$CC, $44] ' Start temperature conversion
OWOut DQ1, 1, [$CC, $44]
waitloop: OWIn DQ, 4, [count_remain] ' Check for still busy converting
OWIn DQ1, 4, [count_remain1]
IF count_remain = 0 AND count_remain1 = 0 Then waitloop
'OWOUT ,1 = send reset pulse after data 1 wire
'OWIN ,1 = send reset pulse before data 1 wire
'LCDOUT $FE, 1 Clear display
OWOut DQ, 1, [$CC, $BE] ' Read the temperature DS1820
OWIn DQ, 0, [temperature.LOWBYTE, temperature.HIGHBYTE, Skip 4, count_remain, count_per_c]
temperature = (((temperature >> 1) * 100) - 25) + (((count_per_c - count_remain) * 100) / count_per_c)
LCDOut $fe, 1, "Cuve: ", DEC (temperature / 100), ".", DEC2 temperature, %11011111, "C"
OWOut DQ1, 1, [$CC, $BE] ' Read the temperature1 DS1820
OWIn DQ1, 0, [temperature1.LOWBYTE, temperature1.HIGHBYTE, Skip 4, count_remain1, count_per_c1]
temperature1 = (((temperature1 >> 1) * 100) - 25) + (((count_per_c1 - count_remain1) * 100) / count_per_c1)
LCDOut $fe, $c0 , "Solar: ", DEC (temperature1 / 100), ".", DEC2 temperature1, %11011111, "C"
Pause 500 ' Affichage pendant 1/2 seconde
IF POMPE=0 then
LCDOut $fe, 1, "POMPE OFF-LINE"
PAUSE 500
ENDIF
IF POMPE=1 then
LCDOut $fe, 1, "POMPE ON-LINE"
PAUSE 500
ENDIF
'PORTC.7 Activation de la pompe en PORTC.7 ?
IF (temperature1) >= (temperature+10) then 'si sun >= cuve+10° , pompe=1 et flag=1
POMPE=1
FLAG=1
ENDIF
IF (temperature1) >= (temperature) AND FLAG=1 then 'si sun >= cuve , et flag=1, alors pompe=1
POMPE=1
ELSe
pompe=0
ENDIF
IF (temperature1) < (temperature) AND FLAG=1 then 'si sun < cuve , pompe=0
POMPE=0
Flag=0
ENDIF
IF (temperature1) < (3) then 'risque de gel , pompe=0 car sinon la pompe casse
POMPE=0
FLAG=0
ENDIF
IF (temperature1) < (3) then
LCDOut $fe, 1, "MODE GEL a T<3°C"
LCDOut $fe, $c0 , "POMPE OFF-LINE"
PAUSE 500
ENDIF
GoTo mainloop ' boucle infinie
' Si Solair>=Cuve+10 alors POMPE=1 sinon POMPE=0
' Regulation d'un chauffe eau solaire avec gestion LCD (4bits HD44780LCD)
' Nicolas RISTOVSKI, code source modifié v4
'PIC 16F877 , PIC BASIC PRO v2.47
'
DEFINE OSC 20 ' frequence du quartz = 20MHz
trisc = %01111111 'Set all of portC to inputs except C.7 (7...0)
temperature VAR WORD ' variable Temperature storage cuve
temperature1 VAR WORD ' variable Temperature1 storage panneaux solaires
flag VAR WORD ' flag , variable consigne temp. delta=10°C
flag=0 ' flag=1 ssi température ext. > cuve+10°C
count_remain VAR BYTE ' Count remaining
count_per_c VAR BYTE ' Count per degree C
count_remain1 VAR BYTE ' Count remaining1
count_per_c1 VAR BYTE ' Count per degree C1
DQ VAR PORTC.0 ' One-wire data pin storage cuve , sonde DS1820
DQ1 VAR PORTC.1 ' one-wire data pin panneaux solaires , sonde DS1820
OUTPUT PORTC.7 'au cas ou , on force portC.7 en sortie
POMPE VAR PORTC.7 ' PORTC.7 affecté pour activation POMPE
POMPE=0 ' C.7=0 (POMPE est à l'arret)
ID VAR BYTE[8] ' Array storage variable for 64-bit ROM code DS1820 cuve
ID1 VAR BYTE[8] ' Array storage variable for 64-bit ROM code DS1820 solaire
'pour la GESTION du LCD
'lignes données
DEFINE LCD_DREG PORTB 'LCD DATA port: PORTB
DEFINE LCD_DBIT 4 'LCD data starting bit =4à7 (0 ou 4)
'lignes RS (register select)
DEFINE LCD_RSREG PORTE 'LCD register select port
DEFINE LCD_RSBIT 0 'LCD register select bit ligne RS sur PORTE.0
'lignes Enable port (la ligne E du LCD)
DEFINE LCD_EREG PORTE 'LCD enable port
DEFINE LCD_EBIT 1 'LCD enable bit PORTE.1
'lignes R/W
Low PORTE.2 ' LCD R/W line =low in PORTE.2 (R/W)=0, car pas utilisé !
'fin déclaration des lignes pour la gestion du LCD
ADCON1 = 7 ' Set PORTA et PORTE à digital
'presentation
LCDOut $fe, 1, "Thermostat 1820"
'PAUSE 500
LCDOut $fe, 1, "par RISTOVSKI"
LCDOUT $FE, $C0 , "Nicolas..."
'PAUSE 500
LCDOut $fe, 1, "scan des sondes"
LCDOUT $FE, $C0, "DS1820 ..."
PAUSE 500
'Identification des capteurs DS1820
OWOUT DQ, 1, [$33] ' Issue Read ROM command sonde cuve
OWOUT DQ1, 1, [$33] ' Issue Read ROM command sonde solaire
OWIN DQ, 0, [STR ID\8]' Read 64-bit device data into the 8-byte array "ID"
OWIN DQ1, 0, [STR ID1\8]' Read 64-bit device data into the 8-byte array "ID1"
'Affiche capteur cuve
IF (ID[0] = $28) OR (ID[0] = $22) OR (ID[0] = $10) THEN
LCDOut $fe, 1, "Cuve Sonde OK"
PAUSE 500
LCDOut $fe, $C0,HEX2 ID[1],HEX2 ID[2],HEX2 ID[3],HEX2 ID[4],HEX2 ID[5],HEX2 ID[6],"h"
PAUSE 500
ELSE
LCDOut $fe, 1, "Cuve Sonde HS"
PAUSE 500
ENDIF
'Affiche capteur solaire
IF (ID1[0] = $28) OR (ID1[0] = $22) OR (ID[0] = $10) THEN
LCDOut $fe, 1, "Sonde Solaire OK"
PAUSE 500
LCDOut $fe,$C0,HEX2 ID1[1],HEX2 ID1[2],HEX2 ID1[3],HEX2 ID1[4],HEX2 ID1[5],HEX2 ID1[6],"h"
PAUSE 500
ELSE
LCDOut $fe, 1, "Sonde Solaire HS"
PAUSE 500
ENDIF
LCDOut $fe, 1, " "
mainloop: OWOut DQ, 1, [$CC, $44] ' Start temperature conversion
OWOut DQ1, 1, [$CC, $44]
waitloop: OWIn DQ, 4, [count_remain] ' Check for still busy converting
OWIn DQ1, 4, [count_remain1]
IF count_remain = 0 AND count_remain1 = 0 Then waitloop
'OWOUT ,1 = send reset pulse after data 1 wire
'OWIN ,1 = send reset pulse before data 1 wire
'LCDOUT $FE, 1 Clear display
OWOut DQ, 1, [$CC, $BE] ' Read the temperature DS1820
OWIn DQ, 0, [temperature.LOWBYTE, temperature.HIGHBYTE, Skip 4, count_remain, count_per_c]
temperature = (((temperature >> 1) * 100) - 25) + (((count_per_c - count_remain) * 100) / count_per_c)
LCDOut $fe, 1, "Cuve: ", DEC (temperature / 100), ".", DEC2 temperature, %11011111, "C"
OWOut DQ1, 1, [$CC, $BE] ' Read the temperature1 DS1820
OWIn DQ1, 0, [temperature1.LOWBYTE, temperature1.HIGHBYTE, Skip 4, count_remain1, count_per_c1]
temperature1 = (((temperature1 >> 1) * 100) - 25) + (((count_per_c1 - count_remain1) * 100) / count_per_c1)
LCDOut $fe, $c0 , "Solar: ", DEC (temperature1 / 100), ".", DEC2 temperature1, %11011111, "C"
Pause 500 ' Affichage pendant 1/2 seconde
IF POMPE=0 then
LCDOut $fe, 1, "POMPE OFF-LINE"
PAUSE 500
ENDIF
IF POMPE=1 then
LCDOut $fe, 1, "POMPE ON-LINE"
PAUSE 500
ENDIF
'PORTC.7 Activation de la pompe en PORTC.7 ?
IF (temperature1) >= (temperature+10) then 'si sun >= cuve+10° , pompe=1 et flag=1
POMPE=1
FLAG=1
ENDIF
IF (temperature1) >= (temperature) AND FLAG=1 then 'si sun >= cuve , et flag=1, alors pompe=1
POMPE=1
ELSe
pompe=0
ENDIF
IF (temperature1) < (temperature) AND FLAG=1 then 'si sun < cuve , pompe=0
POMPE=0
Flag=0
ENDIF
IF (temperature1) < (3) then 'risque de gel , pompe=0 car sinon la pompe casse
POMPE=0
FLAG=0
ENDIF
IF (temperature1) < (3) then
LCDOut $fe, 1, "MODE GEL a T<3°C"
LCDOut $fe, $c0 , "POMPE OFF-LINE"
PAUSE 500
ENDIF
GoTo mainloop ' boucle infinie


