注册会员
- 积分
- 184
- 威望
- 134
- 贡献
- 34
- 兑换币
- 0
- 注册时间
- 2012-4-14
- 在线时间
- 8 小时
|
#include <hidef.h> /* common defines and macros */
#include "derivative.h" /* derivative-specific definitions */
#include "CAP.h"
#define k 4
unsigned int dt0,dt1;
unsigned int time01,time11;
unsigned int time02,time12;
int T0,T1;
int v0,v1;
void main(void) {
/* put your own code here */
P0_4ms_Init();
P1_4ms_Init();
CAPInit();
EnableInterrupts;
for(;;) {
//k=(2*3*radius)/chishu;
T0=8*dt0/1000;
T1=8*dt1/1000;
v0=(k/T0)*10; // unit:m/s
_FEED_COP(); /* feeds the dog */
} /* loop forever */
/* please make sure that you never leave main */
}
#pragma CODE_SEG __NEAR_SEG NON_BANKED
void interrupt 8 capture0_ISR()
{
TFLG1_C0F = 1;
time01 = time02; //记录上一时刻的捕捉值
time02 = TC0; //读取这一次的捕捉值
dt0= time02-time01; //计算时间差
}
#pragma CODE_SEG __NEAR_SEG NON_BANKED
void interrupt 9 capture1_ISR()
{
TFLG1_C1F = 1;
time11 = time12; //记录上一时刻的捕捉值
time12 = TC1; //读取这一次的捕捉值
dt1= time12-time11; //计算时间差
}
|
|