vacant34
Newbie level 3
- Joined
- Nov 25, 2012
- Messages
- 4
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,281
- Activity points
- 1,316
hi all iv been working on anemometer using a lpc936. my anemometer sends two pulses to the controller for every rotation.
im trying to use the external interrupt to count the amount of pulses in a second and use that variable to calculate the wind-speed
i would like someone to point out where im going wrong with the interrupt of if there a better method to calculate the wind-speed
thank you.
#include <REG936.H>
void delay(unsigned char no_loops);
//Level trigger external interrupt
sbit led =P2^0;
sbit IR = P1^3;
int count=0;
int speed=0;
void main()
{
EA=1;
//IE = 0x81;
IT0=1;
EX0=1;
led=1;
//count=0;
while(1);
//speed=speed/2;
}
void ISR_ex0(void) interrupt 0
{
int n;
//delay(50);
for(n=0;n<=9;n++)
{
if(IR==1); // if IR on port 1.3 goes 1 i.e. detects 5 volts
{
count++;
for(;IR ==1; // wait for getting P1.3 to go low.
delay(50);
}
}
count=0;
}
//function to generate a delay of x * 50msec
void delay(unsigned char no_loops)
{
unsigned char x;
TR0 = 0;
TF0 = 0;
TMOD = 0x01;
TH0 = 0x87;
TL0 = 0xFF;
TR0 = 1;
for(x=0;x<no_loops;x++)
{
while(!TF0);
TF0 = 0;
TH0 = 0x87;
TL0 = 0xFF;
}
TR0 = 0;
}
im trying to use the external interrupt to count the amount of pulses in a second and use that variable to calculate the wind-speed
i would like someone to point out where im going wrong with the interrupt of if there a better method to calculate the wind-speed
thank you.
#include <REG936.H>
void delay(unsigned char no_loops);
//Level trigger external interrupt
sbit led =P2^0;
sbit IR = P1^3;
int count=0;
int speed=0;
void main()
{
EA=1;
//IE = 0x81;
IT0=1;
EX0=1;
led=1;
//count=0;
while(1);
//speed=speed/2;
}
void ISR_ex0(void) interrupt 0
{
int n;
//delay(50);
for(n=0;n<=9;n++)
{
if(IR==1); // if IR on port 1.3 goes 1 i.e. detects 5 volts
{
count++;
for(;IR ==1; // wait for getting P1.3 to go low.
delay(50);
}
}
count=0;
}
//function to generate a delay of x * 50msec
void delay(unsigned char no_loops)
{
unsigned char x;
TR0 = 0;
TF0 = 0;
TMOD = 0x01;
TH0 = 0x87;
TL0 = 0xFF;
TR0 = 1;
for(x=0;x<no_loops;x++)
{
while(!TF0);
TF0 = 0;
TH0 = 0x87;
TL0 = 0xFF;
}
TR0 = 0;
}