8051 4 Bit mode Interfacing LCD Display using Keil C – AT89C51

Liquid Crystal Display (LCD) in 4 Bit mode:

 16x2 LCD 4 Bit Mode uses only 4 data lines D4 – D7. The idea of 4 bit communication is used save pins of microcontroller. 4 bit communication is a bit slower than 8 bit communication but this speed difference can be neglected since LCD's are slow speed devices. Thus 4 bit mode data transfer is most commonly used.

Hardware Connection: 

 

Connect VEE to pot or gnd

Program:

    //program by udaya prakash jayaraman

    #include<reg51.h>

    /* program by udaya prakash jayaraman */

    /* Configure the data bus and Control pins as per the hardware connection
         Databus is connected to P2_0:P2_7 and control bus P0_0:P0_2*/
       
    #define LcdDataBus  P2

    sbit RS = P0^0;
    sbit RW = P0^1;
    sbit EN = P0^2;

    /* local function to generate delay */
    void delay(int k)
    {
            unsigned int i, j;
            for(i=0;i<k;i++)
        {
            for(j=0;j<100;j++);
        }
    }

    /* Function to send the command to LCD */
    void Lcd_CmdWrite( char cmd)
    {
            LcdDataBus=cmd;    // Send the command to LCD
            RS=0;          // Select the Command Register by pulling RS LOW
            RW=0;          // Select the Write Operation  by pulling RW LOW
            EN=1;          // Send a High-to-Low Pusle at Enable Pin
            delay(15);
            EN=0;
            delay(1000);
    }

    /* Function to send the Data to LCD */
    void Lcd_DataWrite( char dat)
    {
            LcdDataBus=dat;      // Send the data to LCD
            RS=1;          // Select the Data Register by pulling RS HIGH
            RW=0;          // Select the Write Operation by pulling RW LOW
            EN=1;          // Send a High-to-Low Pusle at Enable Pin
            delay(15);
            EN=0;
            delay(1000);
    }

    int main()
    {
            char i,a[]={"Udaya Prakash!"};
           
            Lcd_CmdWrite(0x38);        // enable 5x7 mode for chars
            Lcd_CmdWrite(0x0E);        // Display OFF, Cursor ON
            Lcd_CmdWrite(0x01);        // Clear Display
            Lcd_CmdWrite(0x80);        // Move the cursor to beginning of first line

            Lcd_DataWrite('H');
            Lcd_DataWrite('E');
            Lcd_DataWrite('L');
            Lcd_DataWrite('L');
            Lcd_DataWrite('O');
            Lcd_DataWrite(' ');
            Lcd_DataWrite('F');
            Lcd_DataWrite('R');
            Lcd_DataWrite('I');
            Lcd_DataWrite('E');
            Lcd_DataWrite('N');
            Lcd_DataWrite('D');
            Lcd_DataWrite('S');

            Lcd_CmdWrite(0xc0);        //Go to Next line and display Name
            for(i=0;a[i]!=0;i++)
            {
                    Lcd_DataWrite(a[i]);
            }

            while(1);
    }


if you have any doubts kindly contact me..!