Problem with Interfacing 16x2 lcd to AT89S52 microcontroller

Status
Not open for further replies.

santosh.s

Newbie level 1
Joined
Jul 5, 2013
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
13
Hello

I am interfacing lcd (JHD 162A) using 8051(AT89c52).The lcd's lamp only lit up and all i can see is boxes in the first line,i have checked all the connections to the lcd and they are fine.I wrote the code on keil uvision4 .I tried with different c codes to check lcd but still i see the same problem ,please help .Thanks in Advance.
Here is the code :

#include<AT89X51.h>
sfr ldata=0x90;
sbit rs=P3^3;
sbit rw=P3^4;
sbit en=P3^5;
void lcd_command(unsigned char);
void lcd_data(unsigned char);
void delay(unsigned int);
void main()
{
P2=0x00;
P1=0xFF;
delay(100);
lcd_command(0x38);
delay(100);
lcd_command(0x0F);
delay(100);
lcd_command(0x01);
delay(100);
lcd_command(0x06);
delay(100);
lcd_command(0x80);
delay(100);
lcd_data('H');
delay(100);
lcd_data('I');
while(1);
}
void lcd_command(unsigned char value)
{
ldata=value;
rs=0;
rw=0;
en=1;
delay(100);
en=0;
}
void lcd_data(unsigned char value)
{
ldata=value;
rs=1;
rw=0;
en=1;
delay(150);
en=0;
}
void delay(unsigned int num)
{
unsigned int k,q;
for(k=0;k<num;k++)
{
for(q=0;q<=1275;q++);
}
}
 

Hi There,

Please try this code and revert back me.

//Program to test LCD. Display single character "A"

#include<reg51.h>
#define cmdport P3
#define dataport P2
#define q 100
sbit rs = cmdport^0; //register select pin
sbit rw = cmdport^1; // read write pin
sbit e = cmdport^6; //enable pin

void delay(unsigned int msec) // Function to provide time delay in msec.
{
int i,j ;
for(i=0;i<msec;i++)
for(j=0;j<1275;j++);
}

void lcdcmd(unsigned char item) //Function to send command to LCD
{
dataport = item;
rs= 0;
rw=0;
e=1;
delay(1);
e=0;
}

void lcddata(unsigned char item) //Function to send data to LCD
{
dataport = item;
rs= 1;
rw=0;
e=1;
delay(1);
e=0;
}

void main()
{
lcdcmd(0x38); // for using 8-bit 2 row mode of LCD
delay(100);
lcdcmd(0x0E); // turn display ON for cursor blinking
delay(100);
lcdcmd(0x01); //clear screen
delay(100);
lcdcmd(0x06); //display ON
delay(100);
lcdcmd(0x86); // bring cursor to position 6 of line 1
delay(100);
lcddata('A');
}

Best regards,
 

Attachments

  • How to interface 16x2 LCD with AT89C51.gif
    45.6 KB · Views: 92
Last edited:

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…