51單片機(jī)-溫度PID算法(C程序)_第1頁
51單片機(jī)-溫度PID算法(C程序)_第2頁
51單片機(jī)-溫度PID算法(C程序)_第3頁
全文預(yù)覽已結(jié)束

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)

文檔簡介

第第頁51單片機(jī)-溫度PID算法(C程序)#include"reg51.h"#include"intrins.h"#include"math.h"#include"string.h"structPID{unsignedintSetPoint;//設(shè)定目標(biāo)DesiredValueunsignedintProportion;//比例常數(shù)ProportionalConstunsignedintIntegral;//積分常數(shù)IntegralConstunsignedintDerivative;//微分常數(shù)DerivativeConstunsignedintLastError;//Error[-1]unsignedintPrevError;//Error[-2]unsignedintSumError;//SumsofErrors};structPIDspid;//PIDControlStructureunsignedintrout;//PIDResponse(Output)unsignedintrin;//PIDFeedback(Input)sbitdata1=P1^0;sbitclk=P1^1;sbitplus=P2^0;sbitsubs=P2^1;sbitstop=P2^2;sbitoutput=P3^4;sbitDQ=P3^3;unsignedcharflag,flag_1=0;unsignedcharhigh_time,low_time,count=0;//占空比調(diào)節(jié)參數(shù)unsignedcharset_temper=25;unsignedchartemper;unsignedchari;unsignedcharj=0;unsignedints;voiddelay(unsignedchartime){unsignedcharm,n;for(n=0;nfor(m=0;m>i;temp=tempwrite_bit(temp);}delay(7);//TR0=1;EA=1;}unsignedcharread_bit(){unsignedchari,value_bit;EA=0;DQ=0;_nop_();_nop_();DQ=1;for(i=0;i>4;temper=i|j;}voidPIDInit(structPID*pp){memset(pp,0,sizeof(structPID));//全部初始化為0}unsignedintPIDCalc(structPID*pp,unsignedintNextPoint){unsignedintdError,Error;Error=pp->SetPoint-NextPoint;//偏差pp->SumError+=Error;//積分dError=pp->LastError-pp->PrevError;//當(dāng)前微分pp->PrevError=pp->LastError;pp->LastError=Error;return(pp->Proportion*Error//比例項+pp->Integral*pp->SumError//積分項+pp->Derivative*dError);//微分項}voidcompare_temper(){unsignedchari;if(set_temper>temper)//是否設(shè)置的溫度大于實際溫度{if(set_temper-temper>1)//設(shè)置的溫度比實際的溫度是否是大于1度{high_time=100;//如果是,則全速加熱low_time=0;}else//如果是在1度范圍內(nèi),則運行PID計算{for(i=0;i0){high_time=0;low_time=100;}else{for(i=0;i>1;if(m==1)data1=1;elsedata1=0;_nop_();clk=1;_nop_();}}}voiddisplay(){unsignedcharcodenumber[]={0xfc,0x60,0xda,0xf2,0x66,0xb6,0xbe,0xe0,0xfe,0xf6};unsignedchardisp_num[6];unsignedintk,k1;k=high_time;k=k00;k1=k/100;if(k1==0)disp_num[0]=0;elsedisp_num[0]=0x60;k=k0;disp_num[1]=number[k/10];disp_num[2]=number[k];k=temper;k=k0;disp_num[3]=number[k/10];disp_num[4]=number[k]+1;disp_num[5]=number[s/10];disp_1(disp_num);}voidmain(){unsignedcharz;unsignedchara,b,flag_2=1,count1=0;unsignedcharphil[]={2,0xce,0x6e,0x60,0x1c,2};TMOD=0x21;TH0=0x2f;TL0=0x40;SCON=0x50;PCON=0x00;TH1=0xfd;TL1=0xfd;PS=1;EA=1;EX1=0;ET0=1;ES=1;TR0=1;TR1=1;high_time=50;low_time=50;PIDInit(//InitializeStructurespid.Proportion=10;//SetPIDCoefficients比例常數(shù)ProportionalConstspid.Integral=8;//積分常數(shù)IntegralConstspid.Derivative=6;//微分常數(shù)DerivativeConstspid.SetPoint=100;//SetPIDSetpoint設(shè)定目標(biāo)DesiredValuewhile(1){if(plus==0){EA=0;for(a=0;a5)temper=a;elsetemper=b;a=temper;flag_2=0;if(++count1>30){display();count1=0;}compare_temper();}TR0=

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

最新文檔

評論

0/150

提交評論