部分源程序如下://=================测速计数处理===================================voidtimer1()interrupt3{time1++;}//+++++++++++++++++测速转换处理+++++++++++++++++++++++voidint1()interrupt2{longkA=0;uchartemp;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处理与数据采集处理函数===================voidPWM_generator()interrupt1using0{if(flag==1){a--;if(a==0){flag=0;if(K_B_bit==1)a=UK;elsea=SP_in;}else{OUT_PWM=0;}}if(flag==0){b--;if(b==0){flag=1;if(K_B_bit==1)b=0xff-UK;elseb=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