| 
 | 
	
    
 
EDA365欢迎您登录!
您需要 登录 才可以下载或查看,没有帐号?注册  
 
x
 
//PID算法温控C语言2008-08-17 18:58 
5 F' h6 Z, |2 E3 v( ~3 n#include<w77e58.h>  
; D; ^2 J  e1 W% D#include<intrins.h> 5 s& o' T# T8 K- N  U 
#include<math.h>  
; B% S6 \7 k7 C0 a4 P#include<string.h>  
7 y" f1 f( F: Q3 `struct PID { 2 n. S4 ^9 n# l2 Q9 D! A 
unsigned int SetPoint; // 设定目标 Desired Value  
0 c5 b3 x' h; S3 V" Junsigned int Proportion; // 比例常数 Proportional Const , Z8 }) ]/ w$ k+ F' o/ H$ B 
unsigned int Integral; // 积分常数 Integral Const  
  `6 _4 X! a, f" D( _unsigned int Derivative; // 微分常数 Derivative Const  
3 M$ d  [; y9 m: b4 N+ D! a# gunsigned int LastError; // Error[-1]  
. K( q1 C9 @# X1 Sunsigned int PrevError; // Error[-2]  
* r* b  w+ U5 B* v3 y) B; L9 hunsigned int SumError; // Sums of Errors  
/ B" s7 a1 N8 b9 Y/ z& g) A5 J};   s4 l  B- g) K7 ^ 
struct PID spid; // PID Control Structure / k! C. J# V, ], R& W9 t1 q2 j 
unsigned int rout; // PID Response (Output) $ W2 w" H4 ?7 E; P 
unsigned int rin; // PID Feedback (Input)  
. f9 i; C+ d) B1 R8 ]; z8 [sbit data1=P1^0;  
( t4 p3 G/ u$ H' z: e: o( Csbit clk=P1^1; $ V; N5 e! b0 |5 b2 z 
sbit plus=P2^0; 6 \& N2 v% \. b% k8 E7 t$ E 
sbit subs=P2^1;  
# C$ y. K: D0 d9 {sbit stop=P2^2; 5 Z. O: ]/ P/ P! m# D" d* L 
sbit output=P3^4;  
/ _1 g3 d/ u2 D$ L4 F3 |: ]sbit DQ=P3^3; ( K/ D- C: D2 s 
unsigned char flag,flag_1=0;  
; G& N" G/ t3 e0 v3 Nunsigned char high_time,low_time,count=0;//占空比调节参数 - c, v7 b0 U% N  m0 d 
unsigned char set_temper=35;  
3 n$ Q, s7 A2 u8 ]. Xunsigned char temper;  
: z7 @/ Y3 `4 _; |unsigned char i;  
  b( s3 m( N4 I3 Q- W/ {. r' B% Z$ m) Gunsigned char j=0; 1 ~- x+ X2 [0 \/ _1 ]+ ^" t4 C/ J! q+ W 
unsigned int s;  
/ l7 H( W$ E! n* S9 a  d: \" g( y/*********************************************************** 4 l0 ~/ Y% i+ I, X 
) }* s& Q$ f% I2 s7 u 
6 G: s3 t/ v& S! R. k) y& T 
 |   
 
 
 
 |