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.

why this code doesn't work

Status
Not open for further replies.

hassan ali

Member level 2
Joined
May 18, 2010
Messages
47
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Location
egypt
Activity points
1,667
#include<reg52.h>
sbit en=P3^0;
sbit rs=P3^1;
sbit rw=P3^2;
#define lcd P2
void delay(unsigned int );
void lcddata(unsigned char );
void lcdcmd(void);
void convert(unsigned char);
unsigned char mybyte;
void main(void)
{
void lcdcmd();
T0=1;
TMOD=0x06; //counter 1 mode 2
TH0=0;


while(1)
{
do
{
TR0=1;
mybyte=TL0;
convert(mybyte);
}
while(TF0==0);
TR0=0;
TF0=0;
}
}


void delay(unsigned int m)
{
unsigned int r,t;
for (r=0;r<m;r++)
for (t=0;t<50;t++);
return;
}

void lcdcmd()
{
lcd=0x38;
rs=0;
rw=0;
en=1;
delay(1);
en=0;

lcd=0x83;
rs=0;
rw=0;
en=1;
delay(1);
en=0;

lcd=0x0e;
rs=0;
rw=0;
en=1;
delay(1);
en=0;
return;
}

void lcddata(unsigned char g)
{
lcd=g;
rs=1;
rw=0;
en=1;
delay(1);
en=0;
return;
}

void convert(unsigned char mybyte)
{
unsigned char x,d1,d2,d3,g;
x=mybyte / 10;
d1=mybyte % 10;
d2=x % 10;
d3=x / 10;
g=30 | d1;
lcddata(g);
g=30 | d2;
lcddata(g);
g=30 | d3;
lcddata(g);
return;
}
 

Re: why this code desn't work

i mean that this program must take the counter value and display it on LCD but it's display any thing , so can u help me to find the problem in this code.
 

Re: why this code desn't work

where is the crystal oscillator in your circuit... add a crystal to pin 18 and 19 with 33pf capacitors to each terminal, and other end to ground....

---------- Post added at 16:45 ---------- Previous post was at 16:43 ----------

try to vary the pot connected to LCD to see any text is coming or not...
 

Re: why this code desn't work

i try it but it still not work i guess that the problem in the initialization of LCD , may be the routine"LCDCMD" isn't in the right position.
 

Re: why this code desn't work

Hi, I had a look at the code:
1. Have a look at the min freq for the Enable. I do know that the lcd segment display is slow.
2. Connect a scope and monitor the lines.
3. Make sure that the init routine is correct. There is sample code availible on the net.

MN
 

Re: why this code desn't work

Try to find that LCD driver files on the net, it is very common as i know.
It is HD44780 compatible LCD.
Fisrt try like that, any only make a short code to pirnt something on LCD.
Then try to write your own functions.
 

Maybe the problem is related to timing.
In your code you placed a delay(1) while en is high and no delay while it is low.
Actually the display needs at least 2 milisec while it is low. To admit data the active high pulse of en may be very short.
 

now after takes ur advices the cursor is only moving on lcd and there is nothing displayed, so any one can please check out the subroutine "CONVERT" which is used to get the ASCII code for the number to display it on LCD.
 

There is a problem in function convert:
The conversion from BCD to asc
g = 30 | d1;
Shuld be
g = 0x30 | d1;
The value 0x30 is the ASCII code of the character '0' (zero) [May be written as '0' but not as 30]
 
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top