echo '' ;

8051 Interface – LCD


Interfacing an LCD (Liquid Crystal Display) with the 8051 microcontroller is a common practice in embedded systems for displaying information. Here’s a brief overview of 8051 Interface LCD

  • Hardware Connections: Connect the data lines (D0-D7) of the LCD to the GPIO pins of the 8051. Connect the control lines (RS, RW, E) to specific GPIO pins. Optionally, connect the backlight control pin and adjust the contrast using a potentiometer.
  • Initialization: Send initialization commands to the LCD to configure its operation mode, display settings, and other parameters. This typically involves sending specific command codes over the data lines.
  • Sending Data: To display characters or strings on the LCD, send the ASCII codes of the characters over the data lines while setting the RS (Register Select) line appropriately to indicate data transmission mode.
  • Sending Commands: To control the operation of the LCD (such as clearing the display, setting the cursor position, etc.), send command codes over the data lines while setting the RS line to indicate command transmission mode.
  • Timing Considerations: Ensure proper timing between data/command transmissions and the strobing of the E (Enable) line to ensure reliable communication with the LCD.
  • Busy Flag Checking: Check the busy flag of the LCD before sending new commands or data to ensure that the LCD is ready to receive new instructions.
  • Writing Custom Characters: Some LCDs allow you to define custom characters by programming specific patterns into the CGRAM (Character Generator RAM) of the LCD.
  • Example Code: Here’s a basic example of initializing and sending data to an LCD connected to an 8051 microcontroller:
Read more: 8051 Interface – LCD

Uses of LCD

  • Displaying Information: LCDs (Liquid Crystal Displays) are used to visually display information such as text, numbers, and symbols.
  • Interface Compatibility: They can be easily interfaced with 8051 microcontrollers through parallel or serial communication interfaces.
  • Textual Output: LCDs allow for the display of textual information, making them suitable for user interfaces or information panels.
  • Low Power Consumption: They typically consume less power compared to other display technologies, making them suitable for battery-powered devices.
  • Compact Size: LCD modules come in various sizes, allowing for flexibility in design and integration into compact devices.
  • Backlighting Options: Some LCD modules offer backlighting options, enabling visibility in low-light conditions.
  • Dynamic Display: LCDs can be dynamically updated to show changing information or real-time data.
  • Multipurpose Usage: They find applications in various domains such as digital clocks, thermometers, calculators, and industrial control panels.

Next will see about code of 8051 Interface LCD

Code Header file (LCD8.h)

#define LCD_First_Line     0x80
#define LCD_Second_Line    0xc0
#define LCD_Curser_On          0x0f
#define LCD_Curser_Off         0x0c
#define LCD_Clear_Display 0x01
#define Lcd8_Data_Port         P2

sbit Lcd8_RS = P0^0;
sbit Lcd8_RW = P0^1;
sbit Lcd8_EN = P0^2;

void Lcd8_Init();
void Lcd8_Command(unsigned char);
void Lcd8_Write(unsigned char,unsigned char);
void Lcd8_Display(unsigned char,const unsigned char*,unsigned int);
void Lcd8_Decimal2(unsigned char,unsigned char);
void Lcd8_Decimal3(unsigned char,unsigned char);
void Lcd8_Decimal4(unsigned char,unsigned int);
void Delay(unsigned int);

void Lcd8_Init()
{
    Lcd8_Command(0x38);     //to select function set
    Lcd8_Command(0x06);     //entry mode set
    Lcd8_Command(0x0c);     //display on
    Lcd8_Command(0x01);     //clear display
}

void Lcd8_Command(unsigned char com)
{
    Lcd8_Data_Port=com;
    Lcd8_EN=1;
    Lcd8_RS=Lcd8_RW=0;
    Delay(125);
    Lcd8_EN=0;
    Delay(125);
}

void Lcd8_Write(unsigned char com,unsigned char lr)
{
    Lcd8_Command(com);

    Lcd8_Data_Port=lr;          // Data 
    Lcd8_EN=Lcd8_RS=1;
    Lcd8_RW=0;
    Delay(125);
    Lcd8_EN=0;
    Delay(125);
}

void Lcd8_Display(unsigned char com,const unsigned char *word,unsigned int n)
{
    unsigned char Lcd_i;

    for(Lcd_i=0;Lcd_i<n;Lcd_i++)
    { 
        Lcd8_Write(com+Lcd_i,word[Lcd_i]);
    }
}

void Lcd8_Decimal2(unsigned char com,unsigned char val)
{
    unsigned int Lcd_hr,Lcd_t,Lcd_o;

    Lcd_hr=val%100;
    Lcd_t=Lcd_hr/10;
    Lcd_o=Lcd_hr%10;
    
    Lcd8_Write(com,Lcd_t+0x30);
    Lcd8_Write(com+1,Lcd_o+0x30);
}


void Lcd8_Decimal3(unsigned char com,unsigned char val)
{
    unsigned int Lcd_h,Lcd_hr,Lcd_t,Lcd_o;

    Lcd_h=val/100;
    Lcd_hr=val%100;
    Lcd_t=Lcd_hr/10;
    Lcd_o=Lcd_hr%10;
    
    Lcd8_Write(com,Lcd_h+0x30);
    Lcd8_Write(com+1,Lcd_t+0x30);
    Lcd8_Write(com+2,Lcd_o+0x30);
}

void Lcd8_Decimal4(unsigned char com,unsigned int val) 
{
    unsigned int Lcd_th,Lcd_thr,Lcd_h,Lcd_hr,Lcd_t,Lcd_o;

    val = val%10000;
    Lcd_th=val/1000;
    Lcd_thr=val%1000;
    Lcd_h=Lcd_thr/100;
    Lcd_hr=Lcd_thr%100;
    Lcd_t=Lcd_hr/10;
    Lcd_o=Lcd_hr%10;

    Lcd8_Write(com,Lcd_th+0x30);
    Lcd8_Write(com+1,Lcd_h+0x30);
    Lcd8_Write(com+2,Lcd_t+0x30);
    Lcd8_Write(com+3,Lcd_o+0x30);
}

void Delay(unsigned int del)
{
    while(del--);
}     

Code Main File (LCD8_Interface_Main.c)

#include<reg51.h>
#include "LCD8.h"

void timer_init(void);

static unsigned char i;
static unsigned int x=100,y=150,cnt; 

void main()
{
    Lcd8_Init();
    Lcd8_Display(LCD_First_Line,"   Hello World  ",16);
    while(1)
    {
        Lcd8_Display(LCD_Second_Line," ArunEworld.com ",16);
    }//while(1)
}//void main()

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Discover more from ArunEworld

Subscribe now to keep reading and get access to the full archive.

Continue reading