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 in interfacing LCD with LPC2138

Status
Not open for further replies.

abhishekdixit

Full Member level 2
Joined
Dec 30, 2011
Messages
124
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,296
Location
India
Activity points
2,182
hi,
i am using LPC2138 in my programming. i want to use a simple 16X2 LCD in my programming in which i want to initilize my LCD by LPC2138 micro controller. but my LCD is not working when i simulate my program on proteus. i am adding my program & connection of LCD with my controller on proteus. please help me to initilize my LCD.
Thanks.

Code:
#include <LPC213X.H>
#define RS 4
#define RW 5
#define EN 6

void lcd_cmd(unsigned char);
void lcd_data(unsigned char);
void shift(int);
void delay(int);

unsigned char array[11]="ESSEL SHYAM";
unsigned char array1[12]="WELCOMES U";
unsigned char array2[10]="booting...";

int main(void)
{
int i;
{
 lcd_cmd(0x38);
 delay(1000);
 lcd_cmd(0x0e);
 delay(1000);
 lcd_cmd(0x06);
 delay(1000);
 lcd_cmd(0x01);
 delay(1000);
 while(1)
 {
 	for(i=0;i<11;i++)
	{
		lcd_data(array[i]);
		delay(1000);
	}
	lcd_cmd(0x0c0);
	delay(1000);
	for(i=0;i<12;i++)
	{
		lcd_data(array1[i]);
		delay(1000);
	}
	lcd_cmd(0x01);
	delay(1000);
	for(i=0;i<10;i++)
	{
	lcd_data(array2[i]);
	delay(1000);
	}
	lcd_cmd(0x0c0);
	delay(1000);
	for(i=0;i<16;i++)
	{
	lcd_data(0x0ff);
	delay(2000);
	}
 }
 }
 return 0;
}

void lcd_cmd(unsigned char value)
{
	IOSET0|=1<<RS;
	IOCLR0|=1<<RW;
	shift(value);
	IOSET0|=1<<EN;
	delay(1000);
	IOCLR0|=1<<EN;
}

void lcd_data(unsigned char value)
{
	IOCLR0|=1<<RS;
	IOCLR0|=1<<RW;
	shift(value);
	IOSET0|=1<<EN;
	delay(1000);
	IOCLR0|=1<<EN;
}

void shift(int value1)
{
	unsigned int j;
	for(j=0;j<8;j++)
	{
		if(value1 & 0x01)
		{		  
			IOSET0|=1<<(j+7);
		}
		else
		{
			IOCLR0|=1<<(j+7);
		}
		value1=value1>>1;
	 }
}

void delay(int a)
{
 unsigned int i,j;
 for(i=0;i<a;i++);
 for(j=0;j<a;j++);
}

and the simulating diagram of my project is:
View attachment New Picture.bmp

with regards,
Abhishek Dixit
 

The delay's you use is not sufficient, Read the datasheet of lcd and use proper delay's between the commands
 
  • Like
Reactions: mgate

    mgate

    Points: 2
    Helpful Answer Positive Rating
hello nandhu015,
as per your post, i provide 1ms delay in my code, which is sufficient for initializing the LCD. but still my LCD is not initialize. i am again sending you my code schematic diagram of my project. please check it.
Code:
#include <LPC213X.H>
#define RS 4
#define RW 5
#define EN 6

void lcd_cmd(unsigned char);
void lcd_data(unsigned char);
void shift(int);
void delay(int);

unsigned char array[11]="ESSEL SHYAM";
unsigned char array1[12]="WELCOMES U";
unsigned char array2[10]="booting...";

int main(void)
{
int i;
{
 lcd_cmd(0x38);
 delay(3);
 lcd_cmd(0x0e);
 delay(3);
 lcd_cmd(0x06);
 delay(3);
 lcd_cmd(0x01);
 delay(3);
 while(1)
 {
 	for(i=0;i<11;i++)
	{
		lcd_data(array[i]);
		delay(3);
	}
	lcd_cmd(0x0c0);
	delay(3);
	for(i=0;i<12;i++)
	{
		lcd_data(array1[i]);
		delay(3);
	}
	lcd_cmd(0x01);
	delay(3);
	for(i=0;i<10;i++)
	{
	lcd_data(array2[i]);
	delay(3);
	}
	lcd_cmd(0x0c0);
	delay(3);
	for(i=0;i<16;i++)
	{
	lcd_data(0x0ff);
	delay(3);
	}
 }
 }
 return 0;
}

void lcd_cmd(unsigned char value)
{
	IOSET0|=1<<RS;
	IOCLR0|=1<<RW;
	shift(value);
	IOSET0|=1<<EN;
	delay(1000);
	IOCLR0|=1<<EN;
}

void lcd_data(unsigned char value)
{
	IOCLR0|=1<<RS;
	IOCLR0|=1<<RW;
	shift(value);
	IOSET0|=1<<EN;
	delay(1000);
	IOCLR0|=1<<EN;
}

void shift(int value1)
{
	unsigned int j;
	for(j=0;j<8;j++)
	{
		if(value1 & 0x01)
		{		  
			IOSET0|=1<<(j+7);
		}
		else
		{
			IOCLR0|=1<<(j+7);
		}
		value1=value1>>1;
	 }
}

/*void delay(int a)
{
 unsigned int i,j;
 for(i=0;i<a;i++);
 for(j=0;j<a;j++);
}*/

void delay(int a)
{	unsigned int i;
   for(i=0;i<a;i++)
   {
	T0MR0= 3000;
	T0MCR= 0x04;
	T0TCR= 0x01;
	while(T0TC<T0MR0);
	T0TC=0;
}
}

and the diagram is here:
View attachment New Picture.bmp
 

According to manual, 1ms is not enough in the initialization ...

check page 45 and 46 of HD44780 Datasheet

also keep in mind that the controller only executes data on the EN negative transition, and you are not poling busy flag... I suggest you start you bigger delays and try to reduce them progressively
 
Last edited:

Code:
#include <lpc21xx.h>
#include "delay.h"



#define RS_High	IO0SET=(1<<2)
#define EN_High	IO0SET=(1<<3)
#define RS_Low	IO0CLR=(1<<2)
#define EN_Low	IO0CLR=(1<<3)


void lcd_cmd(unsigned char cmd) ;
void lcd_char(unsigned char data) ;
void lcd_init(void);
void shift(unsigned char value);
void lcd_string(char *dat);

void main(void)
{
		lcd_init();
		lcd_cmd(0x80) ;
		lcd_string("Hello") ;
		while(1);		
}

void lcd_cmd(unsigned char cmd) 
{
		unsigned char temp;
	
		temp=cmd&0xF0;
		temp=temp>>4;
		RS_Low;
		shift(temp);
		EN_High;
		delay(5000);
		EN_Low;
	
		temp=cmd&0x0F;
		shift(temp);
		EN_High;
		delay(5000);
		EN_Low;
	
}
void lcd_char(unsigned char data) 
{
		unsigned char temp;
	
		temp=data&0xF0;
		temp=temp>>4;
		RS_High;
		shift(temp);
		EN_High;
		delay(5000);
		EN_Low;
	
		temp=data&0x0F;
		shift(temp);
		EN_High;
		delay(5000);
		EN_Low;
	
}

void lcd_string(char *dat) // string transmitting function
{
	while(*dat != '\0')
	{
		lcd_char(*dat++);
	}
}

void lcd_init(void)	// LCD initializing function
{
	
		PINSEL0=0x00000000;
		IO0DIR=0x000000FF;
		lcd_cmd(0x33);
		lcd_cmd(0x32);
		lcd_cmd(0x28);
		lcd_cmd(0x0e);
		lcd_cmd(0x01);
}

void shift(unsigned char value)
{
		unsigned char j=0x00;
		for(j=4;j<=7;j++)										// j represents pin number in which data lines of lcd connected
		{
				if(value & 0x01)
				{
						IO0SET |=(1<<j);
				}
				else 
				{
						IO0CLR |=(1<<j);
				}
				value=value>>1;
		}
}
[ATTACH=CONFIG]76416._xfImport[/ATTACH]
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top