【正文】
astError。 ppLastError = Error。 return (ppProportion * Error // 比例項 + ppIntegral * ppSumError // 積分項 + ppDerivative * dError // 微分項 )。}//繼電器控制子程序//===========================================================//函數(shù): void active()//語法:void active()//描述:PID輸出值的處理//參數(shù):無//返回:無//===========================================================void active(){ if(Out=0){ turn_off_relay()。 //溫度高于設定值,關(guān)閉電爐 turn_off_timerB()。 //停止計時 }Else{ if(Out30*) //溫度低于設定值2攝氏度 turn_on_relay()。 //開電爐加熱 else { turn_on_relay()。SP_INT_TIMEB()} //初始化定時器,開始定時加熱 }}//=======================================================//函數(shù): 主程序//語法:int main(void)//描述:鍵盤掃描、溫度控制//參數(shù):無//返回:無//=======================================================int main(void){ int KeyValue。 status = temperature_set。 System_Initial()。 PID_Initial()。 //PID初始化 while(1){ KeyValue = GetCh()。 //鍵盤掃描、去抖動處理、取鍵值 key_value_process(KeyValue)。 //鍵值處理 if(status = temperature_control) display_AD_temperature()。 //測量溫度顯示、PID計算 if(Out=0) turn_off_timer()。 }}電路原理圖:參考文獻 [1]黃智偉. 全國大學生電子設計競賽電路設計. 北京:北京航天航空大學出版社,2007 [2]譚浩強. C程序設計. 北京:清華大學出版社,2002 [3](第四版). 北京:科學出版社, 2000Microcontrollerbased temperature control system Li Hong (Physics ang Electrical Engineerring ,Anyang Nomal University ,Anyang,455002)Abstract: Temperature is the main control of industrial control of parameters, In temperature control, due to temperature controlled object properties (such as inertia big, big, lagging effect of nonlinear, etc.), to improve performance, some process temperature control of its direct impact on the quality of the product, and designed a kind of ideal temperature control system is a very valuable. In order to realize high precision temperature measurement and control, this paper introduces a meter taking Atmel pany lowpower highperformance CMOS chip as the core, and the PID control algorithm with PID parameters bination of control method to realize the temperature control system, the hardware circuit including temperature, temperature control, temperature gathering, keyboard input and RS232 interface circuits, etc. The system can realize the measurement for temperature, and can according to value of temperature adjustment, and realize the objective temperature control. Key words: AT89C51 microcontroller, Temperature control, PT1000 temperature sensor, PID algorith