Display the DS18B20 unique rom ID on a LCD & the temperature

Post Reply
Posts: 20
Joined: Fri Aug 01, 2014 9:17 am

Display the DS18B20 unique rom ID on a LCD & the temperature

Post by Anobium » Fri Sep 26, 2014 5:11 pm

This code display the DS18B20 unique rom code on the LCD and also the current temperature.


Code: Select all

'  FILE:    PIC_GCB_16F877A_READ_ROM_DS18B20_and_Temp_with_LCD_Example.gcb
'  DATE:    26/09/14
'  VERSION: 0.1a
'  AUTHOR:  Anobium
'This program was written using the Great Cow Basic IDE for use with the PIC
'16F8777A development board (HCDVBD0003) and a 1602 parallel LCD module
'(HCMODU0013 or HCMODU0038) to display the unique 64-BIT LASERED ROM CODE of a DS18B20 sensor.

'Chip Settings. Assumes the development board with with a 16F877A
#chip 16F877A,20
#include <DS18B20.h>

 'Use LCD in 4 pin mode and define LCD pins
 #define LCD_IO 4
 #define LCD_RW PORTE.1
 #define LCD_RS PORTE.0
 #define LCD_Enable PORTE.2
 #define LCD_DB4 PORTD.4
 #define LCD_DB5 PORTD.5
 #define LCD_DB6 PORTD.6
 #define LCD_DB7 PORTD.7

  ' DS18B20 port settings - this is required
  #define DQ PortC.3

 ' READ ROM [33h]
 ' This command can only be used when there is one slave on the bus.
 ' It allows the bus master to read the slave’s 64-bit ROM code without using the Search ROM procedure.
 ' If this command is used when there is more than one slave present on the bus, a data collision will occur when all the slaves attempt to respond at the same time.

 ' Each DS18B20 contains a unique 64–bit code (see Figure 6) stored in ROM.
 ' The least significant 8 bits of the ROM code contain the DS18B20’s 1-Wire family code: 28h.
 ' The next 48 bits contain a unique serial number.
 ' The most significant 8 bits contain a cyclic redundancy check (CRC) byte that is calculated from the first 56 bits of the ROM code. A detailed explanation of the CRC bits is provided in the CRC Generation section. The 64-bit ROM code and associated ROM function control logic allow the DS18B20 to operate as a 1-Wire device using the protocol detailed in the 1-Wire Bus System section.
 ' 64-Bit Lasered ROM Code
 ' 8-BIT CRC      48-BIT SERIAL NUMBER          8-BIT FAMILY CODE (28h)
 ' MSB  LSB       MSB              LSB          MSB                 LSB

  print "Great Cow Basic "
  locate 1 , 0
  print "DS18B20   @2014 "
  wait 3 s
  print "SHOW 64BIT LASERED"
  locate 1 , 0
  print "ROM CODE ON LCD"
  wait 3 s
  ypos = 0        ' Ypos on the LCD

  ' show 64-BIT LASERED ROM CODE on both rows of the LCD
     wait 100 ms
     MasterRST      ' Reset ds18b20
     PPulse         ' Request a presence pulse
     wait 100 us
     OWout ReadRom  ' Send 64-BIT LASERED ROM CODE read code
     wait 100 us
     OWinRom        ' Process and display the 64-BIT LASERED ROM CODE

  oldDSdata = 255
  do forever
   ' The function readtemp returns the integer value of the sensor
   DSdata = readtemp

   if oldDSdata <> DSdata then
       ' Display the integer value of the sensor on the LCD
       locate 1,0
       print "Currently "
       print DSdata
       print chr(223)+"C "
       oldDSdata = DSdata
   end if


Sub OWinRom
 xpos = 14       ' XPos on the LCD
 For EightBytes = 1 to 8
  For Clocks = 1 to 8
   Rotate RxData Right 'The DS18s20 wants data LSB first
   Dir DQ Out
   Set DQ Off  'Read time slot
   wait 4 us
   Dir DQ In   'Release bus for one wire transmission
   wait 7 us
   If DQ On  Then Set RxData.7 1
   If DQ Off Then Set RxData.7 0
   wait 50 us
   locate ypos , xpos
   Print hex(RxData)
   xpos = xpos - 2

 end sub

Posts: 49
Joined: Wed Aug 21, 2013 7:38 am

Re: Display the DS18B20 unique rom ID on a LCD & the tempera

Post by barewires » Sat Sep 27, 2014 1:32 pm

Hi, I changed the clock to the actual 4Mhz from 20, the temperature displayed is 60 to 100 deg to high.
Could I ask for a text copy of a working :? <DS18B20.h> being posted?
Many thanks,

Post Reply

Return to “Great Cow Basic”