Swordfish Tutorial: DS18B20 Actual Use

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

 

Equipment:

  • 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):

1:00

Begin. Gather hardware together on top of messy desk

1:02

Open DS18B20 Tutorial webpage

1:03

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

1:06

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.

1:08

Compile edited program code

1:09

Load the hex file in the PICkit 2 software

1:10

Write the code to the 18F242 via ICSP

1:10

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

1:11

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

1:11

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

 

Pinout

mt_ignore:MB-SM17111_1_w1

 

Results

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...
Dim
 TempA As ShortInt,
 TempB As Word
 
// Start Of Program...
'SetBaudrate(br19200)
 SetBaudrate(br9600) 'This was changed for personal preference
 
'SetPin(PORTC.0)
 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
 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
 
 

 

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

mt_ignore:ds18b20_fix


Here is the setup used for the test:

DS18B20_test_setup

 

Forum Activity

Member Access