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.

Problem in interfacing LCD

Status
Not open for further replies.

Laxman Kumar

Junior Member level 1
Joined
Jan 19, 2014
Messages
17
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
123
I am using P89V51RD2 microcontroller and trying to interface with 16x2 LCD (jhd162a)...but not able to get a single character on LCD...
here is the code i am using...what is the problem....

----------------------------------------------------------------------------------------------------------

Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include<reg51.h> // include header file
#define msec 50    // definition for delay
sbit rs=P3^0;   //Register select (RS)
sbit rw=P3^1;   //Read write (RW) pin
sbit en=P3^6;   //Enable (EN) pin
unsigned char commands[]={0x38,0x0E,0x01,0x06,'\0'};  //Command to be sent to LCD (initializing)
char name[]={"microcontroller 8051"};    //String to be displayed on LCD
 
void delay(unsigned int time)  //Time delay function
{
unsigned int i,j;
for(i=0;i<time;i++)
  for(j=0;j<1275;j++);
}
 
void lcdcmd(unsigned char value)  //Function for sending values to the command register of LCD
{
P2=value;
rs=0;
rw=0;
en=1;
delay(1);
en=0;
return;
}
 
void display(unsigned char value)  //Function for sending values to the data register of LCD
{
P2=value;
rs=1;
rw=0;
en=1;
delay(1);
en=0;
return;
}
 
void main()
{
int i,j;
for(i=0;commands[i]!='\0';i++)  //Sending string to LCD
{
  lcdcmd(commands[i]);
  delay(msec);
}
for(j=0;name[j]!='\0';j++)
{
  display(name[j]);
  delay(msec);
}
while(1)
{
  lcdcmd(0x18);  //Shift the entire display to right
  delay(75);
}
}


------------------------------------------------------------------------------------------
IMG_20140128_181127.jpgIMG_20140128_181152.jpgIMG_20140202_141829.jpgIMG_20140202_141905.jpg
 
Last edited by a moderator:

Hi Laxman you do first a basic thing
the data lines which you are using to sending that data or the pins/port connected to RS, EN & RW ,

First declare all them(PORTs) as OUTPUT in your main function ,

and instead of Printing a String at the first time try with the the displaying of only 1 character like 'A' using the function
Code:
display('A') ;   // as the function has prototype for the same

Then if that is perfect then go for Printing a String and further moving it to left or RIGHT ,
if there is still problem upload for the same !!
 

you have initialized the LCD, sending the data, but you haven't mentioned where to place the data
 

you have initialized the LCD, sending the data, but you haven't mentioned where to place the data

how to do that so????

- - - Updated - - -

Hi Laxman you do first a basic thing
the data lines which you are using to sending that data or the pins/port connected to RS, EN & RW ,

First declare all them(PORTs) as OUTPUT in your main function ,

and instead of Printing a String at the first time try with the the displaying of only 1 character like 'A' using the function
Code:
display('A') ;   // as the function has prototype for the same

Then if that is perfect then go for Printing a String and further moving it to left or RIGHT ,
if there is still problem upload for the same !!
how to set ports as output????
 

Hi.......You can make the ports as output by writing a "0" to them and also set the DDRAM address to of the lcd which is following for first and 2nd line respectively.....

First line=0x80 to 0x8F
2nd line=0xC0 to 0xCF
 

As Jamal said suppose you have assigned
PORT2 as data lines then declare PORT2 as Output

also Three PINS which are being used for RS , ENable, and RW make them also as OUTPUT,

in The main FUnction

first do like that

PORT2 = 0x00 ; //output
PORT1 = 0b11111000 ; //MAKING 1st , 2nd and 3rd pins of PORT 1 as Output

//You can use any PORT or Pins as per your Convenience OR as per Your CIRCUIT Diagram

then Only Apply the Function

LCD_init();

then first check for 1 data display

with display Function like diplay('M');

if it is working then make a function to print a string using POinters so that address increments
Code:
void LCD_string(unsigned char *mystring)
{
while(*mystring !=  '\0'  )
{
display(*mystring)  ;
mystring++ ; 
}
}

and use it like 
LCD_string("EMBEDDED WORLD");  //this will print the string

- - - Updated - - -

Hi .
as per your PCB I think PORT0 is assigned for Data , PORT2 1st three PINS are assigned for RS , RW and Enable

So declare
PHP:
PORT0 = 0x00 ; //as OUTPUT
PORT2 = 0b11111000 ;   // P2.0 , P2.1 & P2.1  as OUTPUT for RS , RW and EN
 

One thing more......give a delay of 20 ms before giving any command or check the busy flag..
 

Problem Solved: Problem in interfacing LCD

Thanks all of u for the help...
Problem solved..
i have added
p2=0x00;
p0=0x00;
and it worked..thank u all of for the reply..

- - - Updated - - -

Thanks all of u for the help...
Problem solved..
i have added
p2=0x00;
p0=0x00;
and it worked..thank u all of for the reply..


only one question
how to print character in 2nd line..as i am using 16x2 LCD...
 

hello,

how to print character in 2nd line..as i am using 16x2 LCD...

Code:
lcdcmd(0x80);  // 1rst line

 // to set cursor  at 2nd line  1rst caractere in X position
lcdcmd(0xC0);   
to set cursor at other X position, add X value to 0xC0 ...
lcdcmd(0xC8);  //  Y=2  x=8
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top