TA的每日心情 | 开心 2023-5-30 15:22 |
---|
签到天数: 1 天 [LV.1]初来乍到
|
EDA365欢迎您登录!
您需要 登录 才可以下载或查看,没有帐号?注册
x
//PID算法温控C语言2008-08-17 18:58. b) o$ h) z, O4 c5 s0 Z
#include<w77e58.h>
6 a7 s3 p9 o$ b0 G! c8 h/ M#include<intrins.h> # d! R" _! t. A. ?' Z' m
#include<math.h>
0 w5 i; x0 C. \/ @3 S% R. ?#include<string.h>
[ ^0 e3 A l7 ~. _" m8 @struct PID {
" [, r+ m* A4 qunsigned int SetPoint; // 设定目标 Desired Value - O7 [3 O: y0 D3 S7 E _1 t1 d
unsigned int Proportion; // 比例常数 Proportional Const ' L$ [0 t G' V+ c: |8 x
unsigned int Integral; // 积分常数 Integral Const
' u! U9 ?+ m! n: Y% }4 u+ H, Xunsigned int Derivative; // 微分常数 Derivative Const : X+ Z) _0 b3 H9 i: p1 w. z' x5 H
unsigned int LastError; // Error[-1]
/ ~+ X/ b$ f- G) \unsigned int PrevError; // Error[-2] ! j/ k0 q; s! O5 u
unsigned int SumError; // Sums of Errors ! O3 G' e R* k3 I: R
};
1 ]& N& J+ N/ Cstruct PID spid; // PID Control Structure p9 f% M% w7 L p
unsigned int rout; // PID Response (Output)
& g2 Z9 a: N Y# Lunsigned int rin; // PID Feedback (Input)
: q+ Q, T- {* g8 M. rsbit data1=P1^0; 8 M* R- z, z( Q' T
sbit clk=P1^1;
0 e( \# R# y- [# h# p( Usbit plus=P2^0; : |# r. w" I7 `6 y7 j
sbit subs=P2^1;
; v" S0 s( N$ }+ _, C5 Csbit stop=P2^2;
! H' r+ P/ F o- E; N7 x8 vsbit output=P3^4; # A/ I6 c7 d4 \( x
sbit DQ=P3^3; / d w' c+ p" ?9 u6 [5 F" g
unsigned char flag,flag_1=0; 4 R% L/ G# P" \# J& k7 M5 n
unsigned char high_time,low_time,count=0;//占空比调节参数 & n) l$ R6 J ^2 L7 @2 n7 ]3 n' v
unsigned char set_temper=35; 4 \: l7 t' B! z
unsigned char temper; * W$ @& X& Q) v! L
unsigned char i; # I6 j8 V9 S# l8 p# @# [$ ^
unsigned char j=0; , i7 t0 m" b5 V1 Y/ [
unsigned int s; 4 H0 r) N: t% y5 c2 v* d
/*********************************************************** ( D9 S3 f; n% N1 ]9 n
延时子程序,延时时间以12M晶振为准,延时时间为30us×time ) J7 j$ W3 L9 z: }
***********************************************************/ / \; b6 x4 A2 G5 H/ Y2 y7 [9 I
void delay(unsigned char time) 3 R: [' S5 d- b" l" Z/ O
{
5 R2 q* c# s! f8 h7 h K2 Sunsigned char m,n; 6 n j2 s$ m. r/ i! t+ _
for(n=0;n<time;n++)
+ { [4 Y* v6 _* `8 q- d3 Rfor(m=0;m<2;m++){} : o/ s& E' Z1 x# r/ l4 C
} + _3 |: [5 H, @$ B
/***********************************************************
+ e. ?/ N' k; a! |& v( X7 F写一位数据子程序 $ r( t5 z* S t' m8 |" c$ t, }
***********************************************************/
0 Y; ~ M( B. j0 O& N% t! Y& A. Q3 j) Y2 m$ P
4 M- R8 [# e0 W/ o" R |
|