|
EDA365欢迎您登录!
您需要 登录 才可以下载或查看,没有帐号?注册
x
//PID算法温控C语言2008-08-17 18:58
* l, Y \7 l: J9 o$ K/ X2 l#include<w77e58.h>
/ J$ u! I( f" x( p5 S' P/ h8 V#include<intrins.h> ' Z! u2 ~0 e" v" ?( x* v( J4 S: l
#include<math.h>
5 ~6 Z$ Q$ g; s' N#include<string.h>
2 g8 b: L( k6 Rstruct PID { 5 c; e& Y( V- L: P$ `; n
unsigned int SetPoint; // 设定目标 Desired Value
6 g1 h1 `$ q) ^0 D: Lunsigned int Proportion; // 比例常数 Proportional Const
/ K, ?+ P9 t% Junsigned int Integral; // 积分常数 Integral Const $ z- z: k! \1 Q. E" `# d" P2 b
unsigned int Derivative; // 微分常数 Derivative Const
1 a* t! f }* ?' ounsigned int LastError; // Error[-1]
6 D; {2 C' \# x* u* \! i$ Munsigned int PrevError; // Error[-2] 9 s% {" M# k* M- k, m
unsigned int SumError; // Sums of Errors
8 |8 Z) ~" g- O7 {: ~+ g};
) L0 i4 ?2 E& V( Wstruct PID spid; // PID Control Structure
# W. c7 ^$ T- r/ [, B4 eunsigned int rout; // PID Response (Output)
6 G- c' k) z0 Punsigned int rin; // PID Feedback (Input) ! y" x7 O D" t% S, M
sbit data1=P1^0; ; G$ a* P2 e$ m
sbit clk=P1^1; # F, W- e; d. R1 n! F) Z# }" D; M
sbit plus=P2^0; % Y% f# C$ W9 r7 g: U+ o0 L. L
sbit subs=P2^1; 0 w; v4 l( Z3 [( e6 t# _" S) @
sbit stop=P2^2; . H/ i; ^( D- t, M" o, j/ J
sbit output=P3^4;
; y: p# I( v4 Xsbit DQ=P3^3;
" d) U5 @, x! t4 o( c* Y2 K1 c; o- Hunsigned char flag,flag_1=0;
& J1 J3 t) O: u& V o! |! |& Iunsigned char high_time,low_time,count=0;//占空比调节参数 8 O% k; [$ J7 e8 ?; V y4 o8 P
unsigned char set_temper=35; 7 y2 @; R+ _. Q3 z6 n C/ `
unsigned char temper;
. e' _5 q. Y/ D& B0 ?( nunsigned char i;
+ M2 i P& y% L/ munsigned char j=0;
& M" y5 b" X% |: lunsigned int s; , Z: z O. e1 t, K* e9 f
/*********************************************************** 0 S9 D4 C* Y- @$ m* @2 i8 Z
! Y6 Y6 x" Y( C4 f4 U) w5 Q
; |0 @' V. ]% P- M1 o7 q! a) N |
|