Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

DS18B20 to display on LCD

Status
Not open for further replies.
I had already found that

the wend if error and changed after I posted the code your referring to. Posted that last night.
Here is my present clusterfXck of code.
The sub is called down in the LCD display section.Bifgraf suggested the sub but still won't compile.
Code:
{
*****************************************************************************
*  Name    : UNTITLED.BAS                                                   *
*  Author  : [select VIEW...EDITOR OPTIONS]                                 *
*  Notice  : Copyright (c) 2011 [select VIEW...EDITOR OPTIONS]              *
*          : All Rights Reserved                                            *
*  Date    : 10/6/2011                                                      *
*  Version : 1.0                                                            *
*  Notes   : The ADC (READ(0) is used for DEFROST TIMER and ADC READ(1) is for
DESIRED TEMPERATURE adjustment.
Need to add LED routine and DEFROST TIME using delayms(drfx10?)
also box temp
*          : 1                                                              *
*          :                                                                *
*****************************************************************************
}
Device = 18F4520
Clock = 20
// some LCD options...
#option LCD_DATA = PORTD.4
#option LCD_RS = PORTD.2
#option LCD_EN = PORTD.3
// uses LCD and AD libraries...
Include "LCD.bas"
Include "ADC.bas"
Include "convert.bas"
Include "DS18B20.bas"
Dim ADVal As Word
Dim LED_g As PORTB.0
Dim LED_r As PORTB.1
Dim Vref As Word
Dim Vsensor As Word
Dim Desired_T As Word          //DESIRED TEMP
//Dim D_Frost As Word          //DEFROST TIME


      
// Read the AD ports and scale 
Function Dsired_T() As Word
 result = (ADC.Read(1) +1) /100  //Read DESIRED TEMP Adjustment
End Function
Function D_frost() As Word
 result = (ADC.Read(0) + 1)/100  // 100  //Read DEFROST TIMER ADJUSTMENT
End Function
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
// I need this routine to read the DS18B20 buit keep getting syntax errors
// the LCD, ADC sections all worked before putting the DS18B20 into the code
//syntax says a sub routine or  or function is expected
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
   SetPin(PORTB.3)                  // sensor pin
 Sub sens_tep()
    dim myTemp as word
    dim TempA as shortint
    dim TempB as word 
        If DS18B20.Find Then 
            DS18B20.Convert
            mytemp = DS18B20.GetTemp()
            LCD.WriteAt(1,1,"BX temp = ",DecToStr(myTemp))
        EndIf
End Sub
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 
// Start Of Program...
Input(PORTA.0)                  // DESIRED TEMP
Input(PORTA.1)                  // DEFROST TIMER
Low (LED_g)                     //set lEDs OFF
Low (LED_r)
ADCON1 = %10000000              //set up ADC regesters
ADCON0.7 = 1
ADCON0.6 = 1

       
DelayMS (150)
LCD.Cls
//========================================================

 While true
        // call function REF_V() and assign the result to word variable 'Vref'
        Vref =Dsired_T ()           //DESIRED TEMP
        Vsensor = D_Frost()       //DEFROST TIMER
             
Select Vref
       Case <1 deg_s = 32
       Case <2 deg_s = 33
       Case <3 deg_s = 34
       Case <4 deg_s = 35
       Case <5 deg_s = 36
       Case <6 deg_s = 37
       Case <7 deg_s = 38
       Case <8 deg_s = 39
       Case <9 deg_s = 40
End Select
Select Vsensor
       Case <1 drf = 10
       Case <2 drf = 12
       Case <3 drf = 14
       Case <4 drf = 16
       Case <5 drf = 17
       Case <6 drf = 19
       Case <7 drf = 21
       Case <8 drf = 23
       Case <9 drf = 25
       
End Select
// main program loop...
 
        sens_tep() 
        LCD.MoveCursor (1,1)
        LCD.Writeat(1,1,"Desired temp= ", DecToStr(deg_s))  // Display DESIRED TEMP
        DelayMS(250)
        
 // call function sensor() and assign the result to word variable 'drf'
       
        LCD.MoveCursor (2,1)
        LCD.Write("DEFROST = ", DecToStr(drf),"    ")   //Display DEFROST TIMER
        DelayMS(250)
        Wend
   LCD.writeAt(2,1,"Bx temp=",dectostr(sens_T)
 
changes to sensor find
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
// FIND SENSOR
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
SetPin(PORTB.3) // sensor pin
if DS18B20.Find then
while true
convert
GetTemp(TempA, TempB)
//LCD.WriteAt(1,1,"BoX temp = "DecToStr(TempA))
wend
endif


now syntax is EXPECTED at last kine?
 
compare sens temp to ADC read

Been doing something wrong. I figured myTemp = should have done it?



Code:
NoInline   Sub sens_tep()
        Dim myTemp As Word
        Dim TempA As ShortInt
        Dim TempB As Word
            If DS18B20.Find Then
            While true
                DS18B20.Convert
                DS18B20.GetTemp(TempA,TempB)
                LCD.Cls
                LCD.WriteAt(1,1,"bx temp",DecToStr(TempA),".",DecToStr(TempB,1), "'C    ") // displays temp in C
                myTemp = (DecToStr(TempA),".",DecToStr(TempB,1))     // trying to compare to deg_s (ADC.read(1)
                DelayMS(3000)
              //  LCD.writeat(1,1,dectostr( TempB))
              //  delayms(3000)
             if myTemp > deg_s
             then
                  LED_g = 1
                  LED_r=0
             else  
                 LED_g = 0
                  LED_r=1
             end if
            
         
                Exit
                Wend
            EndIf
   End Sub
 
Mrdeb your code needs to be like this
Code:
While true
    Gettemp // sub to get the temp
 //   Do something with the temp reading
    Lcdwrite
    Blink led here
Wend
 
Kinda what I did

I added a DELAYMS(1000 * drf) then when the LED_r is on which indicates the box temp is at or below the DESIRED TEMP. The drf is derivd from the ADC input for DEFROST TIMER. The DEFROST TIMER is set at 2 miniute increments (10, 12, 14etc). Not real sure it works as It needs futher testing. Contemplated using a FOR NEXT LOOP or just INC a counter until COUNTER = drf.
Code:
Public Sub sens_temp()     
       
        Dim TempA As ShortInt
        Dim TempB As Word
      
            If DS18B20.Find Then
                DS18B20.Convert
                DS18B20.GetTemp(TempA,TempB)
                LCD.Cls
                LCD.WriteAt(1,1,"bx temp",DecToStr(TempA),".",DecToStr(TempB,1), "'C    ") // displays temp in C box temp
                DelayMS(3000)

// just uncomment the line below, it will convert C to F
       
             TempA = TempA * 9 / 5 + 32                //tempA is box temp
             If TempA < deg_s Then
                  LED_g = 0                              // cooling off
                  LED_r=1                                //defrost cycle
                 
              DelayMS(1000*drf)                          //defrost cycle timer time = dfx X 1000
           
                  
                 Else 
                  LED_g = 1                              //cooler on
                  LED_r = 0
             EndIf
            EndIf
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top