Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

problem Interfacing 16x2 lcs display with at89c51 microcontroller

Status
Not open for further replies.

kaus9952083382

Member level 4
Joined
Oct 31, 2011
Messages
69
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Activity points
1,755
sir i have interface 16x2 lcd display with microcontroller at89c51 and it is working fine in proteus as well as keil compiler ... but when i m burning hex code and interfacing with my hardware i am not able to get the output .... i m posting my coding over here .... please help me out ... thanks in advance


#include<reg51.h>
#define dp P0
sbit rs=P0^1;
sbit en=P0^2;
sbit rw=P0^3;
lcdcomm(unsigned char val);
lcddat(unsigned char val);
msdelay(unsigned int val);
write_nibble(unsigned int val);

unsigned char mydat[]="hello kaushal";
unsigned char urdat[]="hello amit";

main()
{
P0=0xff;
msdelay(10);
lcdint();
lcdcomm(0x01);
msdelay(1);
lcdcomm(0x80);
msdelay(1);
lcddat('*');
msdelay(1);
lcdcomm(0x82);
msdelay(1);
dis_measure();
lcdcomm(0xc2);
msdelay(1);
dis_d_t();
}

unsigned char z;

lcdint()
{
rs=0;
rw=0;
dp=0x28;

en=1;
msdelay(1);
en=0;
msdelay(1);

lcdcomm(0x28);
msdelay(1);

lcdcomm(0x0f);
msdelay(1);
}

dis_measure()
{
unsigned char z;
for(z=0;z<=15;z++)
{
lcddat(urdat[z]);
msdelay(1);
}

}
dis_d_t()
{
unsigned char z;
for(z=0;z<=15;z++)
{
lcddat(mydat[z]);
msdelay(1);
}

}


/********************************/

lcdcomm(unsigned char val)
{
rs=0;
rw=0;
write_nibble();
}

/*****************************/

lcddat(unsigned char val)
{
rs=1;
rw=0;
write_nibble();
}

/**************************/

msdelay(unsigned int val)
{
unsigned int i,j;
for(i=0;i<=val;i++)
for(j=0;j<=200;j++);
}

/************************/

write_nibble(unsigned int val)
{
unsigned char i,j,k;
i=val&0xf0;
j=dp&0x0f;
dp=j|i;
en=1;
msdelay(1);
en=0;
msdelay(1);
val=val<<4;
i=val&0xf0;
k=dp&0x0f;
dp=k|i;
en=1;
msdelay(1);
en=0;
msdelay(1);
}
 

if the simulated in proteus really means a problem in the hardware
check u're hardware ...
make sure that the pins RS conected to p0.1
pins E conected to p0.2
pins RW conected to p0.3,and
pin data D0-D7
 

sir i m sure tht i have connected the pins properly ... nd one more thing i removed the rw pin from Port 0^3 and grounded it as it is not required in 4 bit operation
 

Check whether you have connected the data pins of the LCD in order. i.e. D0 to P1_0; D1 to P1_1 etc. Maybe you got every connection ok. Then check the microcontroller by writing a simple test program.
 

sir this is my new coding and circuit diagram.....

#include<reg51.h>
#define dp P2
sbit rs=P1^0;
sbit en=P1^1;
lcdcomm(unsigned char val);
lcddat(unsigned char val);
msdelay(unsigned int val);
write_nibble(unsigned int val);

unsigned char mydat[]="hello kaushal";
unsigned char urdat[]="hello amit";

main()
{
P2=0xff;
msdelay(20);
lcdint();
lcdcomm(0x01);
msdelay(10);
lcdcomm(0x80);
msdelay(1);
lcddat('*');
msdelay(1);
lcdcomm(0x82);
msdelay(1);
dis_measure();
lcdcomm(0xc2);
msdelay(1);
dis_d_t();
}

unsigned char z;

lcdint()
{
rs=0;
dp=0x28;

en=1;
msdelay(20);
en=0;
msdelay(10);

lcdcomm(0x28);
msdelay(1);

lcdcomm(0x0f);
msdelay(1);
}

dis_measure()
{
unsigned char z;
for(z=0;z<=15;z++)
{
lcddat(urdat[z]);
msdelay(10);
}

}
dis_d_t()
{
unsigned char z;
for(z=0;z<=15;z++)
{
lcddat(mydat[z]);
msdelay(10);
}

}


/********************************/

lcdcomm(unsigned char val)
{
rs=0;
write_nibble();
}

/*****************************/

lcddat(unsigned char val)
{
rs=1;
write_nibble();
}

/**************************/

msdelay(unsigned int val)
{
unsigned int i,j;
for(i=0;i<=val;i++)
for(j=0;j<=200;j++);
}

/************************/

write_nibble(unsigned int val)
{
unsigned char i,j,k;
i=val&0xf0;
j=dp&0x0f;
dp=j|i;
en=1;
msdelay(10);
en=0;
msdelay(10);
val=val<<4;
i=val&0xf0;
k=dp&0x0f;
dp=k|i;
en=1;
msdelay(10);
en=0;
msdelay(10);
msdelay(200);
}
 

this is my hardware circuit.....

File1-lcd.jpg
 

this is my hardware circuit.....

View attachment 63711

:!:Whenever you use the internal flash-ROM of 8051, connect the EA(pin 31) to VCC. If at all you need an external ROM you have to ground it since it is active 'low'.
So, in the hardware connect pin 31 to VCC.

P.S. Proteus does not take that into account, so you got the result in simulation
 

Sir .... I have corrected connected the pin .... Even varied the delay ..... But it is still not working
 

I agree freddy.....
whether the EA pin (31) is connected to VCC?
EA pin (31) must be connected to VCC
 

now i have made the connection proper .... is there a problem with delay
 

Now it seems the pull-up resistors to the ports in use are missing. This could be the reason if rest is OK.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top