串口接收中断程序 发生一次后程序就死了,在线调试时其是这样的,通过串口发送数据 ,然后串口进入串口中断函数,执行完中断后返回主循环函数 然后程序就死了
主函数的循环程序
while (1)
{
if(flag0==1) //判断是否时间到
{
caiji(); //4.4秒调用一次 T=4.4 s
printf(" 输入电压=%dmV \r\n", SetPoint);
printf("实际电压= %6.2fmV \r\n", wd_dianya);
flag0=0; //开始采集标志清零
flag2=1;//为加热时间更新标志
}
}
float caiji( u8 P_pid,u8 I_pid,u8 D_pid)
{
u8 w; float sum_data=0;
 =(float)(P_pid);
I=(float)(I_pid);
D=(float)(D_pid);
while(w!=64)
{
// ADC_ResetCalibration(ADC1);
// while(ADC_GetResetCalibrationStatus(ADC1));
// ADC_StartCalibration(ADC1);
// while(ADC_GetCalibrationStatus(ADC1)); //等待校准
// ADC_SoftwareStartConvCmd(ADC1, ENABLE); //启动ADC转换 软件启动功能
// delay_us(3); //使AD连续转换
if(ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC)==SET)
{
w++;
AD_value=ADC_GetConversionValue(ADC1);
AD_valu =AD_value;
sum_data+=AD_valu;
// AD_value= (AD_value/4096)*3300;
// printf("The AD value = %d\r\n", AD_valu);
}
// ADC_Cmd(ADC1, DISABLE); //关闭AD
}
w=0;
sum_data=sum_data/64.0 ;//右移两位得到13位的数据
printf("The current AD wd_dianya = %d \r\n", (u16)sum_data);
// SetPoint=480; //
wd_dianya = (sum_data /4096.0)*3300.0; //对应的温度电压值
 V[SetPoint]=(Set[SetPoint/10 +1]-Set[SetPoint/10 ])/10.0*(SetPoint%10)+Set[SetPoint/10 ] ;//
printf("The PV[SetPoint]= %5.1fmV \r\n", PV[SetPoint]);
Error = PV[SetPoint] - wd_dianya; //wd_dianya为AD采样电压 Error = PV[SetPoint] - wd_dianya; //wd_dianya为AD采样电压
e0=(P+I*T+(D/T)); // 对应为 A e0=(double)P+(double)(I*4.4)+(double)(D/4.4);
printf("The e0= %d \r\n",(u8)(1000*e0)); //
e1=(P+2.0*(D/T)); // B e1=(double)P+2.0*(double)(D/T);
e2=(D/T); // C e2=(double)(D/T);
du=0.0;
du=(u8)(e0*Error-e1*LastError+e2*BEFORError)*0.05; //为返回的增量
printf("The du= %d \r\n",(u8)du);
BEFORError=LastError;
LastError=Error;
u=u+du; //返回占空比值1/200
if(u>=128.0)
{u=128.0;}
if(u<0){u=0.0;}
printf("The u is = %d \r\n", (u8)u);
printf("The current AD and u is ok = %5.4fmV \r\n", wd_dianya);
return u;
}
|