Interfacing 16x2 LCD display with 8051 ( AT89S52 ) microcontroller

8051 is a famous microcontroller for small scale projects. the 16X2 LCD Display can interfaced with 8051 in two modes i.e. 8 bit mode and 4 bit mode.
Hey guys this is Madhusudan, and today I’ll tell you how to interface a 16X2 LCD display with an 8051 microcontroller. 8051 is a popular microcontroller family developed by Intel. here we are interfacing a 16X2 display with AT89S52.

So first of all i will give you a brief intro about AT89S52, it is the most famous microcontroller for small scale projects with powerful hardware it has 8 KB of program memory ( ROM ) and 256 bytes of RAM, also the 16X2 LCD Display can configured in two modes i.e. 8 bit mode and 4 bit mode, for the sake of simplicity we will be using 8 bit mode. so connect the data pins to the desired port of microcontroller, but be careful the PORT 0 , it doesn’t have internal pull ups, so in order to use the PORT 0 you need to connect external pull up resistors. So here i am connecting the LCD display to PORT 1, and other pins i.e.

  1. RS ( Register Select ) : PORT2_0,
  2. R/W ( Read/Write ) : PORT2_1,
  3. E ( Enable ) : and PORT2_2.
LCD interfacing with AT98s52
LCD interfaced with AT89s52 microcontroller

for simplicity here i have not shown the LCD contrast, VCC, GND, pins but make their connections too.

So our connection part is now completed. now we will write a program to show name on this LCD display.

#include<AT89X52.h>         //header file
#define RS P2_0             //registe select pin
#define RW P2_1             //read/write pin
#define EN P2_2             //enable pin
#define PORT P1
void delay();               //delay function
void com(char );            //to send command to LCD
void dat(char );            //to send data to LCD
void print(char );          //our function to print the name.
void main(){
        char text[]="KRYPTON";
        int i,n=0;
        com(0x0c);              // display on cursor off
        com(0x01);              //clr scr
        while(text[i]!='\0'){   //continue to print till we get the null character
      /* this block is intentionally commented. this is to be used when we have to print more than 16 characters
                    com(0x1c);          //shift display left

void print(char c){
    com(0x06);                // shift cursor to right >>>>>>
    dat(c);                   // pass the character to LCD

void delay(){
    short int i;

void com(char m){

void dat(char m){

So in function main we have defined an array to hold our name, and initialized the LCD i.e turned on the display and cleared the screen ( initialization process ). now i am having a function print which simply takes the character and display it on the LCD with incrementing the cursor ( i.e. shifting the cursor to right ). so i am passing the values to the print function which will take one character at a time and then do the cursor shifting operation and finally pass the character to the data function to display it. but as our LCD display has some speed limitations so we cannot pass the values repeatedly in a short span, we need to add some delay or else the LCD will ignore the input thus we are calling our delay function after every command or data function call, actually there is another proper way to do so by checking the LCD busy flag, then sending the data else waiting till the busy flag clears but this becomes very much complex, so we are not using the actual busy flag method instead we have used a simple for loop to clear the delay.

| sr no 	|    name    	|           function           	|
|:-----:	|:----------:	|:----------------------------:	|
|   1   	|     VSS    	|            ground            	|
|   2   	|     VDD    	|     power supply ( +5V )     	|
|   3   	|     VEE    	|           contrast           	|
|   4   	|     RS     	|        register select       	|
|   5   	|     R/W    	| read / write  0=write 1=read 	|
|   6   	|      E     	|            enable            	|
|  7-14 	| Data lines 	|          Data lines          	|
|   15  	|      A     	|    Anode ( LCD Backlight )   	|
|   16  	|      K     	|   Cathode ( LCD Backlight )  	|