Header Ads

Interfacing LCD with the AT89C2051 Microcontroller

Pins Diagram:
In this tutorial, I'll show you how to interface 16x2 LCD with the AT89C2051 Microcontroller. Proteus Circuit Diagram:
Code
//Code by Shahid Khan
//Interfacing LCD
#include
#include
#define LCD P1 //LCD Data pins
sbit RS = P3^0; //RS is connected to pin0 of port3
sbit EN = P3^1; //EN is connected to pin1 of port3
void delay(unsigned int msec) // Function to provide time delay in msec.
{
int i,j ;
for(i=0;i for(j=0;j<1275;j++);
}
void LCD_CMD(unsigned char x)
{
LCD=x;//send data to LCD
RS=0;
EN=1;
delay(2);
EN=0;
}
void LCD_DATA(unsigned char y)
{
LCD=y; //send data to LCD
RS=1;
EN=1;
delay(2);
EN=0;
}
void LCD_STRING(unsigned char *Str) //send string function
{
while(*Str)//stay in this loop while data is not finshed

LCD_DATA(*Str++);//send one by one data to LCD
}
void LCD_INI()
{
delay(300);
LCD_CMD(0x38);//set 8 bit LCD mode, 2 line and 5x10 dots
LCD_CMD(0x0E);//turn display ON for cursor blinking
LCD_CMD(0x01);//clear LCD
}
void main() {
LCD_INI();

delay(300);
LCD_STRING("Hello Wingineers!"); //Write to LCD
}
Simulation Video:

No comments

Powered by Blogger.