PIC MCU Interface with Nokia 5110 LCD & LM35 Sensor | mikroC Projects

This tutorial shows how to interface PIC18F46K22 microcontroller with Nokia 5110 LCD display and LM35 analog temperature sensor from Texas Instruments.
In this project the Nokia 5110 LCD (84×48 pixel resolution) is used to display environment temperature in degree Celsius and Kelvin.
The compiler used in this project is MikroElektronika mikroC PRO for PIC.

To see how to interface PIC18F46K22 MCU with Nokia 5110 LCD using mikroC compiler, visit this post:
Interfacing PIC MCU with Nokia 5110 LCD | mikroC Projects

About the LM35 temperature sensor:
The LM35 temperature sensor is a three pin device (VCC, OUT and GND) with an output voltage linearly related to Centigrade temperature. Since the LM35 output varies with dependent to the temperature, we need an ADC (Analog-to-Digital Converter) module to measure this voltage. The PIC18F46K22 microcontroller has one ADC module with 10-bit resolution.

The LM35 output has linear +10mV/°C scale factor means the following:
If the output voltage =   10mV —> temperature =   1°C
If the output voltage = 100mV —> temperature = 10°C
If the output voltage = 200mV —> temperature = 20°C
If the output voltage = 370mV —> temperature = 37°C
and so on.

LM35 Futures (from datasheet):

  • Calibrated Directly in ° Celsius (Centigrade)
  • Linear + 10 mV/°C Scale Factor
  • 0.5°C Ensured Accuracy (at +25°C)
  • Rated for Full −55°C to +150°C Range
  • Suitable for Remote Applications
  • Low Cost Due to Wafer-Level Trimming
  • Operates from 4 to 30 V
  • Less than 60-μA Current Drain
  • Low Self-Heating, 0.08°C in Still Air
  • Nonlinearity Only ±¼°C Typical
  • Low Impedance Output, 0.1 Ω for 1 mA Load

The ADC module converts analog data into digital data. The PIC18F46K22 MCU has a 10-bit ADC module and a built-in fixed voltage reference (FVR) module which makes it a good choice for this application. With the fixed voltage reference we get a very good results.
Normally negative and positive references of the ADC module are VSS and VDD respectively, but VDD is not exactly equal to 5.00V, hence we should use the fixed voltage reference as a positive reference of the ADC module.

The PIC18F46K22 has 3 fixed voltage references: 1.024V, 2.048V and 4.096V. For example if we set the fixed voltage reference to 4.096V and the ADC module is configured so that the negative and the positive references are VSS and FVR respectively, in this case the equivalent 10-bit digital value of 4.096 is 1023 and 3.00V is 3.00 * 1023/4.096 = 749 , and so on.
In this project I used FVR = 1.024V because the LM35 output is generally less than 1V and also it gave me better result (let’s say higher resolution). Now the ADC module works in the interval between 0 and 1.024V.

Hardware Required:

  • PIC18F46K22 microcontroller   —->  datasheet
  • Nokia 5110 LCD screen
  • LM35 temperature sensor   —->   datasheet
  • AMS1117 3V3 voltage regulator
  • 10 uF capacitor
  • 100 nF ceramic capacitor
  • 5 x 3.3k ohm resistor
  • 5 x 2.2k ohm resistor
  • 5V source
  • Breadboard
  • Jumper wires

PIC18F46K22 MCU with Nokia 5110 LCD and LM35 temperature sensor

PIC18F46K22 MCU with Nokia 5110 LCD and LM35 sensor circuit:
The image below shows project circuit diagram.

The LM35 sensor has 3 pins (from left to right):
Pin 1 is power supply pin, connected to circuit +5V,
Pin 2: output pin,
Pin 3: GND (ground), connected to circuit ground.

The output pin of the LM35 sensor is connected to pin RA0 which is analog channel 0 (AN0).

LM35 PIC18F46K22 NOKIA 5110 LCD circuit

All the grounded terminals are connected together.

The Nokia 5110 LCD module which is shown in the circuit diagram has 8 pins (from left to right): RST (reset), CE (chip enable), DC (or D/C: data/command), Din (data in), Clk (clock), VCC (3.3V), BL (back light) and Gnd (ground).

The Nokia 5110 LCD works with 3.3V only (power supply and control lines). The LCD module is supplied with 3.3V which comes from the AMS1117 3V3 voltage regulator, this regulator steps down the 5V into 3.3V (supplies the LCD controller PCD8544 with regulated 3V3).

All PIC18F46K22 microcontroller output pins are 5V, connecting a 5V pin to the Nokia 5110 LCD may damage its controller circuit!
To connect the PIC18F46K22 to the LCD module, I used voltage divider for each line which means there are 5 voltage dividers. Each voltage divider consists of 2.2k and 3.3k resistors, this drops the 5V into 3V which is sufficient.

So, the Nokia 5110 LCD pins are connected to PIC18F46K22 MCU as follows (each one through voltage divider):
RST (reset) pin is connected to pin RD0 (#19),
CE (chip enable) pin is connected to pin RD1 (#20),
DC (data/command) pin is connected to pin RD2 (#21),
DIN (data in)  pin is connected to pin RD3 (#22),
CLK (clock) pin is connected to pin RD4 (#27),

VCC and BL are connected to AMS1117 3V3 regulator output pin and GND is connected to circuit ground (0V).

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

PIC18F46K22 with Nokia 5110 LCD and LM35 sensor C code:
The following C code is for mikroC PRO for PIC compiler, it was tested with version 7.2.0.

To be able to compile project C code, a driver for the Nokia 5110 LCD is required, download link is below. After you download the driver file which named NOKIA5110.C, add it to your project folder:
Nokia 5110 LCD library for mikroC compiler

The connection of the LCD pins with the microcontroller are defined in the C code as shown below:

The ADC module is configured so that it uses its internal clock, voltage references (negative and positive) are set to VSS and FVR respectively where the FVR is set to 1.024V:

PIC18F46K22 ADC module is used with 10-bit resolution which means the digital value of the input analog voltage varies between 0 (0V) and 1023 (1.024V).
The digital value represents the temperature in tenths °Celsius (output value of “274” equals 27.4 °Celsius).
The temperature in tenths Kelvin = (tenth °Celsius) + 2732 (because: K = °C + 273.16).

To get the actual value of each quantity we’ve to divide it by 10. The line below shows an example for temperature in Kelvin:

We get the first 3 digits by dividing the tenths value by 10, and the tenths number (number after the decimal point) of the actual temperature value is equal to the reminder of that division (tenths value % 10).

The resolution of this thermometer is 0.1°C.

Full mikroC code:


Discover more from Simple Circuit

Subscribe to get the latest posts sent to your email.

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll to Top