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.

[SOLVED] Problem with interfacing LPC2148 with 16*2 LCD

Status
Not open for further replies.

lulezo

Junior Member level 3
Joined
Apr 5, 2010
Messages
27
Helped
6
Reputation
12
Reaction score
6
Trophy points
1,283
Location
sudan
Activity points
1,521
Hi guys
I am trying to interface LPC2148 with 16*2 LCD and I got nothing at all in the LCD, I don't know why, here is my code -I thought that it should work -

Note: Data connected to P0.19 P0.20 P0.21 P0.22
Enable P0.10
RS P0.13
RW P0.12


#include <LPC214X.H>
void cmd(unsigned char d);
void datal(unsigned char t);
void delay (int count);

int main()
{
IODIR0=0x00783400;
IOCLR0=0x00003400;

cmd(0x28 );
cmd(0x01);
cmd(0x02);
cmd(0x06);
cmd(0x0C);
cmd(0x80);

datal('U');

while(1);
}

void cmd(unsigned char d)
{
unsigned char a;
a=d&0xF0;
a=a<<15;

IOCLR0 = 0x00003000;
IOSET0 = 0x00000400;
IOCLR0 = 0x00780000;
IOSET0 = a;
delay(10000);
IOCLR0 = 0x00000400;

a=d&0x0F;
a=a<<19;

IOCLR0 = 0x00003000;
IOSET0 = 0x00000400;
IOCLR0 = 0x00780000;
IOSET0 = a;
delay(10000);
IOCLR0 = 0x00000400;

}

void datal(unsigned char t)
{
unsigned char b;
b=t&0xF0;
b=b<<15;

IOSET0 = 0x00002400;
IOCLR0 = 0x00780000;
IOSET0 = b;
delay(10000);
IOCLR0 = 0x00000400;

b=t&0x0F;
b=b<<19;

IOSET0 = 0x00002400;
IOCLR0 = 0x00780000;
IOSET0 = b;
delay(10000);
IOCLR0 = 0x00000400;

}

void delay(int count)
{
int j=0, i=0;

for (j=0;j<count;j++)
for (i=0;i<35;i++);
}
 

what do you get the output on lcd... Blank lcd??? or black boxex??? check if you have pull up resistor for every port pins...
put you circuit tooo
 

what do you get the output on lcd... Blank lcd??? or black boxex??? check if you have pull up resistor for every port pins...
put you circuit tooo

Thanks for your quick reply.
yeah I got black boxes which means nothing went to the lcd, not even the commands. In fact I tried another code ( which came with the kit for interfacing the lcd) and it worked fine.
I need to figure out what the problem with my code.
 

yes I did, and I am pretty sure that the only problem is with the code attached, so do you file like it is completely correct ?!
 

I did and it didn't help also, and please would you tell me why do we need a delay here ? I believe it is not required.
 

changes to be made:

cmd(0x20);
cmd(0x28)
cmd(0x01);
cmd(0x06);
cmd(0x0f);
cmd(0x80);

IOSET0 = 0x00000400;
delay(1);
IOCLR0 = 0x00780000;
delay(1);


IOSET0 = 0x00000400;
delay(1);
IOCLR0 = 0x00780000;
delay(1);

IOSET0 = 0x00002400;
delay(1);
IOCLR0 = 0x00780000;
delay(1);


IOSET0 = 0x00002400;
delay(1);
IOCLR0 = 0x00780000;
delay(1);


I mean to say that when you make enable high to low you need to keep it for few milliseconds in that state,, so add delay as i have added...

and what is the purpose of
IOSET0 = b;
delay(10000);
IOCLR0 = 0x00000400;

there is a delay(10000),, what is it used for
 

1\ IOCLR0 = 0x00003000; //here I cleared RW and RS
2\ IOSET0 = 0x00000400; //here I made En = 1
3\ IOCLR0 = 0x00780000; //here I cleared p.19 to p.22 for the data
4\ IOSET0 = a; //the command will be sent here
5\ delay(10000); //now En = 1, this delay is precisely to make this En high for a suitable amount of time
6\ IOCLR0 = 0x00000400; //now En = 0. and the data will be latched by the LCD

even though I was not convinced with your method of using a lot of delays, I tried it in my kit, and as expected it didn't work.
may be it is not a delay problem.
 

Hey guys I found that I have some problem with the Keil settings, as in the image attached, when this "use memory layout for target dialog" is ticked I got something in the LCD, even though I got weird characters rather than the expected ones, but at least there is something there. I don't know who should I tick this option, do you know guys about it ?


---------- Post added at 19:21 ---------- Previous post was at 18:25 ----------

Hey guys now it works, the problem is that I defined a and b in cmd and datal[/B[] functions as unsigned char rather than int.
now here is the program and it works fine:


#include <LPC214X.H>
void cmd(unsigned char d);
void datal(unsigned char t);
void delay (int count);

int main()
{
int i;
unsigned char m[]={"MOIZ"};

IODIR0=0x00783400;
IOCLR0=0x00003400;

delay(100*100);
delay(100*100);

cmd(0x28);
cmd(0x01);
cmd(0x02);
cmd(0x06);
cmd(0x0C);

for (i=0;i<4;i++)
{
datal(m);
}
while(1);
}

void cmd(unsigned char d)
{
int a=0;
a=d&0xF0;
a=a<<15;

IOCLR0 = 0x00003000;
IOSET0 = 0x00000400;
IOCLR0 = 0x00780000;
IOSET0 = a;
delay(10000);
IOCLR0 = 0x00000400;

a=d&0x0F;
a=a<<19;

IOCLR0 = 0x00003000;
IOSET0 = 0x00000400;
IOCLR0 = 0x00780000;
IOSET0 = a;
delay(10000);
IOCLR0 = 0x00000400;

}

void datal(unsigned char t)
{
int b=0;
b=t&0xF0;
b=b<<15;

IOSET0 = 0x00002400;
IOCLR0 = 0x00780000;
IOSET0 = b;
delay(10000);
IOCLR0 = 0x00000400;

b=t&0x0F;
b=b<<19;

IOSET0 = 0x00002400;
IOCLR0 = 0x00780000;
IOSET0 = b;
delay(10000);
IOCLR0 = 0x00000400;

}

void delay(int count)
{
int j=0, i=0;

for (j=0;j<count;j++)
for (i=0;i<35;i++);
}
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top