/*pca测速中断服务子程序*/
void pca_isp() interrupt 6 using 1//interrupt sevice routine
{
static bit flag_pca3=0;
static bit flag_pca4=0;
static unsigned long idata temp1_pca3=0x00;
static unsigned long idata temp2_pca3=0x00;
static unsigned long idata temp1_pca4=0x00;
static unsigned long idata temp2_pca4=0x00;
static uint idata count_pca3=0x00;
static uint idata count_pca4=0x00;
if(CCF3)
{
CCF3=0;
if(flag_pca3==0)
{
temp1_pca3=CCAP3L|(CCAP3H<<8)|(count_pca3<<16);
flag_pca3=1;
}
else
{
temp2_pca3=CCAP3L|(CCAP3H<<8)|(count_pca3<<16);
right_speed[3]=right_speed[2];
right_speed[2]=right_speed[1];
right_speed[1]=right_speed[0];
if((temp2_pca3-temp1_pca3)<65535)
right_speed[0]=(uint)(sensitive/((temp2_pca3-temp1_pca3)/1000.0)); //单位为(mm/s)
else
right_speed[0]=0; //速度过低标志
flag_pca3=0;
}
}
if(CCF4)
{
CCF4=0;
if(flag_pca4==0)
{
temp1_pca4=CCAP4L|(CCAP4H<<8)|(count_pca4<<16);
flag_pca4=1;
}
else
{
temp2_pca4=CCAP4L|(CCAP4H<<8)|(count_pca4<<16);
left_speed[3]=left_speed[2];
left_speed[2]=left_speed[1];
left_speed[1]=left_speed[0];
if((temp2_pca4-temp1_pca4)<65535)
left_speed[0]=(uint)(sensitive/((temp2_pca4-temp1_pca4)/1000.0)); //单位为(mm/s)
else
left_speed[0]=0; //速度过低标志
flag_pca4=0;
}
}
if(CF)
{
count_pca3++;
count_pca4++;
if(!count_pca3)
flag_pca3=0;
if(!count_pca4)
flag_pca4=0;
}
CF=0;
}
pca_init()
{
EC=1;//允许pca中断
EA=1;
CMOD=0X01;//12us计数,使能ccon中的cf位来生成中断
CH=0X00;//计数器清零
CL=0X00;
CCAPM3=0X21;//p1.6上跳沿捕捉,并允许ccf0中断
CCAPM4=0X21;
CR=1;//计数开始
}