LCD Interfacing with 8051 Microcontroller
LCD
Interfacing with 8051 Microcontroller
There are variety of displays available though 16*2 LCD
is widely used display device in embedded system. We will discuss about how to
interface 16*2 LCD (rows=2, columns=16) with 8051 microcontroller. We will use uvision
keil for programming and Proteus for circuit designing of the circuit.
Basic
Commands:
Pin Description:
Circuit
Diagram:
Embedded
C Code:
While programming you should follow these steps:
·
STEP1: Initialization of LCD.
·
STEP2: Sending commands to LCD.
·
STEP3: Writing the data to LCD.
Initializing LCD
To initialize LCD to the 8051 the following
instruction and commands are to be embed in to the functions
·
0x38
is used for 8-bit data initialization.
·
0xoC
for making LCD display on and cursor off.
·
0X01
for clearing the display of the LCD.
·
0x80
for positioning the cursor at first line .
Sending
Commands to the LCD
·
E=1;
enable pin should be high
·
RS=0;
Register select should be low for sending commands
·
Placing
the data on the data registers
·
R/W=0;
Read/Write pin should be low for writing the data.
Writing
the Data to the LCD
·
E=1;
enable pin should be high
·
RS=1;
Register select should be high for writing data
·
Placing
the data on the data registers
·
R/W=0;
Read/Write pin should be low for writing the data.
#include<reg51.h>
/* 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 LCD_RS = P0^0;
|
sbit LCD_RW = P0^1;
|
sbit LCD_EN = P0^2;
|
/* local function to generate delay */
|
void
delay_us(int cnt)
|
{
|
int i;
|
for(i=0;i<cnt;i++);
|
}
|
/* Function to send the command to LCD */
|
void
LCD_CmdWrite( char cmd)
|
{
|
LcdDataBus=cmd; // Send the command to LCD
|
LCD_RS=0; // Select the Command Register by pulling RS LOW
|
LCD_RW=0; // Select the Write Operation
by pulling RW LOW
|
LCD_EN=1; // Send a High-to-Low Pusle at Enable Pin
|
delay_us(10);
|
LCD_EN=0;
|
delay_us(1000);
|
}
|
/* Function to send the Data to LCD */
|




Comments
Post a Comment