728x90

728x90

Saturday, September 27, 2025

dsPIC30F2010 and ds18B20 Temperature Interfacing

The DS18B20 is a digital thermometer that able to convert the temperature from -55 to +125 degree Celsius. The controller communicates with this temperature sensor using a 1-Wire bus. So this device requires only three wires including GND, VCC, and data line. Furthermore it can use data line to power  the device eliminating the VCC. 

dsPIC30F2010 and ds18B20 Temperature Interfacing

 

This device also work in TTL logic level that could interface with the dsPIC30F2010 using its digital bi-directional I/O. 

PIC16F84A DS18B20 1-Wire Temperature Reading And Multiplexing Display Example Using XC8
DS18B20 Pin Configuration
PIC16F84A DS18B20 1-Wire Temperature Reading And Multiplexing Display Example Using XC8
DS18B20 In TO-92 Package

For more information and interfacing this sensor with a micro-controller please check this post. 

The newer version of CCS PICC (v5.119) have a C driver "ds18b20.c"for this device that allow the programmer to call it using a few lines of code. It's effective and fast.

The following example I use RB0 of dsPIC30F2010 to read the temperature sensor from a single wire ds18b20 temperature sensor. The sensor's data will be send over the RS-232 between the micro-controller and the host PC. I also added a TC1604A-04 16x4 LCD to display the temperature data in degree Celsius and Fahrenheit.  

  • CCS PICC Source Code (v5.119) 

 


  1. /*CCS PICC Compiler version 5.119*/
  2. #include <30F2010.h>
  3. #fuses HS,NODEBUG,NOWDT,PR,CKSFSM
  4. #use delay(clock=20M)
  5. #use rs232(UART1,BAUD=9600)


  6. #define PIN_DS18B20_DATA PIN_B0
  7. #include "ds18b20.c"

  8. #define LCD_RS_PIN PIN_E4
  9. #define LCD_RW_PIN PIN_E5
  10. #define LCD_ENABLE_PIN PIN_E5
  11. #define LCD_DATA4 PIN_E0
  12. #define LCD_DATA5 PIN_E1
  13. #define LCD_DATA6 PIN_E2
  14. #define LCD_DATA7 PIN_E3

  15. #include "lcd.c"

  16. #define lcd_clear() lcd_putc('\f')
  17. #define lcd_home() lcd_putc('\a')
  18. /*For 16x4 LCD Only*/
  19. #define line_1() lcd_send_byte(0,0x80);
  20. #define line_2() lcd_send_byte(0,0xC0);
  21. #define line_3() lcd_send_byte(0,0x90);
  22. #define line_4() lcd_send_byte(0,0xD0);



  23. void main(){
  24. signed int16 val;
  25. printf("\n\rdsPIC30F2010 Prototype Board.");
  26. printf("\n\rSaturday 26th September 2025");
  27. printf("\n\rds18b20 Humidity Sensor Example\n\r");
  28. printf("\r\n\r\ds18b20.c - DHT11 example starting\r\n\r\n");
  29. ds18b20_init();
  30. lcd_init();
  31. printf(LCD_PUTC,"dsPIC30F2010 LCD");
  32. line_2();
  33. printf(LCD_PUTC,"ds18b20 Sensor");
  34. line_3();
  35. printf(LCD_PUTC,"Programming");
  36. line_4();
  37. printf(LCD_PUTC,"CCS PICC v5.049");
  38. delay_ms(5000);
  39. lcd_clear();
  40. while(1){
  41. ds18b20_read(&val);
  42. printf("temperature = %ldC\r\n", val/(signed int16)16);
  43. lcd_home();
  44. printf(LCD_PUTC," ds18b20 Sensor");
  45. line_2();
  46. printf(LCD_PUTC," Temperature");
  47. line_3();
  48. printf(LCD_PUTC," %ld%cC",val/(signed int16)16,0xDF);
  49. line_4();
  50. printf(LCD_PUTC," and %f%cF",1.8*(val/(signed int16)16)+32,0xDF);
  51. delay_ms(1000);
  52. }
  53. }

 I modified the "lcd.c" C driver file to make it works with my TC1604A-04 LCM module. So I need to copy this driver file to my project folder. The "ds18b20.c" C driver file is already existed in the driver folder of CCS PICC v5.119. But I also copied to my project folder.

This program needs 51% of ROM and 36% of RAM.

dsPIC30F2010 and ds18B20 Temperature Interfacing
Serial Input/Output Monitor

I use my DIY dsPIC30F2010 Prototype Board offered by PCBWAY to test this programming example.

dsPIC30F2010 and ds18B20 Temperature Interfacing
Start Up Program

dsPIC30F2010 and ds18B20 Temperature Interfacing
ds18B20 Temperature Reading


Click here to download this example.

 

No comments:

Post a Comment

320x50

Search This Blog

tyro-728x90