I don't know proper procedure to insert a subroutine as I have indicated.
Been looking at sample codes trying to decipher why certain sections were inserted where they did. Moved the code around but to no avail.
WHY??
Code: Select all
{
*****************************************************************************
* 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 :compute voltage to temperature. Start with sensor at 50ohms.
* : 180-200 ohms melts solder *
* : *
*****************************************************************************
}
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 deg_s As Word //DESIRED TEMP
Dim drf As Word //DEFROST TIME
Dim TempA As Word
Dim TempB As ShortInt
// Read the AD ports and scale
Function REF_V() As Word
result = (ADC.Read(1) +1) /100 //1024 is divide by tip sensor
End Function
Function sensor() As Word
result = (ADC.Read(0) + 1)/100 // 100 //1024 is divide by temp ref desired
End Function
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
// I need this routine to read the DS18B20 but 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
Public Sub sens_tep()
If DS18B20.Find Then
While True
Convert
GetTemp(TempA, TempB)
// LCD.WriteAt(1,1,"BX temp = "DecToStr(TempA))
Wend
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 = REF_V()
Vsensor = sensor()
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...
LCD.MoveCursor (1,1)
LCD.Write("Desired temp= ", DecToStr(deg_s))
DelayMS(250)
// call function sensor() and assign the result to word variable 'drf'
LCD.MoveCursor (2,1)
LCD.Write("DEFROST = ", DecToStr(drf)," ")
DelayMS(250)
Wend
{
// compare Vsensor and Vref values
If Vsensor < Vref Then // not hot enough
LED_r=1
LED_g=0
Else // Vsensor must be >= Vref, so desired temperature
LED_g=1
LED_r=0
End If
Wend