Welcome, Guest
Username: Password: Secret Key Remember me

TOPIC: Swordfish Tutorial: DS18B20 Actual Use

Re: Swordfish Tutorial: DS18B20 Actual Use 9 years 3 months ago #15332

To verify that the DS18B20 tutorial does indeed work as written, I wanted to test it out.


  • DS18B20 temperature probe from Sure Electronics (convenient package - a bare part would work just as well)
  • TAP-28 board, equipped with an 18F242 processor and 20 MHz crystal
  • (2) PICkit 2 - for convenience, 1 used for programming, 1 for UART tool

Procedure (with timeline):


Begin. Gather hardware together on top of messy desk


Open DS18B20 Tutorial webpage


Paste code from tutorial into Swordfish
  1. Change device
  2. Change baudrate - personal preference
  3. Change data pin from PortC.0 to PortB.0.  The TAP-28 board has a 10k pullup resistor installed


Connect sensor with jumper wires to TAP-28 board.  The order of the pins on the sensor cable is ground / data / V+.  Examine the picture below if unsure.


Compile edited program code


Load the hex file in the PICkit 2 software


Write the code to the 18F242 via ICSP


Select the UART tool for the second PICkit 2 and select 9600 baud to agree with program setting


Toggle power on to the TAP-28 on the PICkit menu


Observe temperature data on PICkit UART screen, and note change when probe held with fingers.




Eleven minutes from start to finish.  Granted, I am extremely familiar with the TAP-28 board, and the built-in pullup resistor made the task slightly easier.  But clearly, if the code is changed to reflect the actual hardware being used and the connections are made correctly, this project is a piece of cake and works exactly as written.

Here is the code with my modifications:

'Device = 18F452       This must be changed to the actual part used.  
 Device = 18F242
Clock = 20
// import modules...
Include "DS18B20.bas"
Include "convert.bas"
Include "usart.bas"
// working variables...
   TempA As ShortInt,
   TempB As Word
// Start Of Program...
 SetBaudrate(br9600)      'This was changed for personal preference
 SetPin(PORTB.0)          'Changed to use Pin B.0 on TAP-28 board as the board
                          'has a 10k pullup resistor installed   
// 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
      GetTemp(TempA, TempB)
      USART.Write(DecToStr(TempA),".",DecToStr(TempB,4), " C", 13, 10)
    USART.Write("No device found", 13, 10)


This is the PICkit 2 UART Screen showing the results.  Note the UART has been disconnected to stop updating.

Read full article...
Time to create page: 0.232 seconds