|
|
EDA365欢迎您登录!
您需要 登录 才可以下载或查看,没有帐号?注册
x
//PID算法温控C语言2008-08-17 18:58* A* b2 i8 Y& V& t3 F$ T
#include<w77e58.h> # I9 ~2 m% ~9 N; Q7 t
#include<intrins.h> ' a; A0 X* @3 @1 p# t# m% e
#include<math.h> # ^% L+ w! y, F* T6 I- ^+ T
#include<string.h> [8 k# {( J. u- T. u, E# ^7 c
struct PID {
% V! l" ~7 h5 e( I' Q( Uunsigned int SetPoint; // 设定目标 Desired Value 9 S) R, s6 u2 v; H. B
unsigned int Proportion; // 比例常数 Proportional Const " |: A- W" P! B9 f! a
unsigned int Integral; // 积分常数 Integral Const
( J& r! \; L6 c& {unsigned int Derivative; // 微分常数 Derivative Const , C, n1 x; @+ m5 D0 O$ ?) Z
unsigned int LastError; // Error[-1] 7 F" \" a; ~$ O8 h" S
unsigned int PrevError; // Error[-2]
" q* {$ S0 O3 b6 v% |unsigned int SumError; // Sums of Errors
, }/ e4 {! |) z2 H}; $ w% }( _7 M7 J$ f
struct PID spid; // PID Control Structure
6 Q9 a- o7 J- D& S+ i8 eunsigned int rout; // PID Response (Output)
6 S! {# C3 c6 @/ F( z. N" munsigned int rin; // PID Feedback (Input) / n9 B- K4 @0 U
sbit data1=P1^0;
" A5 y1 H& X1 \+ w7 asbit clk=P1^1; 2 a3 Z& W# |( U. Y( O+ U8 T
sbit plus=P2^0; & Q; P7 U* z& J# t; x1 f& n
sbit subs=P2^1; 4 Y6 C! Q P$ t8 V5 {
sbit stop=P2^2; + w3 H* l2 f' t% X
sbit output=P3^4; 5 _ N4 R g9 e
sbit DQ=P3^3;
! e4 Z" p; B, B6 c3 wunsigned char flag,flag_1=0;
5 N8 i$ y7 T% g! o2 H, cunsigned char high_time,low_time,count=0;//占空比调节参数 8 z1 `; t: {4 X7 D/ P
unsigned char set_temper=35; 3 S* q- U! c7 R7 _( k' F; i( L9 l. M
unsigned char temper;
; k4 C/ l( f8 ?, `unsigned char i;
4 c4 w0 ^ P8 w5 ~! |% D. xunsigned char j=0; 0 H j! Y {( v) U+ j: S' I6 c/ Q
unsigned int s;
! Y! x r; y- W% g$ E0 w# [2 c$ F/*********************************************************** / v; j& f: Z2 K5 r# G
5 k, X/ X2 M( n8 b6 _7 b% g# ]0 v* s4 z& O) m' u5 f9 ]9 H' o
|
|