hashim5003

Joined Apr 29, 2013
32
I was using adc0831 and lm35 with at89s52. Now I am using adc0804 instead. I have written the code, it simulates on proteus but not running on the hardware. I am posting the code I have written. Plz mention if there is any problem.
Problem:
when I use while (intr == 1) lcd only shows black boxes. and without this statement all it shows "temp:000"

Rich (BB code):
#include<reg52.h>

#define lcd_data P1

void delay (int);
void lcdcmd (char);
void lcddata (char);
void lcd_init(void);

sbit r = P3^1;
sbit w = P3^2;
sbit rs = P3^7;
sbit rw = P3^6;
sbit e = P3^5;
sbit intr = P3^3;

void main()
{
signed char x, a, b, c;
while (1)
{
r = 1;
w = 0;
delay (1);
w = 1;
while (intr == 1);
r = 0;

lcd_init();

lcddata ('t');
lcddata ('e');
lcddata ('m');
lcddata ('p');
lcddata (':');

a = x / 10;
b = x % 10;

lcddata ( a + 0x30 );
lcddata ( b + 0x30 );
lcddata ( c + 0x30 );
}
}

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

void lcdcmd (char value)
{
rs=0;
lcd_data = value;
rw=0;
e=1;
delay (1);
e=0;

}

void lcd_init(void)
{
lcdcmd(0x38);
lcdcmd(0x0c);
lcdcmd(0x06);
lcdcmd(0x80);
}

void lcddata (char value)
{
rs=1;
lcd_data = value;
rw=0;
e=1;
delay (1);
e=0;

}

AfdhalAtiffTan

Joined Nov 20, 2010
120
I'm not really familiar with 8051;
But, have you set the INTR pin as input?

Try remove the while (intr == 1);
and see if the lcd displays anything. If it does, then your adc might not accessed correctly.

If no, there's might be a hardware issue.

This is what I've used before for adc,

NOP ;Access time delay
RET

To my rough observation, it looks quite familiar to yours.
Have you checked if the ADC get its clock?

Last edited:

hashim5003

Joined Apr 29, 2013
32
when i remove while (intr == 1).
it works but only shows "temp: 000" (000 is supposed to be temperature)
no change in value happens.

hashim5003

Joined Apr 29, 2013
32
Have you checked if the ADC get its clock?
yep. by using internal clock with 150pF capacitor and 10k resistor.

AfdhalAtiffTan

Joined Nov 20, 2010
120
If you already built the hardware, with the while(intr==1) still intact,
could you just manipulate the mcu-pin directly?

i.e. with the adc-chip disconnected, take a wire which is connected to p3.3,
drive it to either vcc or ground, and observe what the lcd displays.

If there's any sign of activity towards the pin input change, your adc might not wired correctly.

Better yet, just hook an oscilloscope to the pin, and monitor for signal issued by the adc, especially the clock and intr pin.

ErnieM

Joined Apr 24, 2011
8,019
when i remove while (intr == 1).
it works but only shows "temp: 000" (000 is supposed to be temperature)
no change in value happens.
The "000" is consistence with not getting any A2C data, or always reading zero. I don't see any code to initialize the device you use to do that conversion.

(And while I'm at it, while I see your LCD initialization, it lacks delays and doesn't get called anyway.)

hashim5003

Joined Apr 29, 2013
32
The "000" is consistence with not getting any A2C data, or always reading zero. I don't see any code to initialize the device you use to do that conversion.

(And while I'm at it, while I see your LCD initialization, it lacks delays and doesn't get called anyway.)
yep, It's not getting data from adc. I have initialized the adc according to it's datasheet.
I think it's not getting clk pulses by using internal clock pulse. Could that be the problem?

hashim5003

Joined Apr 29, 2013
32
If you already built the hardware, with the while(intr==1) still intact,
could you just manipulate the mcu-pin directly?

i.e. with the adc-chip disconnected, take a wire which is connected to p3.3,
drive it to either vcc or ground, and observe what the lcd displays.

If there's any sign of activity towards the pin input change, your adc might not wired correctly.

Better yet, just hook an oscilloscope to the pin, and monitor for signal issued by the adc, especially the clock and intr pin.
Today I have used adc without using microcontroller giving pulses from switched. It didn't worked either. I am guessing that it could be the internal clock pulse that is not converting.

AfdhalAtiffTan

Joined Nov 20, 2010
120
Today I have used adc without using microcontroller giving pulses from switched. It didn't worked either. I am guessing that it could be the internal clock pulse that is not converting.
Have you tried to operate it in free-running mode?
With LEDs as the output, and a potentiometer as input,
just curious to know if the ADC still alive.

hashim5003

Joined Apr 29, 2013
32
Have you tried to operate it in free-running mode?
With LEDs as the output, and a potentiometer as input,
just curious to know if the ADC still alive.
how do i run in free running mode?

AfdhalAtiffTan

Joined Nov 20, 2010
120
Datasheet will give some clues.

Download the datasheet from the site, and scroll to page 11, Fig. 17, 'free running connection'.

Just wire everything as shown in the diagram, and you're good to go.

Don't forget to include Vref/2 on the ADC.
For your 8051 case, just connect it to resistive voltage divider; by half, i.e. 2.5V.
The start switch is a momentary contact, once it closed and re-open, the ADC will run by itself.

The absence of suitable Vref would render the reading useless.

Assign all of the output to drives LEDs.
If the LEDs readout changes as the analog input varies, then you're good to proceed with the mcu.

Last edited:

hashim5003

Joined Apr 29, 2013
32
Problem has been solved. It was clock pulse that wdc was not getting.
Now I am interfacing lcd but it's showing weird characters.

AfdhalAtiffTan

Joined Nov 20, 2010
120

How weird the character is?
Do the "temp:" properly displayed?

hashim5003

Joined Apr 29, 2013
32

How weird the character is?
Do the "temp:" properly displayed?
Like when i write 'TEMP' in program. on display it shows temP, TGmP, toMp or sometime spaces between characters, and sometimes it misses the character also.

could it be the problem in the lcd?

AfdhalAtiffTan

Joined Nov 20, 2010
120
There's might be a problem with your LCD routine.
Since you're not checking busy-flag, you could try to increase the delay.

hashim5003

Joined Apr 29, 2013
32
Here is my code now.
Problem is still there.
How these lcds get clock pulse? Do they have internal clocl source?
Here is my code now:
Rich (BB code):
#include<reg52.h>

sbit en = P3^5;
sbit rw = P3^6;
sbit rs = P3^7;
sbit busy = P1^7;

void delay()
{
TMOD = 0x01;
TH0 = 0x00;
TL0 = 0x00;
TR0 = 1;
while(TF0 == 0);
TR0 = 0;
TF0 = 0;
}

void lcdbusy()
{
rs = 0;
rw = 1;
while(busy == 1)
{
en = 0;
delay();
en = 1;
}
}

void lcdcmd(char y)
{

P1 = y;
rs = 0;
rw = 0;
en = 1;
delay();
en = 0;
lcdbusy();
}
void lcddata(char z)
{

P1 = z;
rs = 1;
rw = 0;
en = 1;
delay();
en = 0;
lcdbusy();

}

void main()
{
delay();
lcdcmd(0x30);
delay();
lcdcmd(0x30);
delay();
lcdcmd(0x30);
delay();
lcdcmd(0x38);
delay();
lcdcmd(0x0E);
delay();
lcdcmd(0x01);
delay();
lcdcmd(0x06);
lcddata('T');
lcddata('E');
lcddata('M');
lcddata('P');
while(1);
}

shteii01

Joined Feb 19, 2010
4,647
Here is my code now.
Problem is still there.
How these lcds get clock pulse? Do they have internal clocl source?
Here is my code now:
Rich (BB code):
#include<reg52.h>

sbit en = P3^5;
sbit rw = P3^6;
sbit rs = P3^7;
sbit busy = P1^7;

void delay()
{
TMOD = 0x01;
TH0 = 0x00;
TL0 = 0x00;
TR0 = 1;
while(TF0 == 0);
TR0 = 0;
TF0 = 0;
}

void lcdbusy()
{
rs = 0;
rw = 1;
while(busy == 1)
{
en = 0;
delay();
en = 1;
}
}

void lcdcmd(char y)
{

P1 = y;
rs = 0;
rw = 0;
en = 1;
delay();
en = 0;
lcdbusy();
}
void lcddata(char z)
{

P1 = z;
rs = 1;
rw = 0;
en = 1;
delay();
en = 0;
lcdbusy();

}

void main()
{
delay();
lcdcmd(0x30);
delay();
lcdcmd(0x30);
delay();
lcdcmd(0x30);
delay();
lcdcmd(0x38);
delay();
lcdcmd(0x0E);
delay();
lcdcmd(0x01);
delay();
lcdcmd(0x06);
lcddata('T');
lcddata('E');
lcddata('M');
lcddata('P');
while(1);
}
You strobe the enable pin (en).
en=1;
short delay;
en=0;

Anyway, I see a couple of problems in the code.

hashim5003

Joined Apr 29, 2013
32
You strobe the enable pin (en).
en=1;
short delay;
en=0;

Anyway, I see a couple of problems in the code.
I have used delay between enable pin. you mean to say that I have to use short delay?
Can you plz mention these mistakes? It would be really helpful.

shteii01

Joined Feb 19, 2010
4,647
I have used delay between enable pin. you mean to say that I have to use short delay?
Can you plz mention these mistakes? It would be really helpful.
In your lcdcmd and lcddata P1 is not defined.
You say P1=y and P1=z. But what is P1?

I know that you know what P1 is. But the chip/computer does not know and, what is worse, does not care.

shteii01

Joined Feb 19, 2010
4,647
Also.
lcdcmd and lcddata needs return; in the end to return to main.