Interface PIC MCU with DS18B20 sensor and SSD1306 | mikroC Projects

This project shows how to connect PIC16F887 microcontroller with SSD1306 OLED display (128×64 pixel) and DS18B20 digital temperature sensor. The DS18B20 sensor provides 9-bit to 12-bit Celsius temperature measurement resolution (programmable resolution). The default resolution is 12-bit which is used in this project.
The DS18B20 sensor is a 3-pin electronic component (like a simple transistor) from Maxim (formerly Dallas) which uses 1-wire protocol to communicate with the master device (microprocessor, microcontroller ….).
The compiler used in this project is mikroElektronika mikroC PRO for PIC.

The SSD1306 OLED used in this project is configured to work in I2C mode, some SSD1306 OLED boards may require a small hardware modifications (to select between SPI mode and I2C mode) such as soldering, placing jumpers …

The PIC16F887 microcontroller has one hardware I2C module (MSSP module) with SDA on pin RC4 (#23) and SCL on pin RC3 (#18). The SDA pin of the MCU is connected to the SDA pin of the display and the SCL pin of the MCU is connected to the SCL pin of the display.
The reset pin of the display is connected to pin RD4 (#27) of the microcontroller.

The SSD1306 OLED display DC pin is connected to VDD which means the I2C slave address of the display is 0x7A (default address).

The DS18B20 sensor has 3 pins (from left to right): GND, data and VCC (+5V). The data pin is connected to PIC16F887 pin RD5.

In this project the PIC16F887 microcontroller runs with its internal oscillator @ 8 MHz, MCLR pin is configured as an input pin.

The C code:
The following C code is for mikroC PRO for PIC compiler, it was tested with version 7.2.0.

after the download, add the driver file (SSD1306.C) to project folder.

MikroC PRO for PIC compiler has a built-in one-wire protocol library which makes the interfacing more easier.

The default resolution of DS18B20 is 12-bit which means the step of the temperature is 0.0625°C. The datasheet of the device contains more details about that. Rest of code is described through comments.