To verify that the DS18B20 tutorial does indeed work as written, I wanted to test it out.
Procedure (with timeline):
Begin. Gather hardware together on top of messy desk
Open DS18B20 Tutorial webpage
Paste code from tutorial into Swordfish
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... 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.
Read full article...