資源簡介
本實(shí)例采用51單片機(jī),AD,DA設(shè)計(jì),采用單片機(jī)C語言編程,并且通過Proteus軟件仿真。第一次上傳資料,請大家多多指教

代碼片段和文件信息
#include
#include
#define?uchar?unsigned?char
#define?uint?unsigned?int?
#define?KP?100
#define?TI?2
#define?TD?1
#define?T?1 ??
??sbit?start=P3^0;
??sbit?OE=P3^1;
??sbit?EOC=P3^2;??
??float??y_cur;
??float??y_pre;
??float??e_cur;
??float??e_pre;
??float??e_last;
??float??u_cur;
??float??u_pre;
??float??u_aug;
??uchar?AD;?
??uint??INPUT=3;
??uint?r;
void?pid_init()
??{
????r=INPUT;
y_cur=0;
y_pre=0;
u_pre=0;
e_pre=0;
e_last=0;
??}
float?pid_process()
??{ ?
?????float?q0?q1?q2;
?????e_cur=r-y_cur;
?q0=(float)(?KP*(1+T/TI+TD/T));
?q1=-KP-2*KP*TD/T;
?q2=KP*TD/T;
?u_aug=q0*e_cur+q1*e_pre+q2*e_last;
?u_cur=u_aug+u_pre;
?u_pre=u_cur;
?e_last=e_pre;
?e_pre=e_cur;
?y_pre=y_cur;
?return??u_cur;
??}
void??dac1()
??{
????uint?idata?out;
????out=(int)(pid_process());
P0=out;
??}
void?delayms()
{?
????int?ij;
????for(i=0;i<1000;i++)
??????{
????????for(j=0;j<10;j++);
????{
;
??? ?}
???????}
}
void?ad_0808(?)
{ ???
start=1;
start=0;
while(EOC==0)
?{
OE=1;
??}
?AD=P2;
?OE=0;
}
void??adc()
??{
??? ad_0808();
y_cur=AD;
???}
void??main()
{?
?????pid_init();
?????while(1)
????{
??delayms();
??dac1();
??????adc();
?}
}
?
?????
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件?????119499??2010-01-07?22:54??數(shù)字PID\Last?Loaded?PID??ok.DBK
?????文件???????1078??2010-01-07?22:54??數(shù)字PID\PID??ok.PWI
?????文件?????119499??2010-01-07?22:54??數(shù)字PID\PID??控制器.DSN
?????文件???????1296??2010-01-07?22:41??數(shù)字PID\PID?控制器.c
?????文件???????2178??2010-01-07?18:52??數(shù)字PID\PID?控制器.Uv2
?????文件???????6376??2005-03-22?15:22??數(shù)字PID\STARTUP.A51
?????文件??????14063??2010-01-07?22:54??數(shù)字PID\STARTUP.LST
?????文件????????758??2010-01-07?22:54??數(shù)字PID\STARTUP.OBJ
?????文件???????3844??2010-01-07?22:54??數(shù)字PID\Text1.LST
?????文件???????7682??2010-01-07?22:54??數(shù)字PID\Text1.OBJ
?????文件???????7670??2010-01-07?22:54??數(shù)字PID\wo?wo
?????文件???????3646??2010-01-07?22:54??數(shù)字PID\wo?wo.hex
?????文件?????????43??2010-01-07?22:54??數(shù)字PID\wo?wo.lnp
?????文件??????10354??2010-01-07?22:54??數(shù)字PID\wo?wo.M51
?????文件???????1034??2010-01-07?22:54??數(shù)字PID\wo?wo.Opt
?????文件???????1008??2010-01-07?22:54??數(shù)字PID\wo?wo.plg
????.......??????1041??2010-01-07?22:06??數(shù)字PID\wo?wo_Opt.Bak
????.......?????????0??2010-01-07?17:57??數(shù)字PID\wo?wo_Uv2.Bak
?????目錄??????????0??2010-01-07?22:55??數(shù)字PID
-----------?---------??----------?-----??----
???????????????301069????????????????????19
評論
共有 條評論