LCD-LED Display

Interfacing16X2 LCD with PIC Microcontroller

In this session, we’ll look at how to connect a Interfacing16X2 LCD with PIC Microcontroller from the PIC18F series. In the course How to Interface 16X2 LCD with Microcontroller, you may learn more about 162 LCD.


  • Features of PIC18F4550:
  • 16X2 LCD Interfacing PIC Microcontroller Circuit Diagram:
    • 16X2 LCD Interfacing PIC Microcontroller – Circuit Explanation:
    • Programming PIC for Interfacing 16X2 LCD:
      • Initializing the LCD with PIC Microcontroller function:
      • Sending command to the LCD with PIC Microcontroller:
      • Sending data to the LCD with PIC Microcontroller:
      • Steps for Programming:
      • Program for Interfacing LCD to PIC18F4550:

Features of PIC18F4550:

  • PIC18F4550 is an 8-bit microcontroller with RISC architecture that belongs to the PIC18F series. The PIC18F4550 features 40 pins in a PDIP (duo in line package) and 44 pins in a TQFP (thin quadrant package) (Quad flat package).
  • The PIC18F4550 has 32KB flash memory, 2048 bytes of SRAM (synchronous Random Access Memory), and 256 bytes of EEPROM (Electrically Erasable Program Read Only Memory).
  • It features 35 I/O pins for interacting with and talking with other peripherals, as well as 13 channels of 10bit analogue to digital converters for interacting with and communicating analogue peripherals (DC motor, LDR, etc.).
  • It contains two enhanced capture and compare modules (CCP and ECCP), which are primarily utilised for modulation and waveform production. The CCP module is a 16-bit register that functions as a 16-bit capture bit register, a 16-bit comparison bit register, and a 16-bit PWM and duty cycle register.
  • For master and slave modes, the PIC18F4550 has SPI (serial peripheral interface) and i2c (inter integrated circuit). For USB streaming transfer, it has SPP (Streaming Parallel Port).
  • The PIC18F4550 has four timer modules (timer0 to timer3), two comparator modules, and three external interrupt modules. It offers Dual Oscillator capabilities, which let the microcontroller and USB module to run at distinct clock speeds. It can work in a range of voltages from 2.0 to 5.5V.

16X2 LCD Interfacing PIC Microcontroller Circuit Diagram:

Interfacing16X2 LCD with PIC Microcontroller

16X2 LCD Interfacing PIC Microcontroller – Circuit Explanation:

The LCD’s contrast is controlled by the resistor R1. For system clock, a 12 MHz crystal oscillator is attached to the OSC1 and OSC2 pins of the Pic microcontroller PIC18F4550. The capacitors C2 and C3 will operate as crystal oscillator filters. Before going to different ports, you might utilise different ports or pins to interface the LCD. Please check the data sheet to see if the pins are general-purpose or special-purpose.

Programming PIC for Interfacing 16X2 LCD:

Connecting an LCD to a PIC is similar to interfacing an 8051. The underlying notion and substance of programming are nearly same. More information can be found at

Only the interfacing pins, registers, and architecture will be different. When we look at the software, we’ll notice that functions like startup and transferring data to the LCD are nearly identical.

In the pic programming also for initializing the LCD the R/W pin should be low for writing the data, Enable pins should be high and register select pin (RS) should be high for writing the data. For sending a command the RS should be low, R/W pin should be low and enable pin should be high.

Initializing the LCD function:

lcdcmd(0x38);//Configure the LCD in 8-bit mode,2 line and 5×7 font
lcdcmd(0x0C);// Display On and Cursor Off
lcdcmd(0x01);// Clear display screen
lcdcmd(0x06);// Increment cursor
lcdcmd(0x80);// Set cursor position to 1st line,1st column

Sending command to the LC:

  • rs=0;    Register select pin is low.                                                      
  • rw=0;  Read/write Pin is also for writing the command to the LCD.
  • en=1;enable pin is high.

Sending data to the LCD:

  • rs=1; Register select pin is high.
  • rw=0; Read/write Pin is also for writing the command to the LCD.
  • en=1; enable pin is high.

Steps for Programming:

  • Install MPLAB on your computer and start a new project by choosing a device and a family. Add the PIC18F4550 controller to your project by selecting the PIC18F family.
  • Add the file to your project after selecting the compiler you installed. After you’ve added the file, paste the code below into it and execute it. There will be no errors because it is a precompiled and tested software.
  • After compiling the software without errors, use the PICKIT2 or PICKIT3 programmer/debugger to load it onto your development board.
  • If you don’t have PICKIT, simply compile the code and save it as a HEX file. You can then use this HEX file to programme the PIC microcontroller.

Program for Interfacing LCD to PIC18F4550:

#define rs LATA.F0
#define rw LATA.F1
#define en LATA.F2
//LCD Data pins
#define lcdport LATB

void lcd_init();
void lcdcmd(unsigned char);
void lcddata(unsigned char);
unsigned char data[20]=”hello world”;
unsigned int i=0;

void main(void)
TRISA=0;                             // Configure Port A as output port
TRISB=0;                             // Configure Port B as output port
lcd_init();                              // LCD initialization
lcddata(data[i]);     // Call lcddata function to send characters
// one by one from “data” array

void lcd_init()
lcdcmd (0x0C);


void lcdcmd(unsigned char cmdout)

void lcddata(unsigned char dataout)


Related Articles

Leave a Reply

Your email address will not be published.

Back to top button