Interfacing 16x2 LCD with 8051 microcontroller. |Keil C – AT89C51| Assembly Language|

Interface 16*2 LCD with 8051, Display Your Name on First Line of LCD and Registration Number on Second Line of LCD using C language Connect Data Pins (D0-D7) with Port 1, RS with P2.0, RW with P2.1 and EN with P2.2.

Source code:

#include<reg51.h>

sbit rs=P2^0;

sbit rw=P2^1;

sbit en=P2^2;

void lcdCommand(unsigned char);

void lcddata(unsigned char);

void delay();

void main()

{

P1=0x00; //D0-D7

while(1)

{

lcdCommand(0x38); //5x7 matrix

delay();

lcdCommand(0x01); // clear screen

delay();

lcdCommand(0x10); // cursor blinking

delay();

lcdCommand(0x0E); // Display ON, Cursor ON

delay();

lcdCommand(0x81); // // Force cursor to the beginning of the 1st line

delay();

lcddata('M');

delay();

lcddata('U');

delay();

lcddata('H');

delay();

lcddata('A');

delay();

lcddata('M');

delay();

lcddata('M');

delay();

lcddata('A');

delay();

lcddata('D');

delay();

lcddata('-');

delay();

lcddata('I');

delay();

lcddata('B');

delay();

lcddata('R');

delay();

lcddata('A');

delay();

lcddata('R');

delay();

lcdCommand(0xC0); // Force cursor to the beginning of the 2nd line

delay();

lcddata('B');

delay();

lcddata('A');

delay();

lcddata('E');

delay();

lcddata('M');

delay();

lcddata('-');

delay();

lcddata('F');

delay();

lcddata('1');

delay();

lcddata('8');

delay();

lcddata('-');

delay();

lcddata('0');

delay();

lcddata('2');

delay();

lcddata('5');

delay();

}

}

void lcdCommand(unsigned char a)

{

P1=a;

rs=0;

rw=0;

en=1;

delay();

en=0;

delay();

}

void lcddata(unsigned char a)

{

P1=a;

rs=1;

rw=0;

en=1;

delay();

en=0;

delay();

}

void delay()

{

unsigned int i;

for(i=0;i<12000;i++);

}

Result:




Post a Comment

1 Comments