lcd problem using 8051.

Thread Starter

ahmed847

Joined May 1, 2010
1
Hi everyone,

I am interfacing lcd (JHD 162A) using 8051(89c51). The lcd's lamp only lit up otherwise nothing is displaying on the lcd.

here is the link to lcd datasheet:
http://www.egochina.net.cn/eBay/Download/JHD162A.pdf


i have checked all the connections to the lcd and they are good.

I wrote the code on keil uvision4

please tell me the problem!

your help is greatly appriciated

here is my code:


Rich (BB code):
#include<regx51.h>
void lcdmd(unsigned char value);
void lcddata(unsigned char value);
void busyflag();
void delay(unsigned char value);
       
sbit rs=P2^0;
sbit rw=P2^1;
sbit e=P2^2;
sbit busy=P1^7;
sfr ldata=0x90;

int main(){



P0_2=0;         //just for checking

//initilization
//step 1
delay(20);
rs=0;
rw=0;
P1_7=0;
P1_6=0;
P1_5=1;
P1_4=1;

e=1;
delay(200);
e=0;

//step 2
delay(10);
rs=0;
rw=0;
P1_7=0;
P1_6=0;
P1_5=1;
P1_4=1;

e=1;
delay(200);
e=0;

//step 3
delay(200);
rs=0;
rw=0;
P1_7=0;
P1_6=0;
P1_5=1;
P1_4=1;

e=1;
delay(200);
e=0;

//step 4
delay(100);
busyflag();
rs=0;
rw=0;
P1_7=0;
P1_6=0;
P1_5=1;
P1_4=0;

e=1;
delay(200);
e=0;

delay(100);
rs=0;
rw=0;
P1_7=0;
P1_6=0;
P1_5=1;
P1_4=0;

e=1;
delay(200);
e=0;

 // lines and font
 delay(100);
rs=0;
rw=0;
P1_7=1;
P1_6=0;
P1_5=0;
P1_4=0;

e=1;
delay(200);
e=0;

delay(100);
rs=0;
rw=0;
P1_7=0;
P1_6=0;
P1_5=0;
P1_4=0;

e=1;
delay(200);
e=0;

delay(100);
rs=0;
rw=0;
P1_7=1;
P1_6=0;
P1_5=0;
P1_4=0;

e=1;
delay(200);
e=0;

delay(100);
rs=0;
rw=0;
P1_7=0;
P1_6=0;
P1_5=0;
P1_4=0;

e=1;
delay(200);
e=0;

delay(100);
rs=0;
rw=0;
P1_7=0;
P1_6=0;
P1_5=0;
P1_4=1;

e=1;
delay(200);
e=0;

delay(100);
rs=0;
rw=0;
P1_7=0;
P1_6=0;
P1_5=0;
P1_4=0;

e=1;
delay(200);
e=0;

// I/D  S
delay(100);
rs=0;
rw=0;
P1_7=0;
P1_6=1;
P1_5=1;
P1_4=1;

e=1;
delay(200);
e=0;


P0_3=0; //just for checking

//initilization ends
lcdmd(0x0E);
lcdmd(0x06);
lcddata('P');
lcddata('h');
lcddata('a');
lcddata('s');
lcddata('e');
lcddata('1');
lcdmd(0xC0);
lcddata('P');
lcddata('h');
lcddata('a');
lcddata('s');
lcddata('e');
lcddata('2');
while(1){
if(P3_1==0){
lcddata(' ');
lcddata('o');
lcddata('n');
}
else{
lcddata(' ');
lcddata('o');
lcddata('f');
lcddata('f');
}

if(P3_0==0){
lcdmd(0x86);
lcddata(' ');
lcddata('o');
lcddata('n');
}
else{
lcdmd(0x86);
lcddata(' ');
lcddata('o');
lcddata('f');
lcddata('f');
}
}










return 0;
}


void lcdmd(unsigned char value){
busyflag();
ldata=value;
rs=0;
rw=0;
e=1;
delay(200);
e=0;

return;

}


void lcddata(unsigned char value){
busyflag();
ldata=value;
rs=1;   //data register
rw=0;   //write

e=1;
delay(200);
e=0;

return;
}



void busyflag(){

             rs=0;
             rw=1;
             busy=1;    //input

             while(busy==1){
             e=0;
             delay(200);
             e=1;
             }

             return;
             }


void delay(unsigned char value){
unsigned int i,j;
for(i=0;i<value;++i)
for(j=0;j<1275;++j);

}
 
Last edited by a moderator:

ErnieM

Joined Apr 24, 2011
8,377
Wow, 281 lines of source code and not one single comment. Assuming you send the correct bits to the correct pins, delays with these things are vital, so make em painfully long until it works, then back off from there.

The good news is as this is one of the most common applications using a standard device in a standard format I would suggest you spend a good 5 to 10 minutes using the Google page.

Google is your friend.
 

astrotom

Joined Jul 14, 2012
16
To help you you would need to supply details about about pin connections. Which are connected to which pins? And most importantly, have you connected a potentiometer of 10k ohms to pin 3, 2 and 1? And if you have, use the potentiometer to increase the voltage. The default voltage is too low and hence you wont see anything on the screen. You should then be able to see atleast a cursor o the screen. And I don't understand your need for a busy flag function. You actually never read from the lcd. Remove the function and and all calls to it. It's useless.

On another note, the delays for latching is too long. Latching delay is the delay b/w e=1 and e=0. A delay of 1000 cpu cycles ie. 1000 loops is more than enough. And if it works, try decreasing it till a suitable value.
 

shubham161

Joined Jul 22, 2012
47
I think that the person who wrote the code is the most favorable person for its debugging. And in your case, it's you.

I am lazy enough to go through all the code and I know that i'd not be able to find the error easily unless you give me a flow chart of the program.

But something i'd like to recommend you

Rich (BB code):
lcddata('P'); lcddata('h'); lcddata('a'); lcddata('s'); lcddata('e'); lcddata('1');
instead of sending all letters independently, why don't your save them in a array and use one other function to pass them one by one. That would be a great time saver and will make your code clean.
 
Top