18F DS18B20 Example

    There are 3 Dallas digital temperature sensors, so be sure to get the correct one. There is the 1820, 18S20 and 18B20. The 18S20 is the successor to the 1820, and does not drift over time. The 18B20 is further enhanced, and offers faster conversions. Be aware that the 1820 and 18S20 will not function correctly with this 18B20 example.

    The DS18B20 can be brought from www.newark.com

    The basic wiring diagram

Note the PIC's power supply/oscillator are not shown

    Be sure to attach the 4.7K pull-up resistor to the databus, this is a requirement of the Dallas 1-Wire system. Most of the popular One Wire devices have their own libraries within Swordfish, I'm using the DS18B20 library to make this as simple as possible. Note that Swordfish also has an extensive One Wire library should you want to create your own custom interfacing module.

Device = 18F452
Clock = 20

// import modules...
Include "DS18B20.bas"
Include "convert.bas"
Include "usart.bas"

// working variables...
Dim 
   TempA As ShortInt,
   TempB As Word
   
// Start Of Program...
SetBaudrate(br19200)
SetPin(PORTC.0)

// 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)
      USART.Write(DecToStr(TempA),".",DecToStr(TempB,4), " C", 13, 10)
      DelayMS(1000)
    Wend   
Else
    USART.Write("No device found", 13, 10)
EndIf
 

Where you can get the components;

 

 Skip Navigation Links.

Collapse Site Tutorial IndexSite Tutorial Index
Expand 16F PIC Examples16F PIC Examples
Collapse 18F PIC Examples18F PIC Examples
LED's
Switches
Expand 7 Segment Displays7 Segment Displays
LCD's
Expand 7 Segment Displays7 Segment Displays
ADC
ADC (Another Example)
EEPROM's
DS1307
Expand RS232 and UARTRS232 and UART
DS18B20
External ADC
Hall Effect Sensor
Pulse Width Modulation (PWM)
Infrared UART
Swordfish Modules
Expand Code SnippetsCode Snippets
Expand Handy TipsHandy Tips