You are on page 1of 4

A string or message can be displayed on LCD by sending its characters to data register after configuring the command register

of LCD. To create dynamic effects, a specific command instruction is sent to LCD via microcontroller AT89C51. The different command codes for LCD are tabulated below:

Hex Code 1 2 4 6 5 7 8 A C E 10 14 18 1C 80 C0 38

Command to LCD Instruction Register Clear screen display Return home Decrement cursor Increment cursor Shift display right Shift display left Display OFF, cursor OFF Display OFF, cursor ON Display ON, cursor OFF Display ON, cursor blinking Shift cursor position to left Shift cursor position to right Shift the entire display to the left Shift the entire display to the right Force the cursor to the beginning of the 1st line Force cursor to the beginning of the 2nd line Use 2 lines and 5x7 matrix

To create a particular effect, any of these code(s) can be used in a pattern. For example, shifting the entire display right (5H) in a loop will keep moving the text to right. To create oscillating text, first keep shifting the string to right (for say, 8 positions) and then shift it to left. This left-right shifting can be done in an infinite loop. Here P2 is used as output port of the 8051 microcontroller (AT89C51) which sends the data byte to data pins of the LCD. The control pins (pin 4, 5 & 6) are connected to pins 0, 1 & 6, respectively, of P3 port of the microcontroller. Pin 3 is connected to a preset of 10k to adjust the contrast on LCD screen.

// Program to display dynamic text on LCD

#include<reg51.h> #define msec 50 sbit rs=P3^0; sbit rw=P3^1; sbit en=P3^6; //Register select (RS) //Read write (RW) pin //Enable (EN) pin //Command to be sent to

unsigned char commands[]={0x38,0x0E,0x01,0x06,'\0'}; LCD char name[]={"ECE Rocks"};

//String to be displayed on LCD

void delay(unsigned int time)

//Time delay function

{ unsigned int i,j; for(i=0;i<time;i++) for(j=0;j<1275;j++); }

void lcdcmd(unsigned char value) command register of LCD { P2=value; rs=0; rw=0; en=1; delay(1); en=0; return; }

//Function for sending values to the

void display(unsigned char value) register of LCD { P2=value; rs=1; rw=0; en=1; delay(1); en=0; return;

//Function for sending values to the data

void main() { int i,j; for(i=0;commands[i]!='\0';i++) { lcdcmd(commands[i]); delay(msec); } for(j=0;name[j]!='\0';j++) { display(name[j]); delay(msec); } while(1) { lcdcmd(0x1C); delay(75); } } //Shift the entire display to right //Sending string to LCD