8051 To 16×2 LCD Interfacing


It’s an example of 8051 To 16×2 LCD Interfacing.

Circuit Diagram


It is 16×2 LCD interfacing example with 8051 in 4 bit mode. In this project we can display results or outcomes of our system for users.


In embedded systems it is difficult to find status and errors generated by system software running inside of microcontroller. It is also necessary in so many other applications where we have to show results to users so that they can use system effectively. So there is a need of a display unit. There are more than one ways of displaying status or results of the system and LCD is one of these ways.

In this project we have used 16×2 means 16 columns and 2 rows LCD. This is based on HD44780 LCD controller. HD44780 is a generic dot matrix LCD controller made by Hitachi. This controller is installed on other sizes of LCDs like 16×1, 16×4, 20×2, 20×4 etc.

Click to Enlarge


Pin Symbol Function
1 Vss ground (0 V)
2 Vdd power (4.5 – 5.5 V)
3 Vo contrast adjustment
4 RS H/L register select signal
5 R/W H/L read/write signal
6 E H/L enable signal
7-14 DB0 – DB7 H/L data bus for 4- or 8-bit mode
15 A (LED+) backlight anode
16 K (LED-) backlight cathode

This LCD can be operated in 4 or 8 bit data mode. In 4 bit mode 4 most significant data bits are used while in 8 bit mode all 8 data pins are connected to microcontroller. In this project we have used 4 bit mode of operation. In 4 bit mode each data or command byte is loaded in 2 iterations of 4 bit each. We can read & write data to LCD but to keep things simple we have hardwired R/W line to ground for only writing. It means we can only print on LCD but cannot read back content written in LCD RAM.

LCD commands used in this project are

  1. Function Set
  2. Entry Mode Set
  3. Display On/Off
  4. Clear Display
  5. Move Cursor/RAM Address Pointer

For basic operation & components used in an 8051 based microcontroller based systems see
8051 Basic LED Flasher.


There is one header and two source/c files.

  1. main.c
  2. lcd4bit.h
  3. lcd4bit.c

Functional description of LCD functions is below

void init_lcd(void);

This function initializes LCD in 4 bit mode. First it confirms 4 bit interface of LCD then sets entry mode, switches on display and clears it.

void gotoxy_lcd(unsigned char col,unsigned char line);

Changes position of cursor on specified column and line by using cursor move command.

void putc_lcd(unsigned char byte);

This function prints single character on current position of cursor on LCD screen.

void print_lcd(char String[]);

This function prints a string on current position of LCD.

void delay_lcd (void);

This function is used to introduce delays needed before sending next command or to wait until previous command is executed.

void write_lcd(unsigned char Val);

This function writes/sends a byte (8 bits) by calling “write_nibble_lcd” function 2 times. It means 4 bits are transferred at one time. After this a delay is introduced to wait until for action is being performed by LCD according data/command sent.

void write_nibble_lcd(unsigned char Val)

This function writes/sends a nibble (4 bits) at one time.

Below is the main file code.

// Start of code.

// Company         : Micro Digital                       //
// Address         : Office # C7 Raza Plaza              //
//                   DAV College Road                    //
//                   Rawalpindi,                         //
//                   Pakistan.                           //
// Programmed By   : Rashid Mehmood                      //
// Project Name    : 8051 To 16x2 LCD Interfacing        //
// Crystal         : 24.000000 MHz                       //
// Microcontroller : AT89C51-C52-C55-S51-S52             //

#include <AT89X51.H>
#include "lcd4bit.h"

void main()
	unsigned char i = 0;
	print_lcd("  Micro Digital  \0");
	gotoxy_lcd(1, 2);

// End of code.

Free Downloads

HD44780 Datasheet

Related Projects

8051 Basic LED Flasher

Electronic Dice using 8051

8051 To Seven Segment Display Interfacing

Cricket Score Board using 8051 and 7 Segment Display

PC Serial RS232 Port Interface To 16×2 LCD

8051 Calculator with 16×2 LCD and Telephone Keypad

8051 4 Digit Electronic Code Lock with LCD and Keypad

More Projects