You are on page 1of 14

Lcd interfacing with 8051

LCD is finding widespread use replacing LEDs:

The declining prices of LCD The ability to display numbers, characters, and graphics
Incorporation of a refreshing controller into the LCD, thereby relieving the CPU of the task of refreshing the LCD Ease of programming for characters and graphics

Pin description

LCD commands

Write a c program to display two strings in 2 lines of lcd? #include<reg51.h> #define ldata P2 void lcdcmd(unsigned char); void lcddata(unsigned char); void delay(unsigned int); sbit rs=P3^0; sbit rw=P3^1; sbit en=P3^6;

void main(void) { unsigned char str[]="Hello E2010"; unsigned char str1[]=Good Morning"; unsigned char i,z,k,l; lcdcmd(0x38); delay(25); lcdcmd(0x01); delay(25); lcdcmd(0x0e); delay(25); lcdcmd(0x06); delay(25); lcdcmd(0x80); delay(25);

for(i=0;i<=11;i++) { z=str[i]; lcddata(z); delay(50); } lcdcmd(0x38); delay(25); lcdcmd(0xc2); delay(25); for(k=0;k<=11;k++) { l=str1[k]; lcddata(l); delay(50); }}

void lcdcmd(unsigned char value) { ldata=value; rs=0; rw=0; en=1; delay(1); en=0; return; }

void lcddata(unsigned char value) { ldata=value; rs=1; rw=0; en=1; delay(1); en=0; return; } void delay(unsigned int delay) { int a,b; for(a=0;a<delay;a++) for(b=0;b<1275;b++); }

You might also like