Show Temperature on LCD - PIC Development Board+PIC16F877A

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

Show Temperature on LCD - PIC Development Board+PIC16F877A

Post by Anobium » Thu Aug 14, 2014 1:17 pm

This demonstration uses the PIC - PIC Development Board + PIC16F877A (HCDVBD0003), a 16*2 LCD and a DS18B20 sensor.

Ensure the LED (j3 /LED - EN) link is NOT in place.

This demo show the temperature as an rounded-up integer and the real value as a decimal.
This code can be easily be adapted for other 40 pin Microchip devices, simply change the #chip type
This code uses the external resonator, however, the #config can be removed to use the internal oscillator, or, a faster external resonator.

Code: Select all

'  FILE:    PIC_GCB_16F877A_DS18B20_with_LCD_Example.gcb
'  DATE:    07/08/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 value of the a DS18B20 sensor.

'Chip Settings. Assumes the development board with with a 16F877A
#chip 16F877A,4
#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

  dim TempC_100 as word   ' a variabler to handle the temperature calculations
  ccount = 0

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

   ' Display the integer value of the sensor on the LCD
   locate 0,0
   print hex(ccount)
   print " Ceil"
   locate 0,8
   print DSdata
   print chr(223)+"C"

   ' Display the integer and decimal value of the sensor on the LCD

   ' The function readtemp12 returns the raw value of the sensor.
   ' The sensor is read as a 12 bit value therefore each unit equates to 0.0625 of a degree
   DSdata = readtemp12
   SignBit = DSdata / 256 / 128
   If SignBit = 0 Then goto Positive
   ' its negative!
   DSdata = ( DSdata # 0xffff ) + 1 ' take twos comp


   ' Convert value * 0.0625. Mulitple value by 6 then add result to multiplication of the value with 25 then divide result by 100.
   TempC_100 =  DSdata * 6		
   DSdata = ( DSdata * 25 ) / 100
   TempC_100 = TempC_100 + DSdata

   Whole = TempC_100 / 100
   Fract = TempC_100 % 100
   If SignBit = 0 Then goto DisplayTemp
   Print "-"

   locate 1,0
   print hex(ccount)
   print " Real"
   locate 1,8
   print str(Whole)
   print "."
  ' To ensure the decimal part is two digits
   Dig = Fract / 10
   print Dig
   Dig = Fract % 10
   print Dig
   print chr(223)
   print "C"
   wait 2 s

You do not have the required permissions to view the files attached to this post.

Post Reply