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] No output in lcd interface with lpc2134?

Status
Not open for further replies.

ps_arunkumar

Member level 1
Joined
Nov 24, 2011
Messages
36
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,545
Hi all,

I am trying to interface to LCD with LPC2134. I have not seeing any output in the LCD. I followed the program posted and I tried to change the ports to 1 but its not working. Please tell me what I did wrong.

P1.16-->RS
P1.17-->En
P1.20 to P1.23--> Data pin 4 to 7

Code:
#include<lpc213x.h>
#include "lcd1.c"

int main()
{
	
	IODIR1=0x00FF0000;
	IOCLR1=0x00FF0000;

	lcd_init();

	cursor(1,5);
	lcd_write("Test");
	cursor(2,3);
	lcd_write("program");

	while(1);
}

Code:
#include <LPC213x.h>
#define lcd_delay 1000

void delay(int ms)
{	
	int i,n;
	for (n=0; n<ms; n++)
	{
		for (i=0; i<lcd_delay; i++); /* For 1 ms */
	}
}

void lcd_send_command(int command)
{
	IOCLR1=0x00010000;	  					
	IOSET1=0x00020000;						
	IOSET1= (command & 0x00F00000);			
	IOCLR1=0x00020000;		   			
	delay(2);			   				
	IOCLR1=0x00F00000;						
											
	IOSET1=0x00020000;
	IOSET1=((command & 0x000F0000)<<4);		
	IOCLR1=0x00020000;
	delay(2);
	IOCLR1=0x000F0000;						
}
void lcd_send_data(int data)
{
	IOSET1=0x00030000;
	IOSET1=(data & 0x00F00000);
	IOCLR1=0x00020000;
	delay(2);
	IOCLR1=0x00F00000;

	IOSET1=0x00020000;
	IOSET1=((data & 0x000F0000)<<4);
	IOCLR1=0x00020000;
	delay(2);
	IOCLR1=0x000F0000;
}

void lcd_write(const char string[])
{
	 unsigned char x=0;
	 while(string[x]!='\0')
	 {
	 	delay(2);
		lcd_send_data(string[x]);
		x++;
	 }
}
void cursor(int row, int column)
{
	if(row==1)
	{
		lcd_send_command(0x00800000 +(column-1));
	}
	else if(row==2)
	{
		lcd_send_command(0x00C00000 + (column-1));
	}
}
void lcd_init(void)
{
	lcd_send_command(0x00020000);
	lcd_send_command(0x00280000);
	lcd_send_command(0x00060000);
	lcd_send_command(0x00080000);
	lcd_send_command(0x000C0000);
	lcd_send_command(0x00010000);
	delay(100);
}
 

Hai

Which compiler you are using? Because i am not aware that we can include a c source file just like header..

#include "lcd1.c"

Thanks
 

Which compiler you are using? Because i am not aware that we can include a c source file just like header..

#include "lcd1.c"

Although not consider a "Good Coding Practice," the #include of any file containing compiler directives, C code, etc, can be compiled.

The #include compiler directive, for all practical purposes, replaces itself with the contents of the specified text file at that position in the source file.

You can verify this fact by simply changing the name of a header file from xxxxxx.h to xxxxxx.c, xxxxxx.txt, etc, along with the associated #include xxxxxx.c.

However, a better coding technique would be to write a header file containing the function prototypes of the LCD routines and replace the C file with header file as #include lcd1.h.

BigDog
 

The vast majority of LCD driver issues are due to the incorrect initialization of the LCD. Incorrect delays or delay routines and initialization command sequences can typically be the cause of the issue.

Accurate software delays can normally only be accomplished with assembly routines, which are not dependent on compiler optimization of the C code.

What is the crystal frequency, oscillator and PLL configuration of your LPC2138? These values are required for the generation of accurate delays.

On the hardware side, floating inputs like the D0-D3 pins of the LCD when operating in 4-bit mode can be an issue, recommend tying them to ground (Vss or GND).

The display contrast level can also complicate matters if not properly implemented. How have you dealt with the display contrast line (Vo)?

What is make and manufacture of your LCD? Do you have its datasheet? Do you know the LCD controller used, HD44780, KS0108, etc?

What is the operating voltage required by the LCD? Many LCDs cannot be driven correctly by the 3.3V GPIOs of some ARMs.

If you provide the info request above, I will attempt to assist you further.


BigDog
 

I am happy to answer all your questions but before that the same program worked fine when i used it for Port 0 but when i attempted to change the port to 1, it seems not to work.

Crystal frequency:12Mhz and i am not using the PLL.

I am using Proteus for the simulation.

The below is the original program which was working good. I modified to work with Port1
Code:
#include <LPC213x.h>
#define lcd_delay 1000

void delay(int ms)
{	
	int i,n;
	for (n=0; n<ms; n++)
	{
		for (i=0; i<lcd_delay; i++); /* For 1 ms */
	}
}

void lcd_send_command(unsigned char command)
{
	IOCLR0=0x00000001;	  					
	IOSET0=0x00000002;						
	IOSET0= (command & 0x000000f0);			
	IOCLR0=0x00000002;		   			
	delay(2);			   				
	IOCLR0=0x000000F0;						
											
	IOSET0=2;
	IOSET0=((command & 0x0000000f)<<4);		
	IOCLR0=2;
	delay(2);
	IOCLR0=0x000000F0;						
}
void lcd_send_data(unsigned char data)
{
	IOSET0=0x00000003;
	IOSET0=(data & 0x000000F0);
	IOCLR0=0x00000002;
	delay(2);
	IOCLR0=0x000000F0;

	IOSET0=0x00000002;
	IOSET0=((data & 0x0000000F)<<4);
	IOCLR0=0x00000002;
	delay(2);
	IOCLR0=0x000000F0;
}

void lcd_write(const unsigned char string[])
{
	 unsigned char x=0;
	 while(string[x]!='\0')
	 {
	 	delay(2);
		lcd_send_data(string[x]);
		x++;
	 }
}
void cursor(unsigned char row, unsigned char column)
{
	if(row==1)
	{
		lcd_send_command(0x00000080 +(column-1));
	}
	else if(row==2)
	{
		lcd_send_command(0x000000C0 + (column-1));
	}
}
void lcd_init(void)
{
	lcd_send_command(0x00000002);
	lcd_send_command(0x00000028);
	lcd_send_command(0x00000006);
	lcd_send_command(0x00000008);
	lcd_send_command(0x0000000C);
	lcd_send_command(0x00000001);
	delay(100);
}
 

I am using Proteus for the simulation.


If we are dealing with simulations rather than actual hardware,
please zip up the Proteus Simulation file and upload as well.

Include both the original and modified designs if they are available.

Doing so would aid in the troubleshooting.

BigDog
 

I have attached the code and proteus simulation file.
 

Attachments

  • lcd.rar
    198.3 KB · Views: 72

Dear arun,

I have verified your design and also code.


you have made minor mistakes in the following functions

1. void lcd_send_data(unsigned int data);
2. void cursor(unsigned int row, unsigned int column);

Here you have to shift the data by 16. otherwise the data which you are trying to transmit will become zero during AND process. Similarly the same mistake appears at the column variable also.

and please verify the device selection for the non working code. Because at first i didnt get port 1.

I dont have work experience in ARM so i couldnt trace the issue. So i have directly modified in the working code and verified in the proteus. It is working fine
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top