|
EDA365欢迎您登录!
您需要 登录 才可以下载或查看,没有帐号?注册
x
//PID算法温控C语言2008-08-17 18:58
& {* W. p; Y( j4 M, @' g1 s3 a#include<w77e58.h>
! ^1 v, J" a+ h#include<intrins.h> $ ^- R1 [+ \, G
#include<math.h>
8 F% C6 U P' \! Z5 G( q#include<string.h> 2 z- J3 p6 L- p) s% a9 Y* G1 E4 u
struct PID {
6 Y) ~/ A) B" s( U, `" M5 B* e$ gunsigned int SetPoint; // 设定目标 Desired Value
( d' N _; z2 [unsigned int Proportion; // 比例常数 Proportional Const / o! P3 F* U9 n9 A; ?. u! M3 x$ W
unsigned int Integral; // 积分常数 Integral Const - V# T5 Y* f5 R
unsigned int Derivative; // 微分常数 Derivative Const . s, T/ w; w0 G. @
unsigned int LastError; // Error[-1] * C/ p) m) L& Y
unsigned int PrevError; // Error[-2]
3 L# r. ^4 _/ ` ]6 \9 qunsigned int SumError; // Sums of Errors
; a: d1 d/ K6 x3 k};
0 E \( m8 H6 t- r9 _ I% dstruct PID spid; // PID Control Structure , V8 S# I8 s: u2 |2 g1 H# a: U
unsigned int rout; // PID Response (Output) 9 H) K, R6 o; U0 L2 s$ X
unsigned int rin; // PID Feedback (Input)
/ g% a- f! i7 T6 A: Msbit data1=P1^0;
; S) c# J4 J/ R* s; S# Hsbit clk=P1^1; . ]+ \# G7 T& g `8 c
sbit plus=P2^0; 7 V; d" ^9 ]* v; V' G, I
sbit subs=P2^1; & S% G& Y9 }$ _* e, G7 X# f
sbit stop=P2^2; ( B) \( X9 i _3 ?# d& l& V/ i
sbit output=P3^4;
; F" S6 a# g2 [) o# Z' u& r6 Gsbit DQ=P3^3; ; Y2 U1 @/ h6 C1 ^
unsigned char flag,flag_1=0;
4 z( g w1 F" b* c# ounsigned char high_time,low_time,count=0;//占空比调节参数
7 W) _: y0 R" r9 c) Q- |unsigned char set_temper=35;
6 ?3 { d+ u( n6 q& D4 _ Tunsigned char temper; 7 g0 Q$ j; m8 X( }$ A C7 I+ N9 n7 ?
unsigned char i; ( I1 m+ `: [8 x1 A1 O" @$ ?$ ?
unsigned char j=0; ' r9 W6 X0 Y/ w$ E% n2 ^
unsigned int s;
' B `# M9 j4 S* `) T+ _. H* _/***********************************************************
8 Q @2 f: i9 C/ u+ e5 [$ c I2 e+ ~; A @9 e; U+ t
" H, o' g. N) a0 H9 n |
|