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 with interfacing LCD with at89s52

Status
Not open for further replies.

Kishor Pyakurel

Newbie level 1
Newbie level 1
Joined
Aug 25, 2013
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Visit site
Activity points
28
Hello

I am interfacing lcd (16x2) using 8051(AT89s52).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.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<reg51.h>
#define port P3
#define adc_input P1
#define dataport P2
#define sec 100
sbit rs = port^0;
sbit rw = port^1;
sbit e = port^2;

sbit wr= port^3;
sbit rd= port^4;
sbit intr= port^5;

sbit fan=port^6;
sbit heater=port^7;

int test_intermediate3=0, test_final=0,test_intermediate1[10],test_intermediate2[3]={0,0,0};

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

void lcd_cmd(unsigned char item)
{
dataport = item;
rs= 0;
rw=0;
e=1;
delay(1);
e=0;
return;
}

void lcd_data(unsigned char item)
{
dataport = item;
rs= 1;
rw=0;
e=1;
delay(1);
e=0;
return;
}

void lcd_data_string(unsigned char *str)
{
int i=0;
while(str!='\0')
{
lcd_data(str);
i++;
delay(10);
}
return;
}

void shape()
{
lcd_cmd(64);
lcd_data(2);
lcd_data(5);
lcd_data(2);
lcd_data(0);
lcd_data(0);
lcd_data(0);
lcd_data(0);
lcd_data(0);
}

void convert()
{
int s;
lcd_cmd(0x81);
delay(50);
lcd_data_string("TEMP:");
test_final=(((9*test_intermediate3)/5)+32);
s=test_final/100;
test_final=test_final%100;
lcd_cmd(0x88);
if(s!=0)
lcd_data(s+48);
else
lcd_cmd(0x06);
s=test_final/10;
test_final=test_final%10;
lcd_data(s+48);
lcd_data(test_final+48);
lcd_data(0);
lcd_data('F');
lcd_data(' ');

test_final=test_intermediate3;
lcd_cmd(0xc1);
delay(2);
lcd_data_string("TEMP:");
s=test_final/100;
test_final=test_final%100;
lcd_cmd(0xc8);
if(s!=0)
lcd_data(s+48);
else
lcd_cmd(0x06);
s=test_final/10;
test_final=test_final%10;
lcd_data(s+48);
lcd_data(test_final+48);
lcd_data(0);
lcd_data('c');
lcd_data(' ');
delay(2);
}

void main()
{
int i,j;
adc_input=0xff;
lcd_cmd(0x38);
lcd_cmd(0x0c);
delay(2);
lcd_cmd(0x01);
delay(50);

while(1)
{
for(j=0;j<3;j++)
{
for(i=0;i<10;i++)
{
delay(1);
rd=1;
wr=0;
delay(1);
wr=1;
while(intr==1);
rd=0;
lcd_cmd(0x88);
test_intermediate1=adc_input/10;
delay(50);
intr=1;
}
for(i=0;i<10;i++)
test_intermediate2[j]=test_intermediate1+test_intermediate2[j];
}

test_intermediate2[0]=test_intermediate2[0]/3;
test_intermediate2[1]=test_intermediate2[1]/3;
test_intermediate2[2]=test_intermediate2[2]/3;
test_intermediate3=test_intermediate2[0]+test_intermediate2[1]+test_intermediate2[2];
shape();
if(test_intermediate3>=25)
{
fan=1;
}
else if(test_intermediate3<=10)
{
heater=1;
}
else
{
fan=0;
heater=0;
}

convert();

}
}
 

Do you see black squares in your screen??
If that is the case, might be possible that your code is working fine. All you need to do is, do some contrast adjustment. 3rd pin of the LCD module i.e. VEE is used for that. Connect a potentiometer with its terminals tied to VCC and ground and connect the variable end to your VEE pin. Adjust the potentiometer until you get a clear character on your screen.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top