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.

Output is not correct at Port2 of AT89S52

Status
Not open for further replies.

munawar sharif

Newbie level 6
Joined
Nov 20, 2009
Messages
12
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
lahore,pakistan
Activity points
1,360
Hi,
I am using LDR,AT89S52,ADC0804 and the minimum analogue voltage at input of ADC0804 is not zero.If analouge input is in the range (1.8-4.8volt) then what will be the value of step size and Vref?LEDS connected to P2.
As i have to write a code such that
if input voltage is between (1.8-2.2) at output i want to make one led "ON".similarly
if input voltage is between (2.2-2.6),at output i want to make two leds "ON".
.
.
.
.
if input voltage is between (4.2-4.6),at output i want to make seven leds "ON".
if input voltage is greater than 4.6volt ,at output i want to make eight leds "ON".
Code is:

#include <reg51.h>
sbit RD1 = P3^4;
sbit WR1 = P3^5;
#define led P2
sbit INTR = P3^6;
sfr mydata = 0x90;
void main()
{
unsigned char val;
P2=0x00;
mydata = 0xFF;
INTR = 1;
RD1 = 1;
WR1 = 1;
while (1)
{
WR1 = 0;
WR1 = 1;
while(INTR==1);
RD1 = 0;
val = mydata;
if(val<0x5C)
{
led=0x00;
}
else if(val<0x70&&val>=0x5C)
{
led=0x01;
}
else if(val<0x85&&val>=0x70)
{
led=0x03;
}
else if(val<0x99&&val>=0x85)
{
led=0x07;

}
else if(val<0xAE&&val>=0x99)
{
led=0x0F;

}
else if(val<0xC2&&val>=0xAE)
{
led=0x1F;

}
else if(val<0xD7&&val>=0xC2)
{
led=0x3F;
}
else if(val<0xEB&&val>=0xD7)
{
led=0x7F;
}
else if(val>=0xEB)
{
led=0xFF;
}


RD1=1;
}
}


But i am not getting the correct output at P2.What may be the problem?

Please help me.Thanks in advance
 

But i am not getting the correct output at P2.What may be the problem?

Hi!

What do you mean that you are not getting the correct output at P2? What are you actually getting? Do you see anything? Is any LED open. Does the open LEDs change when you change the output? Please describe a little bit what you're seeing. Moreover, what's your LEDs connection? are they connected from the pin of the uC directly to ground, to power supply, what? Is it possible to post a simple schematic? At least the connection for one pin of P2 with the LED.

Nick
 


Thanks for the schematic! However, you haven't shown how you connect the LEDs at port P2 of AT89S52.

And explain please a little bit what exactly is you problem. You say that you don't get the correct output at P2. What do you actually get? Are some LEDs 'ON' but they are the wrong ones or you don't see any LED at all 'ON'? Because if you don't see any LED 'ON' at all, it may be a problem of your converter or perhaps you don't set the correct logic level at the pins of P2 for the LEDs to open.

Nick
 

positive terminal of each LED is connected to port2 i.e P2^0 . . . . . . P2^7 and other end directly connected to ground.If i connect leds at ADC pins (D0-D7) output is upto some extent correct,for example if i have analogue input nearly zero,digital output is not zero,actually all leds should remain off at this value but five of them are off and other three remain on,at P2 of uC all leds are on,no effect on leds,they remain on.there may be problem in converter because as it is not converting analogue values to digital correctly.
 

positive terminal of each LED is connected to port2 i.e P2^0 . . . . . . P2^7 and other end directly connected to ground.If i connect leds at ADC pins (D0-D7) output is upto some extent correct,for example if i have analogue input nearly zero,digital output is not zero,actually all leds should remain off at this value but five of them are off and other three remain on,at P2 of uC all leds are on,no effect on leds,they remain on.there may be problem in converter because as it is not converting analogue values to digital correctly.

Thanks for this info. Your'e actually correct with your code and the LEDs. If you want to light them on you have to set the respective pin of P2 to logic '1'. However, don't you think that you should better do the other way round? As far as I know the AT89S52 can source much more current than it can sink. So wouldn't it be better if you connected the anode of the LEDs to your Vcc and the cathode to the P2 port pins, with the addition of a series resistor to limit the max current that can pass through the pin?
You can check these links:

**broken link removed**
**broken link removed**

Anyway, this is not so necessary. So your code is correct from this aspect...

By the way, how fast do you run your code? What is the clock speed that you use for the processor? There may be a problem of timing violation. For example, the WR pulse should remain low for at least 100ns. Are you sure that you keep your pulse for that time low? The same when you read. After you pull RD low, there is a min time before you should read the digital outputs (the tACC time that is around 200ns) If you have a really fast clock these times cannot be assured without putting a delay in your code.

My next comment is the following: You say that if you put an analogue input nearly zero, then the digital output of the converter has five bits off and three on. This is not necessary wrong. How much was your analogue input? What you have seen may have been the error of the converter. Can you make a test with some other analogue voltage? For example put 1V and see what you get at the ADC output pins.
 
Last edited:
Hi,
I had solved my problem,i just changed ADC which was not working properly and displayed output on PC using serial communication,it's working properly now.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top