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..!

Related Posts:

  • Microcontrollers 8051 Input Output Ports 8051 microcontrollers have 4 I/O ports each of 8-bit, which can be configured as input or output. Hence, total 32 input/output pins allow the microcontroller to be connected with the peripheral devices. Pin configuration,… Read More
  • 8051 Led Blinking 8051 Ports 8051 has 32-gpio's grouped into 4-Ports namely P0-P3 as shown in the below table. PORTNumber of PinsAlternative Function P08 (P0.0-P0.7)AD0-AD7 (Address and Data bus) P18 (P1.0-P1.7)None P28 (P2.0-P2.7)A8-A15… Read More
  • Microcontrollers - 8051 Pin Description The pin diagram of 8051 microcontroller looks as follows − Pins 1 to 8 − These pins are known as Port 1. This port doesn’t serve any other functions. It is internally pulled up, bi-directional I/O port. Pin 9 … Read More
  • Microcontrollers - 8051 Interrupts Interrupts are the events that temporarily suspend the main program, pass the control to the external sources and execute their task. It then passes the control to the main program where it had left off. 8051 has 5 interru… Read More
  • Microcontrollers - 8051 Architecture 8051 microcontroller is designed by Intel in 1981. It is an 8-bit microcontroller. It is built with 40 pins DIP (dual inline package), 4kb of ROM storage and 128 bytes of RAM storage, 2 16-bit timers. It consists of are fou… Read More