Interfacing PIC12F1822 microcontroller with I2C LCD

This topic shows an example for connecting LCDs (with HD44780 or complaint controller) with Microchip PIC12F1822 8-bit microcontroller, this microcontroller has only 8 pins of which 5 can be used as outputs, therefore an I2C LCD is required.
An I2C LCD is just a simple LCD with I2C I/O expander such as PCF8574 chip.
This project works also with DFRobot I2C LCD displays.

The compiler used in this example is CCS PIC C. An I2C LCD driver for the CCS PIC C compiler is required to simplify the example C code. This driver is just a C file, we’ve to add this file to the project folder or CCS C drivers folder, download link can be found in the post below:
I2C LCD driver for CCS PIC C compiler

Or it can be downloaded from the link below:
I2C LCD driver download

Hardware Required:
The components listed below are required for this project.

  • PIC12F1822 microcontroller
  • LCD screen (16×2, 20×4 …)
  • PCF8574 I/O expander (or PCF8574A)   —   PCF8574 datasheet
  • 5 x 10k ohm resistor
  • 330 ohm resistor
  • 10k ohm variable resistor or potentiometer
  • 5V source
  • Breadboard
  • Jumper wires

PIC12F1822 MCU with I2C LCD circuit

Interfacing PIC12F1822 MCU with I2C LCD circuit:
Example circuit diagram is shown below.

PIC12F1822 I2C LCD circuit with PCF8574

(All grounded terminals are connected together)

The PIC12F1822 microcontroller has one hardware I2C module with SDA on pin RA2 (#5) and SCL on pin RA1 (#6). SDA and SCL pins of the PIC12F1822 MCU are connected to SDA (#15) and SCL (#14) pins of the PCF8574 I/O expander respectively.

A2, A1 and A0 pins of the PCF8574 are connected to +5V (each one through 10k resistor) which means the I2C address of the PCF8574 (therefor the I2C LCD) is: 0 1 0 0 A2 A1 A0 0 = 0 1 0 0 1 1 1 0 = 0x4E. The 10k ohm resistors for A2, A1 and A0 are optional and each pin can be connected directly to +5V.

PCF8574A can be used instead of the PCF8574, the I2C address becomes: 0x7E.

Interfacing PIC12F1822 with I2C LCD C code:
The C code below is for CCS PIC C compiler, it was tested with version 5.051.

As a reminder, to be able to compile the C code below without errors, a driver for I2C LCD is required, download links are above (2nd paragraph).

The hardware I2C module of the PIC12F1822 is initialized with a clock frequency of 100KHz (100000Hz):
#use I2C(master, I2C1, FAST = 100000, STREAM = I2C_LCD)

The I2C LCD driver file is included with the line:
#include <I2C_LCD.c>

The I2C LCD is initialized with an I2C address of 0x4E:
LCD_Begin(0x4E);

CCS C code:

4 thoughts on “Interfacing PIC12F1822 microcontroller with I2C LCD”

  1. Thanh Khang Pham

    the printf(lcd_out,..) did not work in CCS. the string was not correct as I wanted. it printed out strange symbol. Could you help me how to fix that?

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