Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic 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.

Register Log in

trouble with 4-bit lcd using LP2114

Status
Not open for further replies.

pavan_85

Member level 1
Joined
Jul 3, 2008
Messages
33
Helped
1
Reputation
2
Reaction score
0
Trophy points
1,286
Location
hyderabad
Activity points
1,497
Hi all,
I wanted to write a code for 4-bit mode LCD(16x2) using LPC 2114 Microcontroller.
I am unable to figure out what went wrong. please go through my code and help me out.
The code which i wrote worked quite well using AT89c52(not the syntax, but the concept...)

Code:
//D4 - p1.31; D5 - p1.30; D6 - p1.29; D7 - p1.28; RS - p1.27; EN - p1.26

#include <lpc21xx.h>
#include <stdio.h>


#define RS 0X08000000;
#define EN 0x04000000;

void LCD_INIT	(void			);
void LCD_CMD	(unsigned char	);
void LCD_DATA	(unsigned char	);
void LCD_DISPLAY(unsigned char *);
void delay		(unsigned int 	);

int main(void)
{
	
	//configuring ports p1.31-p1.26 as outputs
	PINSEL2 = 0x00000030;
	IO1DIR  = 0xFF000000;
	
	LCD_INIT();
	LCD_CMD(0x80);
	LCD_DISPLAY("Jai Hanuman");

	return 0;
		
}

void LCD_INIT()
{
	LCD_CMD(0x33);
	delay(25);
	LCD_CMD(0x32);
	delay(25);
	LCD_CMD(0x28);
	delay(25);
	LCD_CMD(0x0E);
	delay(25);
	LCD_CMD(0x06);
	delay(25);
	LCD_CMD(0x01);
	delay(25);
}

void LCD_CMD(unsigned char value)
{
	unsigned long val,val_1;

	val   	= val_1 = value;
	val   	= value << 24;
	val_1 	= value << 28;

	IO1CLR |= RS;
	IO1SET |= val&0xF0000000;
	IO1SET |= EN;
	delay(1);
	IO1CLR |= EN; 
	IO1CLR  = 0xF0000000;
	IO1SET |= val_1&0xF0000000;
	IO1SET |= EN;
	delay(1);
	IO1CLR |= EN;	
}

void LCD_DATA(unsigned char value)
{
	unsigned long val,val_1;

	val   	= val_1 = value;
	val   	= value << 24;
	val_1 	= value << 28;

	IO1SET |= RS;
	IO1SET |= val&0xF0000000;
	IO1SET |= EN;
	delay(1);
	IO1CLR |= EN; 
	IO1CLR  = 0xF0000000;
	IO1SET |= val_1&0xF0000000;
	IO1SET |= EN;
	delay(1);
	IO1CLR |= EN;	
}

void LCD_DISPLAY(unsigned char *take)
{
	while(*take)
	{
		LCD_DATA(*take++);
	}
}


void delay(unsigned int it)
{
	int i,j;
	for(i=0;i<it;i++)
		for(j=0;j<1000;j++);
}
Please do the needful.....
pavan:cry:
 

bobcat1

Advanced Member level 4
Joined
Jul 10, 2002
Messages
1,288
Helped
99
Reputation
198
Reaction score
34
Trophy points
1,328
Activity points
8,547
HI

LCD display is a very slow hardware!

And the LPC21xx is a very fast device! even if you are not using the PLL

There for the answer to your question probably lay in the Interface between your LCD and the UC

Try to slow down the signal (use longer delay)

All the best

Bobi


The microcontroller specialist
 

pavan_85

Member level 1
Joined
Jul 3, 2008
Messages
33
Helped
1
Reputation
2
Reaction score
0
Trophy points
1,286
Location
hyderabad
Activity points
1,497
i have added delay but the result remain the same.......
 

betwixt

Super Moderator
Staff member
Joined
Jul 4, 2009
Messages
14,717
Helped
4,810
Reputation
9,637
Reaction score
4,590
Trophy points
1,393
Location
Aberdyfi, West Wales, UK
Activity points
125,363
Try 100mS delay before LCD_INIT is called in your 'main' function.

Most LCD controllers take about 100mS to initialize after power is turned on and they will not accept any commands until then.

Brian.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top