我是新手,请指教。用来控制速度的。用距离除以两次外部中断间隔时间得出速度。请问中断函数是这样用么?中断函数编译出错
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <p24fj128ga010.h>
#define Designed_V 10*1609344
#define Circumference 2156
#define CLK_TCK 1000
int main(void)
{
int regeneration_model=0;
long i;
int start_time,end_time;
int measured_v=0;
INTCON1bits.NSTDIS=1;
INTCON2bits.INT1EP=0;
IFS1bits.INT1IF=0;
IEC1bits.INT1IE=1;
PORTFbits.RF3=0;
PORTDbits.RD1=1;
PORTBbits.RB13=1;
end_time=clock();
while(1)
{
if(measured_v<=Designed_V)
{
if(regeneration_model==1)
{
PORTDbits.RD1=0;
for(i=1;i<100000;i++);
PORTDbits.RD1=1;
regeneration_model=0;
}
PORTFbits.RF3=1;
}
else
{
PORTFbits.RF3=0;
if(regeneration_model==0)
{
PORTBbits.RB13=0;
for(i=1;i<100000;i++);
PORTBbits.RB13=1;
regeneration_model=1;
}
}
}
}
void _int1 (void) interrupt 1
{
start_time=end_time;
end_time=clock();
measured_v=Circumference/4/(end_time-start_time)*CLK_TCK;
}
错误
my_speed.c: In function 'main':
my_speed.c:29: warning: comparison is always true due to limited range of data type
my_speed.c:17: warning: unused variable 'start_time'
my_speed.c: At top level:
my_speed.c:55: error: syntax error before 'interrupt'
my_speed.c:58: warning: type defaults to 'int' in declaration of 'end_time'
my_speed.c:58: error: initializer element is not constant
my_speed.c:58: warning: data definition has no type or storage class
my_speed.c:59: warning: type defaults to 'int' in declaration of 'measured_v'
my_speed.c:59: error: 'start_time' undeclared here (not in a function)
my_speed.c:59: warning: data definition has no type or storage class
my_speed.c:60: error: syntax error before '}' token |