|
EDA365欢迎您登录!
您需要 登录 才可以下载或查看,没有帐号?注册
x
//PID算法温控C语言2008-08-17 18:58
6 Q) A* y# q. d#include<w77e58.h>
4 O! O ^ w/ }, O% d; i6 q5 j#include<intrins.h> C2 u" E% a: K0 A. x7 I3 Z
#include<math.h> 5 Y; D% u, u4 ?( s t) h. x
#include<string.h>
5 ^. s8 E- g6 B3 P4 h/ {9 _struct PID {
! |6 n- k0 G {0 h( j' w; dunsigned int SetPoint; // 设定目标 Desired Value 7 A8 i. c' y8 X5 P9 l, l# x
unsigned int Proportion; // 比例常数 Proportional Const ( s1 u- b% O! d9 ^) ]; j
unsigned int Integral; // 积分常数 Integral Const $ P# j3 L- i) \4 P
unsigned int Derivative; // 微分常数 Derivative Const
' o! v" M# m+ e. s0 Wunsigned int LastError; // Error[-1] 7 p D3 H, Y* P |6 ]8 k
unsigned int PrevError; // Error[-2]
2 X; n5 E Q" l3 f3 H: Yunsigned int SumError; // Sums of Errors : r& H+ f# X1 v5 q- W; P
};
* {$ b Z9 v0 wstruct PID spid; // PID Control Structure 8 e% d; u3 U1 |& ^8 O1 |! M* {
unsigned int rout; // PID Response (Output)
+ Z. h7 K+ k' \unsigned int rin; // PID Feedback (Input) 1 |# ]# O3 ]/ n# q) X1 v/ {
sbit data1=P1^0;
5 M" {# _: }( y$ w4 p' Ksbit clk=P1^1;
5 C/ p/ r1 e+ A6 b5 }, o/ Lsbit plus=P2^0;
* n; H8 x/ e' W0 x) S2 h2 l4 Tsbit subs=P2^1;
5 j/ E, X; ~1 ^9 S: M/ Qsbit stop=P2^2; 8 `$ ~* M0 j; m# o1 N
sbit output=P3^4; 1 m; }+ S. x" m( ^1 c1 s- w$ z# M
sbit DQ=P3^3; ' V3 \4 b! t/ i
unsigned char flag,flag_1=0; ) x6 A/ ` b8 R8 J" n1 v
unsigned char high_time,low_time,count=0;//占空比调节参数
& w: w+ W/ Y% B. O& [3 `unsigned char set_temper=35;
' I( A& S* W9 K }; t( F$ nunsigned char temper;
7 U: p4 X2 @ c# |; N' O8 \unsigned char i; ) R6 V& }( R# g; |; \1 X
unsigned char j=0; 1 w' a8 n; ^8 [) f0 L; L
unsigned int s;
$ ?3 ^2 p) a4 v! a' h* ~/*********************************************************** & R W/ ^8 b6 V! s* r/ i! o/ \
6 A ?- q4 X+ Q7 g
4 b v( Z8 |6 J# T" O |
|