Dual Thermometer



Dual DS18B20 thermometer

DS18B20 Thermometer schematic

Dual thermometer with Nokia 3310 lcd

Both temperatures, for inside and outside zone, are displayed on a Nokia 3310 lcd. All temperature sensors are in parallel connected with a thin 3 wire 30 AWG cable. Since we have a digital 1-wire communication between microcontroller and sensors, we don't need to use a shilded cable. Temperatures are read at about every 0.8 second.

Download code


Source code file for 2xDS18B20 Thermometer
'*********************************************
'           TERMOMETER DUAL ZONE  
'       DEVICE 16F628A AND DS18B20 x 2
'            http://www.module.ro
'         FOR IN AND OUT TEMPERATURE  
' by Niculescu Dan : niculescu_dann@yahoo.com
' ME JUST PUT TOGHETER PARTS OF CODES WRITTEN
'     BY : IVICA NOVACOVIK,GIANNI,GUSSE
'   FROM http://www.picbasic.co.uk/forum
'   AND IONTOP from my Country - ROMANIA
'  
'        T H A N K S   T O   A L L  !
'**********************************************

Define	NO_CLRWDT 1
DEFINE OSC 4          ' Set oscillatore                  

        TRISB = %11000010        'portB configura direzione  0=out 1=in
        TRISA = %10100010        'portA configura direzione
        PortB = %11110110        'preset uscite   b.3=0
        PortA = %11100010        
        CMCON = 7                'per P16F628
        VRCON = 0                'per P16F628
        INTCON = 0               'spento per adesso
        OPTION_REG = %10000111            
                    
RST         var  PortA.4   'pin 3   Output   reset display
SDIN        var  PortA.3   'pin 2   Output   master data out        
SCK         var  PortA.2   'pin 1   Output   Spi clock
DQ          var  PortA.1   'pin 18  I/O      DQ DS18b20    
D_C         var  PortB.0   'pin 6   Output   command/data sel. register

            
            temperature     Var	 Word			
            TempHigh        var  temperature.highbyte
            TempH           var  byte
            TempL           var  byte
            temperature2     Var	 Word			
            TempHigh2        var  temperature.highbyte
            TempH2           var  byte
            TempL2           var  byte
            Bitovi          var  byte
            Predznak        var  Bitovi.0
            Skala           var  byte[4]
            Minus           var  Byte                   
            LcdReg          var  byte        
            x               var  byte
            y               var  byte
            z               var  byte
            Offset          var  byte
            Char            var  byte
            a               var  byte
            PosX            VAR  Byte
            PosY            VAR  Byte
            Chr             VAR  Byte
            LcdData         VAR  Byte
'-------------------------------------------------------------------------------            
                
                    DATA @0,$3E,$51,$49,$45,$3E,_       ';// 0                  
                            $00,$42,$7F,$40,$00,_       ';// 1
                            $42,$61,$51,$49,$46,_       ';// 2
                            $21,$41,$45,$4B,$31,_       ';// 3
                            $18,$14,$12,$7F,$10,_       ';// 4
                            $27,$45,$45,$45,$39,_       ';// 5
                            $3C,$4A,$49,$49,$30,_       ';// 6
                            $01,$71,$09,$05,$03,_       ';// 7
                            $36,$49,$49,$49,$36,_       ';// 8
                            $06,$49,$49,$29,$1E,_       ';// 9
                            $08,$08,$3E,$08,$08,_       ';// +    10
                            $08,$08,$08,$08,$08,_       ';// -    11
                            $00,$60,$60,$00,$00,_       ';// .    12
                            $01,$01,$7F,$01,$01,_       ' T       13
                            $7F,$49,$49,$49,$41,_       ' E       14
                            $7F,$02,$0C,$02,$7F,_       ' M       15
                            $7F,$09,$09,$09,$06,_       ' P       16
                            $00,$36,$36,$00,$00,_       ' :       17
   				                  $7F,$49,$49,$49,$41,_       ' E       18
                            $00,$41,$7F,$41,$00,_       ' I       19
				                    $7F,$04,$08,$10,$7F,_       ' N       20
                            $63,$14,$08,$14,$63,_       ' X       21
                            $3E,$41,$41,$41,$22,_       ' C       22
                            $00,$02,$05,$05,$02,_       ' simbol grad   23
                            $00,$00,$00,$00,$00         ' SPACE   24

'-------------------------------------------------------------------------------            
                pause 100
                RST = 1
                PortB = 0
                LcdReg  =  %00100001          'LCD Extended Commands.
                call    PrintCtrlLcd
                LcdReg  =  $C8                'Set LCD Vop (Contrast).    initial a fost $c5
                call    PrintCtrlLcd
                LcdReg  =  %00000110          'Set Temp coefficent.
                call    PrintCtrlLcd
                LcdReg  =  %00010011          'LCD bias mode 1:48.
                call    PrintCtrlLcd
                LcdReg  =  %00100000          'LCD Standard Commands, Horizontal addressing mode.
                call    PrintCtrlLcd
                LcdReg  =  $0C                'LCD in normal mode.  

                call    PrintCtrlLcd                 
                call CursorHome

Gosub LCD_Clear

Main:                
'----------------------------------------
' Sensor 1
 OWOut DQ, 1, [$55, $28,  $DD, $06, $49, $1, $0, $0, $D4, $4E, $FF, $FF, $7F] ' Init Sensor 1
 OWOut DQ, 1, [$55, $28,  $DD, $06, $49, $1, $0, $0, $D4, $48] 
 OWOut DQ, 1, [$55, $28,  $DD, $06, $49, $1, $0, $0, $D4, $B8] 
 OWOut DQ, 1, [$55, $28,  $DD, $06, $49, $1, $0, $0, $D4, $BE] 
Pause 50
 OWIn DQ, 2, [temperature.byte0, temperature.byte1]
Pause 50
 
'------------------------------------------
' Sensor 2 
 OWOut DQ, 1, [$55, $28,  $EB, $EA, $48, $1, $0, $0, $FF, $4E, $FF, $FF, $7F] ' Init Sensor 2
 OWOut DQ, 1, [$55, $28,  $EB, $EA, $48, $1, $0, $0, $FF, $48] 
 OWOut DQ, 1, [$55, $28,  $EB, $EA, $48, $1, $0, $0, $FF, $B8] 
 OWOut DQ, 1, [$55, $28,  $EB, $EA, $48, $1, $0, $0, $FF, $BE] 
Pause 50
 OWIn DQ, 2, [temperature2.byte0, temperature2.byte1] 
Pause 50

'------------------------------------------

Part1:	
 OWOut DQ, 1, [$55, $28,  $DD, $06, $49, $1, $0, $0, $D4, $44] ' Start temp. conversion Sensor1
 OWOut DQ, 1, [$55, $28,  $DD, $06, $49, $1, $0, $0, $D4, $BE]
 OWIn DQ, 2, [temperature.byte0, temperature.byte1]             
                Predznak = 0
                if  TempHigh.7 = 1 then  
                    temperature  = ~ temperature + 1 
                    Predznak = 1 
                endif    
                TempH = temperature >> 4
                Templ = temperature.lowbyte & $0f
                Temperature = templ * 625
                OWOut DQ, 1, [$CC, $44]         
'---------------setting cursor for text "TEMP.INT :"
                LcdReg  =  %10000000            ' cursor  X  
                call    PrintCtrlLcd
                LcdReg  =  %01000000            ' cursor  Y
                call    PrintCtrlLcd

                Char = 13
                call    PrintChar           
                Char = 14
                call    PrintChar
                Char = 15
                call    PrintChar                
                Char = 16
                call    PrintChar
                Char = 12
                call    PrintChar                
                Char = 19
                call    PrintChar
                Char = 20
                call    PrintChar                
                Char = 13
                call    PrintChar
                Char = 17
                call    PrintChar
'---------------setting cursor for display the temperature 1
                LcdReg  =  %10100000 + 10       ' cursor  X
                call    PrintCtrlLcd
                LcdReg  =  %01000001            ' cursor  Y
                call    PrintCtrlLcd
'---------------now display temperature 1
                    if TempH > 99 then             
                        Char = 1                
                        call    PrintChar
                    else    
                        Char = 10                        ' + plus
                        if Predznak = 1 then Char = 11  ' - minus
                        call    PrintChar
                    endif                  
                
                Char = (temph dig 1)            
                call    PrintChar
                Char = (temph dig 0)            
                call    PrintChar
                Char = 12                       
                call    PrintChar
                Char = (temperature dig 3)      
                Call    PrintChar 
                Char = 23
                call    PrintChar 
                Char = 22
                call    PrintChar

'-----------------------------------
Part2 :	
OWOut DQ, 1, [$55, $28, $EB, $EA, $48, $1, $0, $0, $FF, $44]  ' Start temp. conversion Sensor2
OWOut DQ, 1, [$55, $28, $EB, $EA, $48, $1, $0, $0, $FF, $BE]
OWIn DQ, 2, [Temperature2.Byte0, Temperature2.Byte1]          
                Predznak = 0
                if  TempHigh.7 = 1 then  
                    temperature2  = ~ temperature2 + 1 
                    Predznak = 1 
                endif    
                TempH = temperature2 >> 4
                Templ = temperature2.lowbyte & $0f
                Temperature2 = templ * 625    
                OWOut DQ, 1, [$CC, $44] 
'---------------setting cursor for text "TEMP.EXT :"    
                LcdReg  =  %10000000            ' cursor  X  
                call    PrintCtrlLcd
                LcdReg  =  %01000011            ' cursor  Y 
                call    PrintCtrlLcd

                Char = 13
                call    PrintChar              
                Char = 14
                call    PrintChar                
                Char = 15
                call    PrintChar                
                Char = 16
                call    PrintChar
                Char = 12
                call    PrintChar
                Char = 18
                call    PrintChar
                Char = 21
                call    PrintChar
                Char = 13
                call    PrintChar
                Char = 17
                call    PrintChar
'---------------setting cursor for display the temperature 2
                LcdReg  =  %10100000 + 10       ' cursor  X  
                call    PrintCtrlLcd
                LcdReg  =  %01000100            ' cursor  Y
                call    PrintCtrlLcd
'---------------now display temperature 2
                    if TempH > 99 then             
                        Char = 1                
                        call    PrintChar
                    else    
                        Char = 10                        ' + plus
                        if Predznak = 1 then Char = 11  ' - minus
                        call    PrintChar
                    endif                     
                
                Char = (temph dig 1)            
                call    PrintChar
                Char = (temph dig 0)            
                call    PrintChar
                Char = 12                       
                call    PrintChar
                Char = (temperature2 dig 3)      
                Call    PrintChar 
                Char = 23
                call    PrintChar 
                Char = 22
                call    PrintChar

goto main              
             
'-------------------------------------------------------------------------------                

CursorHome:     LcdReg  =  %10000000            ' cursor Home
                call    PrintCtrlLcd
                LcdReg  =  %01000000            ' cursor Home
                call    PrintCtrlLcd
                return

PrintChar:   offset = Char * 5          
             
                for a = 1 to 5                
                    read offset, LcdReg
                    call  PrintDataLcd
                    offset = offset + 1
                next a
                LcdReg = 0
                call    PrintDataLcd
                return
                                    
PrintCtrlLcd:   D_C = 0                             
PrintDataLcd:   for x = 1 to 8                
                    SDIN = LcdReg.7              
                    SCK = 1
                    LcdReg = LcdReg << 1
                    SCK = 0
                next x               
                D_C = 1
                return               
                
 LCD_Clear:
  PosX=0:PosY=0:GOSUB LCD_GotoXY
  HIGH D_C
  FOR Chr=1 TO 252
      LcdData=0:GOSUB LCD_ByteOut
      LcdData=0:GOSUB LCD_ByteOut
  NEXT Chr
RETURN

LCD_GotoXY:
  LOW D_C
  LcdData=%01000000 | PosY :GOSUB LCD_ByteOut
  LcdData=%10000000 | PosX :GOSUB LCD_ByteOut
RETURN

LCD_ByteOut:
  SHIFTOUT SDIN,SCK,1,[LcdData]
RETURN         

End         

Links:


Back to my home page