New Member FAQ | Forums | Earn Revenue


Resources Entrance Ask Experts Exam Papers Jobs English Projects Universities Colleges Courses Schools Training My India



My Profile
Active Members
TodayLast 7 Days more...



Awards & Gifts
Online Exams

Fresher Jobs


Our fresher job section is exclusively for fresh graduates! Find jobs for freshers in major Indian cities including Bangalore, Chennai, Hyderabad, Pune or Kochi

Resources


Find educational articles, blogs, discussion threads and other resources.

Colleges


Find details about any college in India or search for courses.

website counter



To interface LCD with Microprocessor to display the output


Posted Date:     Total Responses: 0    Posted By: Pawan Bahuguna   Member Level: Diamond   Points/Cash: 7   


#include
/** define macros **/
sfr ldata =0x90;
sbit rs =P2^2;
sbit rw =P2^1;
sbit en =P2^0;
/**define private function prototype**/
void ini (void);
void lcdcmd (unsigned char );
void lcddata (unsigned char );
void MSDelay (unsigned int );
void Tx (unsigned char );

/* define global variables */
unsigned char k = 0,serial;
bit flag1=0,flag2=0,flag3=0,flag4=0;

/** main start here **/
void main (void)
{
TMOD = 0x20; // enable timer1 in auto reload mode
TH1 = 0xFD; // set 9600 baud rate
SCON = 0x50; // enable uart for serial communication
TR1 = 1; // start timer1

Tx ('W'); // send "welcome" to serial port
Tx ('e');
Tx ('l');
Tx ('c');
Tx ('o');
Tx ('m');
Tx ('e');
ini (); // initialize the lcd
lcdcmd (0x80); // set address for first character in first line
lcddata ('D'); Tx ('D'); // display "DEV1 = 0" on lcd and send to serial port
lcddata ('E'); Tx ('E');
lcddata ('V'); Tx ('V');
lcddata ('1'); Tx ('1');
lcddata ('='); Tx ('=');
lcddata ('0'); Tx ('0'); Tx (' '); Tx (' ');
lcdcmd (0x88); // set address of 8th character in first line
lcddata ('D'); Tx ('D'); // display "DEV2 = 0" on lcd and send to serial port
lcddata ('E'); Tx ('E');
lcddata ('V'); Tx ('V');
lcddata ('2'); Tx ('2');
lcddata ('='); Tx ('=');
lcddata ('0'); Tx ('0'); Tx (' ');Tx (' ');
lcdcmd (0xC0); // set address of first character in second line
lcddata ('D'); Tx ('D'); // display "DEV3 = 0" on lcd and send to serial port
lcddata ('E'); Tx ('E');
lcddata ('V'); Tx ('V');
lcddata ('3'); Tx ('3');
lcddata ('='); Tx ('=');
lcddata ('0'); Tx ('0');Tx (' ');Tx (' ');

lcdcmd (0xC8); // set address of 8th character in second line
lcddata ('D'); Tx ('D'); // display "DEV4 = 0" on lcd and send to serial port
lcddata ('E'); Tx ('E');
lcddata ('V'); Tx ('V');
lcddata ('4'); Tx ('4');
lcddata ('='); Tx ('=');
lcddata ('0'); Tx ('0'); Tx (' ');Tx (' ');

P0 = 1; // configure port p0 as input

while (1) // start infinite loop
{

if (P0_0==1)
{
while (P0_0);
MSDelay (10);
P2_3 = ~P2_3; // toggle pin P2_3
flag1 = ~flag1; // toggle flag1
if (flag1)
{
lcdcmd (0x80);
lcddata ('D'); // display "DEV1 = 1" on lcd and send to serial port
lcddata ('E');
lcddata ('V');
lcddata ('1');
lcddata ('=');
lcddata ('1');

Tx ('D');
Tx ('E');
Tx ('V');
Tx ('1');
Tx ('=');
Tx ('1');
Tx (' ');
Tx (' ');

}
else
{
lcdcmd (0x80);
lcddata ('D'); // display "DEV1 = 0" on lcd and send to serial port
lcddata ('E');
lcddata ('V');
lcddata ('1');
lcddata ('=');
lcddata ('0');

Tx ('D');
Tx ('E');Tx ('1');
Tx ('=');
Tx ('V');

Tx ('0');
Tx (' ');
Tx (' ');

}
}

if (P0_1==1)
{
while (P0_1);
MSDelay (10); // toggle pin P2.4
P2_4 = ~P2_4; // toggle flag2
flag2 = ~flag2;
if (flag2)
{
lcdcmd (0x88);
lcddata ('D');
lcddata ('E'); // display "DEV2 = 1" on lcd and send to serial port
lcddata ('V');
lcddata ('2');
lcddata ('=');
lcddata ('1');

Tx ('D');
Tx ('E');
Tx ('V');
Tx ('2');
Tx ('=');
Tx ('1');
Tx (' ');
Tx (' ');

}
else
{
lcdcmd (0x88);
lcddata ('D');
lcddata ('E'); // display "DEV2 = 0" on lcd and send to serial port
lcddata ('V');
lcddata ('2');
lcddata ('=');
lcddata ('0');

Tx ('D');
Tx ('E');
Tx ('V');
Tx ('2');
Tx ('=');
Tx ('0');
Tx (' ');
Tx (' ');

}
}


if (P0_2==1)
{
while (P0_2);
MSDelay (10);
P2_5 = ~P2_5; // toggle pin P2.5
flag3 = ~flag3; // toggle flag3
if (flag3)
{
lcdcmd (0xC0); // display "DEV3 = 0" on lcd and send to serial port
lcddata ('D');
lcddata ('E');
lcddata ('V');
lcddata ('3');
lcddata ('=');
lcddata ('1');

Tx ('D');
Tx ('E');
Tx ('V');
Tx ('3');
Tx ('=');
Tx ('1');
Tx (' ');
Tx (' ');

}
else
{
lcdcmd (0xC0);
lcddata ('D');
lcddata ('E'); // display "DEV3 = 0" on lcd and send to serial port
lcddata ('V');
lcddata ('3');
lcddata ('=');
lcddata ('0');

Tx ('D');
Tx ('E');
Tx ('V');
Tx ('3');
Tx ('=');
Tx ('0');
Tx (' ');
Tx (' ');

}
}


if (P0_3==1)
{
while (P0_3);
MSDelay (10);
P2_6 = ~P2_6; // toggle P2.6
flag4 = ~flag4; // toggle flag4
if (flag4)
{
lcdcmd (0xC8);
lcddata ('D');
lcddata ('E');
lcddata ('V'); // display "DEV4 = 1" on lcd and send to serial port
lcddata ('4');
lcddata ('=');
lcddata ('1');

Tx ('D');
Tx ('E');
Tx ('V');
Tx ('4');
Tx ('=');
Tx ('1');
Tx (' ');
Tx (' ');

}
else
{
lcdcmd (0xC8);
lcddata ('D');
lcddata ('E'); // display "DEV4 = 0" on lcd and send to serial port
lcddata ('V');
lcddata ('4');
lcddata ('=');
lcddata ('0');

Tx ('D');
Tx ('E');
Tx ('V');
Tx ('4');
Tx ('=');
Tx ('0');
Tx (' ');
Tx (' ');

}
}



}
}

void ini () // lcd initialize function
{
lcdcmd (0x38);
lcdcmd (0x0e);
lcdcmd (0x01);
lcdcmd (0x06);
}

void lcdcmd (unsigned char value ) // write commands to lcd
{
// lcdready ();
ldata = value;
rs = 0;
rw = 0;
en = 1;
MSDelay (1);
en = 0 ;

}

void lcddata ( unsigned char value ) //write data to lcd for display
{
// lcdready ();
ldata = value;
rs = 1;
rw = 0;
en = 1;
MSDelay (1);
en =0;


}

void MSDelay (unsigned int itime ) // to generate the delay in progran
{
unsigned int i,j;
for (i=0;i for (j=0;j<900;j++);


}


void Tx (unsigned char value) // to send the data on serial port
{
SBUF = value;
while (TI == 0);
TI = 0;

}


Project Feedbacks

Author: ashutoshMember Level: SilverRevenue Score: 1 out of 5
Please provide the interface diagram.The code looks fine and understandable.


Author: venugopalMember Level: SilverRevenue Score: 2 out of 52 out of 5
hi

the comments for the code and the relevant circuit diagram for the project would have been good


Post Feedback
You must Sign In to post a feedback.
Next Project: MFC-Modal dialog box
Previous Project: Checking Network Status Notification for Internet and Intranet

Return to Project Index

Post New Project


Related Projects


Advertise Here


Watch TV Channels




Contact Us   Advertise   Editors    Privacy Policy    Terms Of Use   

ISC Technologies.
2006 - 2009 All Rights Reserved.