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
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