Discussion in "Project Help" started by    bnbnqwe    Apr 19, 2012.
Thu Apr 19 2012, 10:56 am
#1
I am doing a project : digital room thermometer. So , I have to interface LCD with 8051 microcontroller at89s52. But whenever I power up the microcontroller , LCD is lit but only black boxes are showing. I have tried many different codes and many things, but display is same . onle black boxes. But i have simulated this circuit in proteus . here, that LCD is giving correct output. Plz help in determining the problem. Here are the attached code and circuit diagram. Here is the C Code....







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

#include<reg51.h>
#define cmdport P3
#define dataport P2
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 lcd_ini() //Function to inisialize the LCD
{
lcdcmd(0x38);
delay(50);
lcdcmd(0x0E);
delay(50);
lcdcmd(0x80);
delay(50);

}
void main()
{
lcd_ini();
lcddata('A');
}












[ Edited Fri May 18 2012, 10:11 pm ]
 Reshal like this.
Fri Apr 20 2012, 12:35 am
#2
you might need to give a little more delay maybe... and give some power on delay before sending any command.
also change your init sequence to 0x38, 0x0E, 0x01, 0x06 then 0x80

Please take a look at tutorial section for LCD initialization info...
http://www.8051projects.net/lcd-interfacing/initialization.php
Fri Apr 20 2012, 01:02 am
#3
now i have made the following modified code .


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

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


void busy()
{
lcd_D7 = 1;
e = 1; //Make port pin as o/p
rs = 0; //Selected command register
rw = 1; //We are reading
while(lcd_D7){ //read busy flag again and again till it becomes 0
e = 0; //Enable H->L
e = 1;
}
}

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;
busy();
}

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

void lcd_ini() //Function to inisialize the LCD
{
lcdcmd(0x38);
lcdcmd(0x0E);
lcdcmd(0x01);
lcdcmd(0x06);
lcdcmd(0x80);


}
void main()
{
delay(250);
lcd_ini();
lcddata('A');
}








but in keil, it is giving error ..\Desktop\C program files\lcdinterfac_2.c(14): error C141: syntax error near '='

i.e at the lcd_D7=1 line.
Fri Apr 20 2012, 01:26 am
#4
change the following..
#define lcd_D7 P2^7
//change it to
sbit lcd_D7 = P2^7;
Fri Apr 20 2012, 01:32 am
#5
Thanx. Now the c code is compiled successfully. But I cant run this program in Proteus simulator . It dows not give any output. I can not find pin 6 of that LCD module. So i have to change circuit a bit. Plz modify it if necessary.

Here is the attached proteus schematic.


Attachment
Fri Apr 20 2012, 01:41 am
#6
you're using wrong LCD... Please use LM032L and try again.
 bnbnqwe like this.
Fri Apr 20 2012, 01:48 am
#7
but in our project, we have to use 16 pin LCD which is jh162a. So 14 pin lcd or 16 pin lcd simulation will be same for proteus??
Fri Apr 20 2012, 01:52 am
#8
so use LM016L anyways.. both 20x2 and 16x2 shares the same LCD controller same code will work for both LCDs. see LCD tutorial for more information on these LCDs.
Fri Apr 20 2012, 02:03 am
#9
Thanx . . I have used lm032l and this time result is positive. though a small error much like warning is displayed in proteus. I am attaching modified files with code .


[ Edited Fri Apr 20 2012, 02:04 am ]
Fri Apr 20 2012, 02:06 am
#10
attached schematic

Get Social

Information

Powered by e107 Forum System

Downloads

Comments

Lewisuhakeply
Thu Apr 18 2024, 06:00 pm
Darrellciz
Thu Apr 18 2024, 11:07 am
Charlessber
Thu Apr 18 2024, 09:29 am
BartonSem
Thu Apr 18 2024, 04:56 am
DonaldKnown
Thu Apr 18 2024, 12:24 am
utaletxcyw
Wed Apr 17 2024, 10:21 am
Anthonyvab
Wed Apr 17 2024, 08:48 am
RobertCix
Wed Apr 17 2024, 06:46 am