pia-468x60

pia-728x90

Tuesday, December 30, 2025

PIC18F4550 ds18B20 16x2 LCD Example

The ds18B20 is a digital one-wire temperature sensor. It can converts between -55 and +125 Degree Celsius. It has three pins, GND, Data and GND. Its open-drain data pin need an additional pullup resistor with a resistance between 4.4 kOhm and 10kOhm.

PIC18F4550 ds18B20 16x2 LCD Example


This popular digital thermometer is widely used among electronics hobbyist due to its low cost, simple communication and rich of libraries (especially Arduino). The MCU just use its digital I/O pin to communicate with this sensor.

Some C compilers for PIC micro-controller like MikroC and CCS PICC have their libraries to interface with this device. However I prefer CCS PICC here due to its simplicity. 

PIC18F4550 ds18B20 16x2 LCD Example
Program Simulation 1

PIC18F4550 ds18B20 16x2 LCD Example
Program Simulation 2

In this example the PIC18F4550 read the temperature data from ds18B20 via RB4 pin. The temperature data will display on the on-board 16x2 character LCD. The PIC18F4550 clock at its maximum frequency of 48MHz.


  1. #include <18F4550.h>
  2. #DEVICE ADC = 10
  3. #fuses HSPLL,NOWDT,NOPROTECT,NOLVP,NODEBUG,USBDIV,PLL5,CPUDIV1,VREGEN
  4. #use delay(clock=48000000)
  5. #use rs232(baud=9600,xmit=PIN_C6,rcv=PIN_C7)
  6. #define PIN_DS18B20_DATA PIN_B4
  7. #include <ds18b20.c>
  8. #define LCD_ENABLE_PIN PIN_D3
  9. #define LCD_RS_PIN PIN_D2
  10. #define LCD_DATA4 PIN_D4
  11. #define LCD_DATA5 PIN_D5
  12. #define LCD_DATA6 PIN_D6
  13. #define LCD_DATA7 PIN_D7
  14. #include "lcd.c"
  15. #define lcd_clear() lcd_putc('\f')
  16. void main(){
  17. signed int16 val;
  18. printf("\n\rPIC18F4550 DIY USB Prototype Board.");
  19. printf("\n\rWednesday 03 September 2025");
  20. printf("\n\rds18B20 one-wire Temperature Sensor Example\n\r");
  21. printf("\r\n\r\ds18b20.c - ds18B20 example starting\r\n\r\n");
  22. ds18b20_init();
  23. lcd_init();
  24. lcd_clear();
  25. printf(LCD_PUTC,"PIC18F4550 LCD\nds18b20 Example");
  26. delay_ms(5000);
  27. lcd_clear();
  28. while(1){
  29. ds18b20_read(&val);
  30. printf("temperature = %ldC\r\n", val/(signed int16)16);
  31. lcd_gotoxy(1,1);
  32. printf(LCD_PUTC, "Temperature:\n%ld%cC",val/(signed int16)16,223);
  33. delay_ms(2000);
  34. }
  35. }

Click here to download this example.

This PCB is offered by PCBWay since it's a sponsor project. PCBWay is a long term and well known one-stop service provider including PCB fabrication, PCB assembling (PCBA) etc. Their service and price are reasonable. Beside their standard PCB they offer advanced PCB, flex PCB, CNC parts and 3D printing parts.

DIY PIC18F4550 Prototype Board



Most of PCBs are fabricated within 24 hours with a few days of delivery time. All PCB are checked and verify before sending to fabrication process (pre-production check). Their engineer contact us very soon if their are any problem or doubt.

PCBWay also offer a low cost PCB fabrication of the size 10cmx10cm. We can order it between 5 and 10 units for only 5USD. They are standard double sided PCB with solder mask, silkscreen, circuit testing etc.

DIY PIC18F4550 Prototype Board


For a large scale demand we can order their PCB assembly service at reasonable price for any projects.

DIY PIC18F4550 Prototype Board


No comments:

Post a Comment

Labels