A题-报告7-程序清单 | ||||
| ||||
A题-报告7-程序清单 初始化代码: intmain(void) { /* Halting the Watchdog */ MAP_WDT_A_holdTimer();
InitLed();//led InitCS();//时钟 InitKey();//按键 InitSystick();//sys InitADC14();//adc TimerA0_Channeln_PWM(1,1,50000,0);//H-PWM,P2.4左边 TimerA0_Channeln_PWM(2,0,50000,100);//L-PWM,p2.5右边
OLED_SSD1306_Init();//led Mode_menu(); /* Enabling MASTER interrupts */ MAP_Interrupt_enableMaster();
while (1) { MAP_PCM_gotoLPM0(); } } 电压反馈调节代码: signedintPI_Control_U (unsignedint Val_FB, unsignedint Val_Ref) { signedlong temp; Val_Error_U[0] = Val_Ref;//类型强制转换 Val_Error_U[0] = Val_Error_U[0] - Val_FB; Val_Error_U[0] = Val_Error_U[0] * 64; //乘以64以提高计算精度 temp=Val_Error_U[0]*K1_U/64 - Val_Error_U[1]*K2_U/64; if(temp>38) { temp=38; } if(Val_Error_U[0] <= EEROR_DELTA && Val_Error_U[0] >= -EEROR_DELTA) { Resp_U[0] = Resp_U[1]; } else { Resp_U[0] = Resp_U[1] + temp; }
if(Resp_U[0] > 32000) Resp_U[0] = 32000; elseif(Resp_U[0] < -32000) Resp_U[0] = -32000;
Resp_U[1] = Resp_U[0]; Val_Error_U[1] = Val_Error_U[0];
return (signedint)(Resp_U[0]/64); } |