The popular 16 x 2 LCD can be interfaced with 89S52 in 4 bit or 8 bit mode. To save port pins of microcontroller , often the LCD is used in 4 bit mode.
The connection details are :
Data pins D4 — P2.0 (pin 21)
D5 — P2.1 (pin22)
D6 — P2.2 (pin23)
D7 — P2.3 (pin24)
Control pins RS — P0.0 (pin 39)
EN — P0.1 (pin 38)
R/W – GND
A header file defining all Functions related to LCD control is created and available for Download here .
Including this header file into your project makes programming much easier.
To start with create a folder for your project , say F:\LCD
Open the KEIL IDE
Click Project – > New uVision Project & browse to the location of the folder created F:\LCD
Provide a filename for the project & select the Target as AT89S52.
Click OK to get the Target1 on the project pane.
Right click the Target1 & click on “Options for Target Target1”
On the Options windows , select the OUTPUT tab & then check mark the box which says “Create HEX file”
Now copy the downloaded lcd.h Header file & paste it to the project folder .
Back to KEIL IDE , Right click on “Source Group 1” & click on “Add Existing Files to Group “
Browse to the lcd.h file you’ve added to the project & select it.
Now the Header file is included in to the project folder.
Right click again on the Source Group 1 & click on “Add new item to Group “
On the next screen select the first option “C File “ & provide a name to your C file.
Feed in the following code :
—————————————-
#include<reg52.h> //including sfr registers for ports of 89s52
#include<lcd.h> // lcd header file
//LCD Module Connections
sbit RS = P0^0;
sbit EN = P0^1;
sbit D4 = P2^0;
sbit D5 = P2^1;
sbit D6 = P2^2;
sbit D7 = P2^3;
//End LCD Module Connections
void Delay(int a)
{
int j;
int i;
for(i=0;i<a;i++)
{
for(j=0;j<100;j++)
{
}
}
}
void main()
{
int i;
Lcd_Init();
Lcd_Clear();
while(1)
{
Lcd_Set_Cursor(1,1);
Lcd_Write_String("8051 LCD Interface");
for(i=0;i<18;i++)
{
Delay(1000);
Lcd_Shift_Left();
}
for(i=0;i<18;i++)
{
Delay(1000);
Lcd_Shift_Right();
}
Lcd_Clear();
Lcd_Set_Cursor(2,1);
Lcd_Write_Char(‘S’);
Lcd_Write_Char(‘E’);
Delay(2000);
}
}
————————————————
After feeding in the code , click the Save button.
Now click F7 or the Build button to start building target.
If the code syntax are correct , you get “Creating HEX file “ display on the Output window.
Now the HEX file is successfully created inside your project folder.
Connect the ISP programmer to the Development board.Plug in the LCD module on to the LCD port connector.
Connect the USB cable to PC & open the PROGISP software.
Click on File & “Load Flash “ .Browse to the location of the HEX file & select it.
Click on AUTO to perform the programming.
Now you can see the characters displayed on the LCD.You can adjust the small blue preset if nothing is seen on the LCD.