TA的每日心情 | 开心 2023-5-30 15:22 |
|---|
签到天数: 1 天 [LV.1]初来乍到
|
EDA365欢迎您登录!
您需要 登录 才可以下载或查看,没有帐号?注册
x
//PID算法温控C语言2008-08-17 18:58
) S5 V, a! ?7 h$ j1 @#include<w77e58.h> / E6 u! u) I, T& B( N! e
#include<intrins.h>
. ^& k" S) G M& F#include<math.h>
$ a5 A- z2 k$ d0 x: S5 E1 @. j/ s#include<string.h>
8 F' K% J j/ @& ?2 i- ^struct PID { - K$ d+ J2 N9 J7 o: Z
unsigned int SetPoint; // 设定目标 Desired Value : f# g! l% m/ L
unsigned int Proportion; // 比例常数 Proportional Const
5 r. d8 `( P% K* k3 ?" munsigned int Integral; // 积分常数 Integral Const , @! L( ^5 R2 e9 V
unsigned int Derivative; // 微分常数 Derivative Const
" W @: v1 n& [: p8 u5 q% lunsigned int LastError; // Error[-1] 4 h' K$ J" _# i( h
unsigned int PrevError; // Error[-2]
* Z9 `# i$ a. @" N, j/ Munsigned int SumError; // Sums of Errors
" j0 ~1 T: Y( D( o}; 6 M* L# O) E; @8 G% v+ }' a9 P
struct PID spid; // PID Control Structure " r% Y+ j5 l/ ]2 ?
unsigned int rout; // PID Response (Output)
! |& V1 s! o% N+ F, runsigned int rin; // PID Feedback (Input) & _, {6 i, i( t$ a2 L
sbit data1=P1^0; , f) a3 i% e0 }, @
sbit clk=P1^1; " c" [" g5 h& |+ x5 @2 N" a
sbit plus=P2^0; " A: w+ [; _% }: w# ^. S
sbit subs=P2^1; - y9 }9 Y" E8 W: r# n! S* W
sbit stop=P2^2; + @) V( {$ B+ n: L5 {
sbit output=P3^4; - v/ Y) Y3 [* R7 Y
sbit DQ=P3^3;
: p2 J8 m! k& }/ D, aunsigned char flag,flag_1=0; 9 g9 p2 F1 |% _
unsigned char high_time,low_time,count=0;//占空比调节参数 . \+ X8 Y3 D/ J/ u( u( A" B
unsigned char set_temper=35;
6 t' u6 { F+ e0 D2 \unsigned char temper;
+ K4 ^) f+ K) @) _unsigned char i; 8 o: ^; e+ R; D4 u' a
unsigned char j=0;
6 b7 ?* V1 `( junsigned int s;
) P( P$ x9 m3 R& r' N& b/*********************************************************** " s2 [6 z& w4 s8 i6 y! Y9 T. `
延时子程序,延时时间以12M晶振为准,延时时间为30us×time
" F- U& h H5 x; I& n( E***********************************************************/
. w' ^; t/ v: H8 |6 ]void delay(unsigned char time)
: B' C+ H$ X, t6 N2 f( Z6 Z{
- c* r( w( a6 g+ Zunsigned char m,n;
% H0 d, j+ \& v- |3 H Tfor(n=0;n<time;n++) 3 f8 S9 C& T Q. C( e D, I
for(m=0;m<2;m++){} 5 e, ~0 Q V/ s- V; P( K j m o
}
4 [' `" `' m; K. ?* c3 z/***********************************************************
) @- [' O* X+ X7 g. c/ \, F写一位数据子程序
8 b+ |& @, e& S6 @4 S4 V4 v***********************************************************/
" W( c& Y" `4 P& [ v2 U4 e) O7 p0 Q7 K6 C' ~: W, D
/ u7 A$ ?8 j; L( U |
|