I just need pulses, 5volts = 1 and 0volts = 0 from sensors so I don't need ADC. So, how do I interface my IR with 8051(AT89S51)?
Here is the image how you should interface IR with MCU, to get 5V & 0V as o/p.
void takinginput()
{
unsigned int is2=0;
int n=0;
P1=0xFF;
for(n=0;n<=20;n++)
{
Timedelay(); // this function is not placed properly... it will add 50 ms delay every time !!!!
if(IR!=0); // if IR on port 1.0 goes 1 i.e. detects 5 volts
{
is2++;
for(;IR == 1; // wait for getting P1.0 to low.
}
}
is1=is2;
}
[/I]
50ms, 20 times gives me 1 second delay but have I not used it properly?
I don't understand why you've added; for(;IR == 1; // wait for getting P1.0 to low.?
void Timedelay() interrupt 1 // time delay for 1 second
{
n++; // define n as char globally
if(n==20) // only satisfies after1 sec.
{
ET0 = 0; // stop timer interrupt immediately when 1 sec completes.
// now check the value of is2 (i.e. is1 = is2 should place here)
//RPMcalculation(zis) GOES INTO ANOTHER FUNCTION WHERE RPM IS CALCULATED and FROM THERE TO LCD display
// after displaying now again we need to start 1sec timer so....
TL0=0xFD;
TH0=0x4B;
ET0 = 1; // start timer interrupt agian
TR0=1; // start timer.
}
}
void takinginput()
{
unsigned int is2=0;
P1=0xFF;
TR0=1; // start timer
while(1) // infinite loop
{
if(IR!=0); // if IR on port 1.0 goes 1 i.e. detects 5 volts
{
is2++;
while(IR == 1); // wait for getting P1.0 to low.
}
}
void main()
{
TMOD=0x01;
TL0=0xFD;
TH0=0x4B;
EA=1; // enable interrupts
ET0=1; // enable timer 0 interrupts
takinginput();
}
I think that measuring the period will give you more precision than counting the 3 blades during 1 sec.
whenever you get your problem solved do share your solution/mistakes here so that other can have your reference.
Here is what you need for more than 1 sensor & to detect them through LED.
but the resistor values will be the same which we've discussed.
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?