|
EDA365欢迎您登录!
您需要 登录 才可以下载或查看,没有帐号?注册
x
//PID算法温控C语言2008-08-17 18:58
" S- v% z% w" a0 S1 B9 J4 U0 h#include<w77e58.h> * m6 \7 ^' v# Y* r
#include<intrins.h> ( R `$ i5 O1 K( O* V
#include<math.h>
+ j6 H( J' a& C4 w#include<string.h> ) f9 C. d! ]2 v1 L+ s
struct PID {
; o0 I6 v6 Y# \unsigned int SetPoint; // 设定目标 Desired Value
7 {" ^1 b ?( K9 C* ? @unsigned int Proportion; // 比例常数 Proportional Const
: d( [! t4 N/ ]1 junsigned int Integral; // 积分常数 Integral Const
- z2 i) V. W. H4 munsigned int Derivative; // 微分常数 Derivative Const $ ]3 w% d: t) Y6 s
unsigned int LastError; // Error[-1] + u- `1 w% e$ u0 d
unsigned int PrevError; // Error[-2]
0 E- I! n1 W( \) kunsigned int SumError; // Sums of Errors ! E1 i+ ?8 ?# O( J0 M- A8 h
};
% x. p% c- c2 T; f" kstruct PID spid; // PID Control Structure 5 X/ h9 U% X- D7 s6 l$ R
unsigned int rout; // PID Response (Output) & Z6 }4 h% j! o6 h! `
unsigned int rin; // PID Feedback (Input)
% \2 Q' o/ j) }/ b3 h% tsbit data1=P1^0; ; [6 V8 R) ~7 ]3 y" T
sbit clk=P1^1;
; r! ]) _4 u, l! a* d* zsbit plus=P2^0;
$ u# I: n6 z% J- W( j4 Gsbit subs=P2^1;
& z: t* i6 r" ]* l. g/ nsbit stop=P2^2;
8 J- _) @$ I; c; csbit output=P3^4;
# Z9 d4 j, G6 q& O( x4 q% M4 vsbit DQ=P3^3; , A, c1 T' ?2 X; ~
unsigned char flag,flag_1=0;
- B' e* A" M6 [4 O: y( s+ c% yunsigned char high_time,low_time,count=0;//占空比调节参数 # U+ C+ ?5 J j$ N2 G1 n3 x. a
unsigned char set_temper=35; 6 ^/ @; A; I- }9 o$ A0 i4 T
unsigned char temper;
2 N' C! }" |7 ]$ i/ }: s$ n# X2 S3 Lunsigned char i;
2 O: a) `# ? H* s4 Munsigned char j=0;
|/ Q* A8 t0 Eunsigned int s;
- W( v7 U: Z, S, p" o) J5 M: [# M/***********************************************************
/ W. ~8 B. M. `* K3 Q
2 X. l" ]# V; X8 z- Q! p0 ]3 m* D
* Z C c; X6 ~- _/ {9 O |
|