4-bit 16×2 LCD interfacing with 8051 microcontroller

By | June 29, 2015

 

4-bit LCD interfacing with 8051 – block diagram

4-bit LCD interfacing with 8051-block diagram

4-bit LCD interfacing with 8051 – code

/*
* Project : 4-bit LCD interfacing with 8051 Microcontroller
* Description : This project is about interfacing a 16x2 LCD
* in 4-bit mode to a 8051 microcontroller. In 4-bit mode only
* 4 data line connects to a 8051.
*
* Software : Keil uVison4
* MCU : AT89S51/S52
* Oscillator : 11.0592 MHz
* Date : 11-06-2015
*/

#include <reg51.h>

sbit rs = P3^2;
sbit rw = P3^3;
sbit en = P3^4;

void Delay(int i)
{
int j;
for(;i;i--)
for(j=122;j;j--);
}

void Data_Lcd (unsigned char Dat)
{
P1 = (P1 & 0x0f)|(Dat & 0xf0);
rs = 1;
rw = 0;
en = 1;
Delay(50);
en = 0;

P1 = (P1 & 0x0f)|((Dat<<4) & 0xf0);
en = 1;
Delay(50);
en = 0;

}
void Str_Lcd (unsigned char *Ptr)
{
while(*Ptr)
Data_Lcd(*Ptr++);
}

void Cmd_Lcd (unsigned char Cmd)
{
P1 = (P1 & 0x0f)|(Cmd & 0xf0);
rs = 0;
rw = 0;
en = 1;
Delay(50);
en = 0;

P1 = (P1 & 0x0f)|((Cmd<<4) & 0xf0);
en = 1;
Delay(50);
en = 0;
}

void Init_Lcd ()
{
Cmd_Lcd(0x33);
Cmd_Lcd(0x32);
Cmd_Lcd (0x28);
Cmd_Lcd (0x01);
Cmd_Lcd (0x0e);
Cmd_Lcd (0x0c);
Cmd_Lcd (0x80);
}

void Love_Lcd(unsigned char pos)
{
Cmd_Lcd(64);

Data_Lcd(0);
Data_Lcd(0x0A);
Data_Lcd(0x15);
Data_Lcd(0x15);
Data_Lcd(0x11);
Data_Lcd(0x0A);
Data_Lcd(0x4);
Data_Lcd(0);

Cmd_Lcd(pos);
Data_Lcd(0);
}

void Smile_Lcd(unsigned char pos)
{
Cmd_Lcd(80);

Data_Lcd(0);
Data_Lcd(0x00);
Data_Lcd(0x0A);
Data_Lcd(0x00);
Data_Lcd(0x00);
Data_Lcd(0x11);
Data_Lcd(0xE);

Cmd_Lcd(pos);
Data_Lcd(2);
}

void Human_Lcd(unsigned char pos)
{
Cmd_Lcd(72);

Data_Lcd(0x0E);
Data_Lcd(0x11);
Data_Lcd(0x0E);
Data_Lcd(0x04);
Data_Lcd(0x1F);
Data_Lcd(0x04);
Data_Lcd(0x1B);

Cmd_Lcd(pos);
Data_Lcd(1);
}

void main()
{
Init_Lcd ();
Str_Lcd ("EmbeddedForU.com");
Human_Lcd(0xc4);
Human_Lcd(0xCC);

Cmd_Lcd(0xc5);
Str_Lcd ("---");
Love_Lcd(0xc8);
Data_Lcd('-');
Data_Lcd('-');
Data_Lcd('>');

Smile_Lcd(0xc0);
Smile_Lcd(0xcF);

while(1)
{
Cmd_Lcd(0xc8);
Data_Lcd(' ');
Delay(500);
Love_Lcd(0xc8);
Delay(1000);
}
}

  4-bit LCD interfacing with 8051 – Circuit

4-bit LCD interfacing with 8051 – Circuit

4-bit LCD interfacing with 8051 – output image

4-bit LCD interfacing with 8051 – output image

4-bit LCD interfacing with 8051 – validation video

Leave a Reply

Your email address will not be published. Required fields are marked *