部分源程序如下:
//=================测速计数处理===================================
void timer1()interrupt 3
{time1++;}
//+++++++++++++++++测速转换处理+++++++++++++++++++++++
void int1()interrupt 2
{ long kA=0;
uchar temp;
TR1=0;
if(SP_bit==0)
{TR1=1;SP_bit=1;}
else
{ kA=time1*65536+TH1*256+TL1;
temp=2500000/kA;
SP_out=temp;
TH1=0x00;
TL1=0x00;
time1=0x00;
TR1=0;
SP_bit=0;
}
}
//================PWM处理与数据采集处理函数===================
void PWM_generator() interrupt 1 using 0
{ if(flag==1)
{ a--;
if(a==0)
{flag=0;
if(K_B_bit==1) a=UK;
else a=SP_in;
}
else
{OUT_PWM=0;}
}
if(flag==0)
{ b--;
if(b==0)
{flag=1;
if(K_B_bit==1) b=0xff-UK;
else b=0xff-SP_in;
}
else
{OUT_PWM=1;}
}
m++;
if(m==20)
{ m=0;
n++;
if(n==40)
{ n=0;
EK0=SP_in-SP_out;
PI_bit=1;
}
}
}
1