TA的每日心情 | 开心 2023-5-30 15:22 |
---|
签到天数: 1 天 [LV.1]初来乍到
|
EDA365欢迎您登录!
您需要 登录 才可以下载或查看,没有帐号?注册
x
//PID算法温控C语言2008-08-17 18:58
7 j) X! B0 m- [ D( V#include<w77e58.h> " [& g9 l2 I. {/ {: z7 {. H
#include<intrins.h>
' a% _1 b( }/ e; ]7 ^#include<math.h> % |' m2 f( }. ^8 Q) e! a, L) P
#include<string.h> $ `) t Z, E4 B5 G
struct PID {
& {3 W, G$ B! q% F! kunsigned int SetPoint; // 设定目标 Desired Value 2 G& v0 ^. H. F
unsigned int Proportion; // 比例常数 Proportional Const " h6 {) }' w% K: e* k1 R
unsigned int Integral; // 积分常数 Integral Const " B/ m. L2 R1 Q
unsigned int Derivative; // 微分常数 Derivative Const ( ]/ J/ g" f& m/ e9 \2 Z# ^
unsigned int LastError; // Error[-1]
: d) b& e1 [3 E, ?9 J& j$ n" M2 nunsigned int PrevError; // Error[-2] & a: [& S' p, Y6 K. T2 t q
unsigned int SumError; // Sums of Errors - [5 w. s& M! F+ b. j
}; * a2 Y# j4 Y8 A' F7 t' ^5 s3 {$ I6 k
struct PID spid; // PID Control Structure # S/ i9 V7 V1 T- l; G
unsigned int rout; // PID Response (Output)
) n9 y% L, b, @( o }& Junsigned int rin; // PID Feedback (Input) ( c2 W# T9 D& ^: \8 b
sbit data1=P1^0;
, ~* A9 K5 G3 E; K4 Osbit clk=P1^1;
' R& h5 Q) u4 i0 o# y) ysbit plus=P2^0;
% f+ s3 s8 g) ^2 i1 Q, Csbit subs=P2^1;
% D2 p. T4 _% M }sbit stop=P2^2;
/ W* E, o% N$ E0 [# |7 Esbit output=P3^4;
: I/ {# l( j+ x3 s) w7 Osbit DQ=P3^3;
O/ a. f" p1 |) e hunsigned char flag,flag_1=0; 4 o* A/ l" s4 b7 ?5 O
unsigned char high_time,low_time,count=0;//占空比调节参数
G2 R$ d* g$ t3 Z7 O6 C g9 munsigned char set_temper=35;
$ L, @& G V' x ]& ]unsigned char temper;
% N% b# g! c3 L0 ~unsigned char i;
4 z7 b5 _ Q* K+ K5 g1 J$ Xunsigned char j=0;
7 t% f5 f3 f6 Wunsigned int s; 7 X" b2 {! ~ k- W( ]* Z/ n
/***********************************************************
, A8 d6 ^( C) \延时子程序,延时时间以12M晶振为准,延时时间为30us×time 6 ^2 r+ l1 Y2 [8 Z! b, i
***********************************************************/ . d: p/ F4 p+ r6 \, n
void delay(unsigned char time)
& ]0 {9 x. j! F" Q9 M9 x{ 5 s; S$ f3 z) A* y1 K
unsigned char m,n;
6 Y5 G: d3 L4 |for(n=0;n<time;n++)
. q: @9 c" C$ s8 U3 j4 nfor(m=0;m<2;m++){} ( ? g# ~$ a* a2 y a/ c- I- x1 |' r
}
. w2 c! i) E" F& i/ p' q, q6 e/***********************************************************
0 G$ l# z5 h6 _& `: c写一位数据子程序 ! U) z- E5 d3 c& I3 j+ N
***********************************************************/ 7 ^5 c: D2 P3 J' I: I! Y/ o' b
) q% u- E) O3 A5 Z
" I* i) u4 n% A5 t8 {# y7 a5 w& y |
|