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.

8051 lcd interfacing problem

Status
Not open for further replies.

hashim5003

Junior Member level 2
Junior Member level 2
Joined
Jul 21, 2013
Messages
21
Helped
1
Reputation
2
Reaction score
1
Trophy points
3
Visit site
Activity points
116
I am interfacing at89s52 with 16*2 lcd. Problem is that lcd don't shows the character that I have written in the code. it shows some random character or weird character. Plz chk my code if it's correct or not:

Code:
#include<reg52.h>
sfr ldata=0x90;  
sbit rs=P3^7; 
sbit rw=P3^6; 
sbit en=P3^5;

void delay()
{
	TMOD = 0x01;
	TH0 = 0x00;
	TL0 = 0x00;
	TR0 = 1;
	while (TF0==0);
	TF0 = 0;
	TR0 = 0;
}

void lcdcmd(unsigned char u)
{
	ldata=u;
	en=1;
	rs=0;
	rw=0;
	delay();
	en=0;
	delay();
}
void lcddata(unsigned char v)    
{
	ldata=v;
	en=1;
	rs=1;
	rw=0;
	delay();
	en=0;
}

void lcdini()    
{
	delay();
	lcdcmd(0x30);
	delay();
	delay();
	lcdcmd(0x30);
	delay();
	delay();
	lcdcmd(0x30);
	delay();
	lcdcmd(0x38);   
	delay();
	lcdcmd(0x0c);       
	delay();
	lcdcmd(0x80);
	delay();

}
void main()
{
	lcdini();

	lcddata('A');
	delay();
	lcddata('B');
	delay();
	lcddata('C');
	delay();

	while(1);
}
 

I don't know C language because i am an assembly language programmer but in your code i didn't see the busy flag checking before initialization of the lcd.......First of all you should check the busy flag or give a delay of about 20ms before issuing any command...
 

HI hashim
apply the following changes to your code
Code:
void delay(unsigned int ms)  //This I have added you may use your own delay 
{
int i , j
for(i=0 ; i<ms ; i++)
{
for(j = 0 ; j<1275 ; j++);
}
}void LCD_init()
{
lcdcmd(0x38);    // Initialize 2 lines 5*7    
lcdcmd(0x0C ) ;  //Cursor OFF
lcdcmd(0x01) ;   
lcdcmd(0x06) ; 
lcdcmd(0x80) ; 
}
void lcddata(unisgned char data)
{  ladata = data ;  RS = 1 ; RW = 0 ; EN = 1 ; delay(5) ; EN = 0 ;}
void lcdcmd(unsigned char cmd)
{ ldata = data ; RS = 0 ; RW = 0 ; EN =1 ; delay(5) ; EN = 0 ; }
void main()
{
ladta = 0x00 ;   // Making the PORT as Output which is connected with Data Lines of LCD

//rs = 1 ; rw = 1 ; en = 1 ; 
// Also make the pins as OUTPUT which are connected to RS , RW and Enable Pins

LCD_init() ; 
delay(1000);
lcddata('A'); delay(100); lcddata('B'); 
}
 
Last edited:

HI hashim
apply the following changes to your code
Code:
void delay(unsigned int ms)  //This I have added you may use your own delay 
{
int i , j
for(i=0 ; i<ms ; i++)
{
for(j = 0 ; j<1275 ; j++);
}
}void LCD_init()
{
lcdcmd(0x38);    // Initialize 2 lines 5*7    
lcdcmd(0x0C ) ;  //Cursor OFF
lcdcmd(0x01) ;   
lcdcmd(0x06) ; 
lcdcmd(0x80) ; 
}
void lcddata(unisgned char data)
{  ladata = data ;  RS = 1 ; RW = 0 ; EN = 1 ; delay(5) ; EN = 0 ;}
void lcdcmd(unsigned char cmd)
{ ldata = data ; RS = 0 ; RW = 0 ; EN =1 ; delay(5) ; EN = 0 ; }
void main()
{
ladta = 0x00 ;   // Making the PORT as Output which is connected with Data Lines of LCD

//rs = 1 ; rw = 1 ; en = 1 ; 
// Also make the pins as OUTPUT which are connected to RS , RW and Enable Pins

LCD_init() ; 
delay(1000);
lcddata('A'); delay(100); lcddata('B'); 
}

Tried it. still no difference. showing random characters

- - - Updated - - -

one thing i have noticed is that when I power up controller and lcd. it shows correctly for some time and then shows some random character
 

Apply some delay before each command as JAMLAL also said
like
Code:
void LCD_init()
{
lcdcmd(0x38);    // Initialize 2 lines 5*7    
delay(100);  //Try with 20 or 30
lcdcmd(0x0C ) ;  //Cursor OFF
delay(100);
lcdcmd(0x01) ; delay(100);   
lcdcmd(0x06) ;  delay(100);
lcdcmd(0x80) ; delay(100);
}
Also Upload any Image if you have of the same if still it is not working
 

Apply some delay before each command as JAMLAL also said
like
Code:
void LCD_init()
{
lcdcmd(0x38);    // Initialize 2 lines 5*7    
delay(100);  //Try with 20 or 30
lcdcmd(0x0C ) ;  //Cursor OFF
delay(100);
lcdcmd(0x01) ; delay(100);   
lcdcmd(0x06) ;  delay(100);
lcdcmd(0x80) ; delay(100);
}
Also Upload any Image if you have of the same if still it is not working


I will take the image tomorrow.
i have used delays.
could it be the problem of lcd hardware?
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top