|
EDA365欢迎您登录!
您需要 登录 才可以下载或查看,没有帐号?注册
x
//PID算法温控C语言2008-08-17 18:58
; z- R* E+ v o+ p7 |9 W# l/ p#include<w77e58.h>
+ }. Y. `9 T/ I2 s6 h; d#include<intrins.h> ) W2 B! P6 a8 ~1 O G9 [: |# t) \
#include<math.h> * W2 m# h3 h- ]+ ^
#include<string.h> 8 q6 }9 D0 W$ p; b2 W% t& E
struct PID {
h2 d( @7 X2 runsigned int SetPoint; // 设定目标 Desired Value
* n( g. t' p+ ]unsigned int Proportion; // 比例常数 Proportional Const ) y* V9 g% x3 e5 ]2 J1 i; E
unsigned int Integral; // 积分常数 Integral Const # u9 z3 R: X5 J: i
unsigned int Derivative; // 微分常数 Derivative Const # Z4 \) _9 z# O7 Y
unsigned int LastError; // Error[-1] 4 p9 a1 P0 i6 v
unsigned int PrevError; // Error[-2] " u5 J# h' z5 n4 j: p8 w8 D0 V
unsigned int SumError; // Sums of Errors
/ G, K7 L5 U# ~4 y7 \, z};
) i9 J, d; L7 _5 S- ^, ]; \' qstruct PID spid; // PID Control Structure J. a/ f- x! Z. G/ O- r$ W& a
unsigned int rout; // PID Response (Output)
9 m7 N+ _" T; L& cunsigned int rin; // PID Feedback (Input) " ?) Y; c, Z7 k5 {) d/ t
sbit data1=P1^0;
* M$ Z+ k" r5 ]- ^4 i2 isbit clk=P1^1;
. p' a/ x, H7 T; `( `8 Zsbit plus=P2^0; $ D: Q; Z2 m: y6 K) X
sbit subs=P2^1; # B* L+ w& a1 W" D: Z
sbit stop=P2^2; q$ \9 K; ?% h1 o- U
sbit output=P3^4; 1 M! h6 K2 t$ `; s1 n# b
sbit DQ=P3^3;
% Y4 J" B& f" E) n$ wunsigned char flag,flag_1=0; / e. [1 h. l F- ? L/ Q
unsigned char high_time,low_time,count=0;//占空比调节参数 $ A! L/ }' Y# c* D5 w, ~, n
unsigned char set_temper=35;
' q2 J0 Q' v6 g2 k" Z8 Nunsigned char temper; 1 x" J! U3 T( `# o
unsigned char i;
1 s k# I7 A. K/ ? Q4 ^& Sunsigned char j=0;
* j/ {* I- f# ?unsigned int s;
+ U. t$ p- q; `# b/*********************************************************** . S b4 A% _: {* o! Z# l# b' }8 p. r
0 W' T* J0 U+ Z9 m; p. H! s
+ W% v* F7 O) A |
|