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.

Facing Problem Interface LPC2138 to LCD

Status
Not open for further replies.

nitinpatil

Member level 1
Member level 1
Joined
Oct 29, 2012
Messages
41
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Location
Pune, Maharashtra, India
Activity points
1,557
Facing problem in Interfacing of LPC2138 to LCD(16x2 alpha.)
Using port as
RS = 0.28
EN = 0.29
WR = GND
D0-D7 = 1.16 - 1.23
I want to use this same ports for this because of my hardware
I attach proteus connection dig. but its not working
also I attach my programme code which is simple one for testing but its not working
I stuck where is the problem
lcd.png
Code:
#include<LPC213X.h>
void delay()
{
	int i;
	for(i=0;i<900000;i++);
}
void DAT(unsigned char data)
{
	IOCLR1 = 0X00FF0000; // port 1.16 to 1.23
	
	IOSET0 = 0X10000000;
	IOSET0 = 0X20000000; // port 0.28 to 0.29
	IOSET1  = data<<16;
	delay();
	IOCLR0 = 0x20000000;
}

void CMD(unsigned int cmd)
{
	IOCLR1 = 0X00FF0000;
	IOCLR0 = 0X10000000;
	
	IOSET0 = 0x20000000;
	IOSET1 = cmd<<16;
	delay();
	IOCLR0 = 0x20000000;	
}

int main(void)
{
	IODIR1 = 0X00FF0000;
	IODIR0 = 0X30000000;
	CMD(0X38);
	delay();
	CMD(0X0C);
	delay();
	CMD(0X01);
	delay();
	CMD(0X0E);
	delay();
	CMD(0X06);
	delay();
	CMD(0X80);
	delay();
	DAT('A');
	delay();
	DAT('B');
	delay();
	return 0;
 }
Please help me...
Thanks in advance..
Nitin
 
Last edited:

This is not a direct answer to your qu ! I hv to go through many things for that :(
But here is a trick :
You can see the sample code for lcd interface in your c:/keil folder, further you can download 'code bundle' for LPC2138(NXP website) to get starting with LCD or any supported peripherals for that matter.
Just modify sourcecode accordingly for your use.
 

This is not a direct answer to your qu ! I hv to go through many things for that :(
But here is a trick :
You can see the sample code for lcd interface in your c:/keil folder, further you can download 'code bundle' for LPC2138(NXP website) to get starting with LCD or any supported peripherals for that matter.
Just modify sourcecode accordingly for your use.

I am tried the code use in keil sample but it still not working

Will you have the sample code for this
Is that initialization of LCD is right ...?
 

Ok.
Are you able to clear screen and set the cursor at first location with your program? Or nothing is happening ?

Please provide the pin mapping you used to interface the LCD.........
 

hoping that you have selected proper port and proper direction following are the commands to initialize LCD in LPC2138.

CMD(0X38);
delay();
delay();
CMD(0X0E);
delay();
delay();


0x0E will on the display and show the cursor.

try this it might work.
please let us know whether it is working or not and if it working please post the step you follow to solve the problem with LCD so that other can learn from you experience.
 

Code:
#include <LPC21xx.H>
#include <stdio.h>

void delay( )
{
		unsigned int i;
		for(i=0;i<4000;i++);
}

void lcddata(unsigned char c)
{
		IOCLR1=0x00ff0000; // output p1.16 to p1.24
		IOSET0=0x00000001; // rs =1 p0.0
		IOCLR0=0x00000002; // rw =0 p0.1
		IOSET0=0x00000004; // en=1  p0.2
		IOSET1 = c<<16;
		delay();
		IOCLR0=0x00000004; //en=0 p0.2
}

void lcdcmd(int c)
{
		IOCLR1=0x00ff0000;
		IOCLR0=0x00000001; // rs =0 p0.0
		IOCLR0=0x00000002; // rw =0 p0.1
		IOSET0=0x00000004; // en=1 p0.2
		IOSET1 = c<<16;
		delay();
		IOCLR0=0x00000004; //en=0 p0.2
}


void lcdinit()
{
		lcdcmd(0x38);
		delay();
		lcdcmd(0x0e);
		delay();

		lcdcmd(0x06);
		delay();
		lcdcmd(0x80);
		delay();
}

void lcdputs(const char * s)
{
	while(*s)
		lcddata(*s++);
}

write the main function by calling lcd data... modify the rs,rw and enable pins as your requirement.

- - - Updated - - -

Code:
#include <LPC21xx.H>
#include <stdio.h>

void delay( )
{
		unsigned int i;
		for(i=0;i<4000;i++);
}

void lcddata(unsigned char c)
{
		IOCLR1=0x00ff0000; // output p1.16 to p1.24
		IOSET0=0x00000001; // rs =1 p0.0
		IOCLR0=0x00000002; // rw =0 p0.1
		IOSET0=0x00000004; // en=1  p0.2
		IOSET1 = c<<16;
		delay();
		IOCLR0=0x00000004; //en=0 p0.2
}

void lcdcmd(int c)
{
		IOCLR1=0x00ff0000;
		IOCLR0=0x00000001; // rs =0 p0.0
		IOCLR0=0x00000002; // rw =0 p0.1
		IOSET0=0x00000004; // en=1 p0.2
		IOSET1 = c<<16;
		delay();
		IOCLR0=0x00000004; //en=0 p0.2
}


void lcdinit()
{
		lcdcmd(0x38);
		delay();
		lcdcmd(0x0e);
		delay();

		lcdcmd(0x06);
		delay();
		lcdcmd(0x80);
		delay();
}

void lcdputs(const char * s)
{
	while(*s)
		lcddata(*s++);
}
write the main function by calling lcd data... modify the rs,rw and enable pins as your requirement.
 

@kodi.sudar
I trying this code and also change as per port used I already mention in first post about port setting...
Actually only screen get bright but nothing is happen, cursor also not shown on screen.
Also I trying as per your port setting but it still stuck their...
I upload the image as per your port setting let me know it is right or wrong..?
lcd 2.png
@androidbuddy
As I mention in the code I display in the 1st post so as per the coding I think it should be work but its not working

So please help me actually I have to go for next step but I still stuck here
 

@nitinpatil
Connect Rs to 19th pin , RW to 21 and E to 22 .... then try .... it works well for me ......
 

Here again I upload my code by giving a reference of you code find the bug in this code. because its not working,
And I did the connection as per your requirement
Now i upload the connection dig and also the code try this is in your proteus for better debugging purpose
Code:
#include <LPC21xx.H>
#include <stdio.h>

void delay( )
{
		unsigned int i;
		for(i=0;i<4000;i++);
}

void lcddata(unsigned char c)
{
		IOCLR1=0x00ff0000; // output p1.16 to p1.24
		IOSET0=0x00000001; // rs =1 p0.0
		IOCLR0=0x00000002; // rw =0 p0.1
		IOSET0=0x00000004; // en=1  p0.2
		IOSET1 = c<<16;
		delay();
		IOCLR0=0x00000004; //en=0 p0.2
}

void lcdcmd(int c)
{
		IOCLR1=0x00ff0000;
		IOCLR0=0x00000001; // rs =0 p0.0
		IOCLR0=0x00000002; // rw =0 p0.1
		IOSET0=0x00000004; // en=1 p0.2
		IOSET1 = c<<16;
		delay();
		IOCLR0=0x00000004; //en=0 p0.2
}

void lcdinit()
{
		lcdcmd(0x38);
		delay();
		lcdcmd(0x0e);
		delay();
		lcdcmd(0x06);
		delay();	
		lcdcmd(0x83);
		delay();
		lcddata('W');
		delay();
	
	
}
lcd3.png
 

Here again I upload my code by giving a reference of you code find the bug in this code. because its not working,
And I did the connection as per your requirement
Now i upload the connection dig and also the code try this is in your proteus for better debugging purpose
Code:
#include <LPC21xx.H>
#include <stdio.h>

void delay( )
{
		unsigned int i;
		for(i=0;i<4000;i++);
}

void lcddata(unsigned char c)
{
		IOCLR1=0x00ff0000; // output p1.16 to p1.24
		IOSET0=0x00000001; // rs =1 p0.0
		IOCLR0=0x00000002; // rw =0 p0.1
		IOSET0=0x00000004; // en=1  p0.2
		IOSET1 = c<<16;
		delay();
		IOCLR0=0x00000004; //en=0 p0.2
}

void lcdcmd(int c)
{
		IOCLR1=0x00ff0000;
		IOCLR0=0x00000001; // rs =0 p0.0
		IOCLR0=0x00000002; // rw =0 p0.1
		IOSET0=0x00000004; // en=1 p0.2
		IOSET1 = c<<16;
		delay();
		IOCLR0=0x00000004; //en=0 p0.2
}

void lcdinit()
{
		lcdcmd(0x38);
		delay();
		lcdcmd(0x0e);
		delay();
		lcdcmd(0x06);
		delay();	
		lcdcmd(0x83);
		delay();
		lcddata('W');
		delay();
	
	
}
View attachment 83481
Code:
void lcdinit()
{
void lcdinit()
{
		lcdcmd(0x38);
		delay();
		lcdcmd(0x0e);
		delay();

		lcdcmd(0x06);
		delay();
		lcdcmd(0x80);
		delay();
}
where is your main function .. write the main function by calling lcdputs...
 

Sorry I forgot to send main function
here it is...
Code:
void main(void)
{
	IODIR1 = 0X00FF0000;
	IODIR0 = 0X00000007;
        lcdinit();
}
 

Sorry I forgot to send main function
here it is...
Code:
void main(void)
{
	IODIR1 = 0X00FF0000;
	IODIR0 = 0X00000007;
        lcdinit();
}

Code:
int main(void)
{
		

			while(1)
				
			{
					
			
				/*code for lcd print*/
					PINSEL0=0X00000000; // gpio pin 0.0 to 0.15
					PINSEL2=0X00000000; // gpio pin 1.16 to 1.31
					IODIR0=0X00000007; //p0.0 rs p0.1 r/w p0.2 e	
					IODIR1=0X00ff0000; //p1.16 to p1.24 output
					lcdinit();
					sprintf (buffer, "lcd display: %x", display); // to display the data
					lcdputs(buffer);
						

	}

display the character that you wanted to using sprintf statement
 

hi...
have a look at the images that u have posted..
the lcd supply pins are not connected...they appear to be floating
moreover even the lcd control pins are floating....
i havent gone through the code....but this is what strikes at first glance
connect the lcd supply pins and let us know about the progress...

cheers,
vijay
 

@ kodi.sundar...
I tried the code you posted but it the code is not compile giving error like..
cd.c(55): warning: #223-D: function "sprintf" declared implicitly
lcd.c(56): warning: #223-D: function "lcdputs" declared implicitly
lcd.c(62): warning: #1-D: last line of file ends without a newline
linking...
LCD.axf: Error: L6218E: Undefined symbol lcdputs (referred from lcd.o).
Target not created

@vijayjadhav.595..
I already tried by connecting this power pin and vss to ground...
may be i had wrong some where so if you have the perfect connection diagrammed for this then please post it for me, it will help me a lot.
Thanks
 

@ kodi.sundar...
I tried the code you posted but it the code is not compile giving error like..

check whether that you have a LCD routine which can display a string?

Code:
/* write a string of chars to the LCD */
void lcdputs (const char * s)
{
	while(*s)
		lcd_data(*s++);
}

If not, implement one like the example above.

Then as I mention before simply use the sprintf() routine:


Code:
 #include <stdio.h>

 char buffer [21];  // Set size to LCD width plus one null
  
 sprintf (buffer, "lcd display: %x", display); // to display the data
 lcdputs(buffer);

If you require the output as an unsigned integer representation, simply change the format specifier from %X to %u.
 

Hey friend i tried your code, its compiled successfully but it not work in proteus, this LCD just blink continuously not display anything.
Code:
sprintf (buffer, "lcd display: %x", 'd'); // to display the data
  lcdputs(buffer);
I change format specifier %x to %u, change signed to unsigned and const also but it strikes on the same issue
I did so many programs on actual hardware for LCD but I want to go for some big project but as soon as I not check on proteus how can i go to hardware directly it may be costly and deterministic output...
Help me ... !!! :-(
 

Hey friend i tried your code, its compiled successfully but it not work in proteus, this LCD just blink continuously not display anything.
Code:
sprintf (buffer, "lcd display: %x", 'd'); // to display the data
  lcdputs(buffer);
I change format specifier %x to %u, change signed to unsigned and const also but it strikes on the same issue
I did so many programs on actual hardware for LCD but I want to go for some big project but as soon as I not check on proteus how can i go to hardware directly it may be costly and deterministic output...
Help me ... !!! :-(

Upload your code. try with proteus first it will help you out to solve the issue your facing.
 

Here is full code...
Code:
#include<LPC213X.h>


void delay()
{
	int i;
	for(i=0;i<900000;i++);
}
void DAT(unsigned char data)
{
	IOCLR1 = 0X00FF0000; // port 1.16 to 1.23
	
	IOSET0 = 0X00000001;
	IOCLR0 = 0x00000002;
	IOSET0 = 0X00000004; // port 0.28 to 0.29
	IOSET1 = data<<16;
	delay();
	IOCLR0 = 0x00000004;
}

void CMD(unsigned int cmd)
{
	IOCLR1 = 0X00FF0000;
	IOCLR0 = 0X00000001;
	IOCLR0 = 0x00000002;
	IOSET0 = 0x00000004;
	IOSET1 = cmd<<16;
	delay();
	IOCLR0 = 0x00000004;	
}
void lcdputs (const char *s)
{
	while(*s)
		DAT(*s++);
}

int main(void)
{
	
	char buffer [21];
	PINSEL0 = 0X00000000;
	PINSEL1 = 0X00000000;
	IODIR1 = 0X00FF0000;
	IODIR0 = 0X00000007;
	CMD(0x38);
	delay();
	CMD(0x0e);
	delay();
	CMD(0x06);
	delay();
	CMD(0x80);
	delay();
	sprintf (buffer, "lcd display: %x", 'd'); // to display the data
  lcdputs(buffer);
	return 0;
 }
 

Here is full code...
Code:
#include<LPC213X.h>


void delay()
{
	int i;
	for(i=0;i<900000;i++);
}
void DAT(unsigned char data)
{
	IOCLR1 = 0X00FF0000; // port 1.16 to 1.23
	
	IOSET0 = 0X00000001;
	IOCLR0 = 0x00000002;
	IOSET0 = 0X00000004; // port 0.28 to 0.29
	IOSET1 = data<<16;
	delay();
	IOCLR0 = 0x00000004;
}

void CMD(unsigned int cmd)
{
	IOCLR1 = 0X00FF0000;
	IOCLR0 = 0X00000001;
	IOCLR0 = 0x00000002;
	IOSET0 = 0x00000004;
	IOSET1 = cmd<<16;
	delay();
	IOCLR0 = 0x00000004;	
}
void lcdputs (const char *s)
{
	while(*s)
		DAT(*s++);
}

int main(void)
{
	
	char buffer [21];
	PINSEL0 = 0X00000000;
	PINSEL1 = 0X00000000;
	IODIR1 = 0X00FF0000;
	IODIR0 = 0X00000007;
	CMD(0x38);
	delay();
	CMD(0x0e);
	delay();
	CMD(0x06);
	delay();
	CMD(0x80);
	delay();
	sprintf (buffer, "lcd display: %x", 'd'); // to display the data
  lcdputs(buffer);
	return 0;
 }

Include the header file "#include<stdio.h> " actually what you wanted to display ? is there any value present in the variable d ?
 

I include that stdio.h file but still not working.
Tell me will you able to run this code in your proteus, Is it working fine ?
Because if it is that then their might be problem with my proteus.

Also I tried different print routine.
Code:
void lcdputs (unsigned char *s)
{
	while(*s)
	{
		DAT(*s++);
	}
}
I tried to change unsigned to const and vice versa
And send the value by this code
Code:
lcdputs("welcome");
Actually this is working in actual hardware as I tried before, but not here on proteus
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top