LCD Interfacing with PIC Using XC8

In this tutorial, we are going to teach how to use an LCD display with an 8-bit PIC microcontroller. We will give you a powerful LCD library and explain how to use it in your microcontroller in this tutorial. We will do examples on PIC16F628A microcontroller but you can do small changes to use it in your projects. Let’s get started to make LCD Interfacing.

We will make 3 projects using our library. These are;

  1. Writing Strings to LCD Display
  2. Shifting Strings and Toggle LCD Display
  3. Writing Numbers to LCD Display

With these projects, you will make what you want with LCD.

16×2 LCD Display

This display is a very basic module that is shown below which uses in very basic electronics projects and products. Pin connections of LCD display which we use areas in the picture below. Be sure that pin orientations are is same, else you may burn your LCD display. If pins not the same, you need to correct the circuit for your LCD display.

16x2 LCD Display
16×2 LCD Display

We are going to use our LCD library. You can read a post about this library which we wrote in the link below.

Circuit Schematic

We will use a circuit below for all 4 projects.

LCD circuit for PIC16F628A microcontroller.
LCD Circuit

Configuration File

In this file, we add configuration of fuses, the definition of oscillator and include statements. This file important because of LCD library needs this file and included libraries. Create config.h file in Header Files and copy-paste code below. If your microcontroller is different edit configuration fuses.

Project 1

In this project, we are going to write “Trion Projects” for first-line and “LCD Interfacing” for the second line. You can print strings in 2 options. You can see options in the code.

LCD interfacing with PIC microcontroller.
LCD Interfacing

Project 2

Now let’s shift string and toggle LCD display. While printing strings we can center it. To center it we need to write 0 to LCDPrintString‘s third parameter.

LCD Display Shifting And Toggling

Project 3

In our third project, we are going to print variables integer numbers to the LCD display. For this, we need to include stdio.h library. We included it in config.h file.

LCD Display Variable Number

In this tutorial project, we teach how to use an LCD display with a PIC microcontroller. We hope this will be helpful. If you have some questions write in the comments below. Stay healthy and see you in the next tutorials.

Share This Tutorial

2 replies on “LCD Interfacing with PIC Using XC8”

very helped very much with the presentation of the LCD part. I’m studying this section. I try to suggest a replacement part for a potentiometer but digital. I’m looking for that reference.

Leave a Reply

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