temp probe project using DB18S20

Status
Not open for further replies.

MrDEB

Well-Known Member
Finally getting back to this project.
Started hacking at the code but wondering where to put the math computations discussed at the beginning of this subject?
Tf=(9xTc / 5 + 32 something to do with floating integers?
Another question is TEMP A and TEMP B variables. I have TEMP A() TEMP B()
Not sure how to access different temp inputs
Need to add the LED sequence (if cooler is too cold , GREEN LED to flash. Too warm RED LED to flash.
planning on making ports HIGH, LOW, or HIGH Impedance (have two LEDs 1GREEN & 1RED per port )
as for ROMID #'s going to just breadboard the probes then warm each seperatly to indicate then number each temp probe then install into application.
Code:
Device = 18F452
Clock = 20
 
// import modules...
Include "DS18B20.bas"
Include "convert.bas"
Include "LCD.bas"
///
#option LCD_DATA = PORTD.4              // Assign the LCD connections
#option LCD_EN = PORTD.3                //
#option LCD_RS = PORTD.2                //


 
// working variables...
Dim
   
   TempA(3) As ShortInt,
   TempB(3) As Word,
   LED(7)As Word,
   Port RA.0 As LED(0),   // HIGH = RED leds , LOW = GREEN leds
   Port RA.1 As LED(1),   //
   Port RA.2 As LED(2),   //
   Port RA.3 As LED(3)   // ############################
 
// Start Of Program...
SetBaudrate(br19200)
SetPin(PORTC.0)  // temp probes connect
 
// Find() will search the bus for a single DS1820 device
// and load its ROM ID into the DS1820 public variable RomID - you
// could do this manually. For example, RomID = MyRomID...
 
If DS18B20.Find Then
    While true
      Convert
      GetTemp(TempA(), TempB())
LCD.WriteAt(1,1,"WALK IN COOLER")(DecToStr(TempA(0)),".",DecToStr(TempB(0),4), " C", 13, 10)          // Send some text to the LCD   
LCD.WriteAt(1,2,"GLASS DOOR COOLER")(DecToStr(TempA(1)),".",DecToStr(TempB(1),4), " C", 13, 10)          // Send some text to the LCD  
LCD.WriteAt(1,3,"METAL DOOR COOLER")(DecToStr(TempA(2)),".",DecToStr(TempB(2),4), " C", 13, 10)          // Send some text to the LCD  
LCD.WriteAt(1,4,"KoC BEER COOLER") (DecToStr(TempA(3)),".",DecToStr(TempB(3),4), " C", 13, 10)         // Send some text to the LCD     
      
     
      DelayMS(1000)
    Wend  
Else
 
You don't need floats. Just do the multiply first. So,
Code:
     Tf=Tc*9
     Tf=Tf/5
     Tf=Tf+32
The swordfish library takes care of the rom search and so that should be straight forward.

Mike.
 
If you take a closer look at Mike's (Pommie's) code you'll see it's in the exact same order as the code from the Gentleman on that other thread.

Mike
 
Last edited:
The code I started with to read the temp sensors has a USART instead of LCD.
is there a certain protocall to convert from USART to useing an LCD?
 
here is what I started with

added the LCD bas but nothing is displayed.
Code:
// device and clock speed...
device = 18F452
clock = 20

// import modules...
#option OW_PIN = PORTC.0
include "DS18B20.bas"
include "convert.bas"
include "usart.bas"

// FAMILY $28 ($1D) ($0000002CDBAE) <- DS18B20
// FAMILY $28 ($3F) ($0000002CD16E) <- DS18B20
const Sensor_A(8) as byte = ($28, $AE, $DB, $2C, $00, $00, $00, $1D)
const Sensor_B(8) as byte = ($28, $6E, $D1, $2C, $00, $00, $00, $3F)

// display a sensor value...
sub DisplaySensor(byrefconst pID() as byte)
   dim TempA as shortint
   dim TempB as word
   RomID = pID
   Convert
   GetTemp(TempA, TempB)
   USART.Write(DecToStr(TempA),".",DecToStr(TempB,2), $BA, "C",13,10)
end sub

// program start...
SetBaudrate(br115200)
while true
   DisplaySensor(Sensor_A)
   DisplaySensor(Sensor_B)
   delayms(1000)
wend

here is what I have tried doing
Code:
Device = 18F452
Clock = 20

#option LCD_DATA = PORTD.4       // Force QL-200 board to use 8-bit data bus
#option LCD_RS = PORTD.3        // LCD RS pin Port A, pin 1
#option LCD_EN = PORTD.2        // LCD EN pin Port A, pin 3
//#option LCD_RW = PORTA.2        // LCD RW pin, Port A, pin 2
Const updateMS = 50  //LCD refresh
Include "DS18B20.bas"           // Include DS18B20 library
Include "utils.bas"             // Include utilities library
Include "convert.bas"           // Include convert library
Include "LCD.bas"               // Include LCD library

Dim
TempA As ShortInt,
TempB As Word

SetAllDigital                   // All I/O ports set to  digital
SetPin(PORTB.0)                 // Set 18B20 data pin  pin 33


While true
//DelayMS(1000)                   // Delay 1 second
DelayMS(250)                            // Let the LCD warm up
LCD.Cls                                 // Clear the LCD screen
LCD.WriteAt(1,1,"I love Sue")          // Send some text to the LCD
If DS18B20.Find Then
Convert
GetTemp(TempA, TempB)           // Get temperature from 18B20
LCD.WriteAt(1,2,DecToStr(TempA),".",DecToStr(TempB,4), "C")
Else
LCD.WriteAt(2,1," No device found ")
EndIf
Wend
I tried changing the input port from RB0 to RC0??
 
making progress??

Well I changed the code (copied from DIY site. Now I at least get NO DEVICE FOUND
I guess the temp input is not configured right?
Code:
device = 18F4520
clock = 20

#option LCD_DATA = PORTD.4        // Force QL-200 board to use 8-bit data bus
#option LCD_RS = PORTD.2        // LCD RS pin Port D, pin 21
#option LCD_EN = PORTD.3        // LCD EN pin Port D, pin 22
//#option LCD_RW = PORTA.2        // LCD RW pin, Port A, pin 2

include "DS18B20.bas"           // Include DS18B20 library
include "utils.bas"             // Include utilities library
include "convert.bas"           // Include convert library
include "LCD.bas"               // Include LCD library

dim
TempA as shortint,
TempB as word

SetAllDigital                   // All I/O ports set to digital

SetPin(PORTC.0)                 // Set 18B20 data pin

while true
delayms(1000)                   // Delay 1 second
if DS18B20.Find then
Convert
GetTemp(TempA, TempB)           // Get temperature from 18B20
LCD.WriteAt(1,1,DecToStr(TempA),".",DecToStr(TempB,4), "C")
else
LCD.WriteAt(2,1," No device found ")
endif
wend
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…