TA的每日心情  | 开心 2023-5-30 15:22 | 
|---|
 
  签到天数: 1 天 [LV.1]初来乍到  
 | 
	
    
 
EDA365欢迎您登录!
您需要 登录 才可以下载或查看,没有帐号?注册  
 
x
 
//PID算法温控C语言2008-08-17 18:58, [% j$ f7 Z: A/ I4 V 
#include<w77e58.h>  
  L( ?$ j! ^! h& B* c: p7 ?#include<intrins.h> 6 _. p# V6 E7 K1 O 
#include<math.h> 5 S5 p2 c$ l6 d 
#include<string.h>  
) C& Z8 A: V. G/ Sstruct PID {  
8 \# K- Y- Y+ N" _# Runsigned int SetPoint; // 设定目标 Desired Value  
) R8 x6 y- P; Q/ s( _- C# U# ~unsigned int Proportion; // 比例常数 Proportional Const ) [/ W4 ~6 n: n6 u6 h$ {9 ?9 K 
unsigned int Integral; // 积分常数 Integral Const  
: H" ]/ Q6 p" D3 Z- ?- p7 F" Bunsigned int Derivative; // 微分常数 Derivative Const : e5 c0 B" [& r 
unsigned int LastError; // Error[-1] : X' e& K1 W! A0 e9 N/ O- @ 
unsigned int PrevError; // Error[-2]  
: i; t& B# V( r) W* m0 Q6 Wunsigned int SumError; // Sums of Errors - n0 {# }3 _3 W3 O& p1 Q" X2 G8 t5 } 
}; ) w  ]; [* q" j- \/ i8 X" f 
struct PID spid; // PID Control Structure  
/ h# i2 y3 C7 Y) l0 ^; yunsigned int rout; // PID Response (Output)  
" V+ ~5 C% P% ~2 J/ runsigned int rin; // PID Feedback (Input)  
3 d/ Y# m1 E0 X! B5 E3 d4 esbit data1=P1^0;  
. R2 `* I; g9 R& T* zsbit clk=P1^1;  
) q  X7 b; F* m. l9 T& Qsbit plus=P2^0; 0 T+ X" k( b! I- l2 I 
sbit subs=P2^1;  
$ @2 r9 k3 _( z& k! _sbit stop=P2^2; 3 q1 Y0 r- {) }0 b 
sbit output=P3^4;  
5 E  _/ U! b5 E9 Ksbit DQ=P3^3; ! b( y$ y  Y& I( @ 
unsigned char flag,flag_1=0;  
* K0 d* `& m$ K1 w; xunsigned char high_time,low_time,count=0;//占空比调节参数 & {9 ?2 n, z' _. I! l2 z 
unsigned char set_temper=35; # B7 m* X( ?- W- A 
unsigned char temper; , F5 i  Z  \; ~  a/ S6 J* z 
unsigned char i; 8 R- w' \/ H$ l4 Q- Y 
unsigned char j=0;  
% t5 T" ?% B8 i, |  lunsigned int s;  
; H$ k. n" w9 T% r, V6 b8 G/***********************************************************  
( ]# [" C/ W% M: g延时子程序,延时时间以12M晶振为准,延时时间为30us×time ( p( }$ Z$ B; X' a 
***********************************************************/  
& Z* Y/ Y/ |, \. d# ~void delay(unsigned char time)  
( u2 y9 `9 s5 H  Y% F5 S* `{ 4 n4 b  |4 l: X8 j  ]* u 
unsigned char m,n;  
/ [" M4 c1 A7 w+ r4 y0 D0 E: Sfor(n=0;n<time;n++)  
; p0 l. d/ \1 _5 X) {for(m=0;m<2;m++){}  
+ g! t* ]( ?. j, U' Y7 {% w5 `' x- S}  
& [& m7 B! ~8 ~5 _/*********************************************************** ; b6 o6 q! w. u 
写一位数据子程序  
5 r5 g( n6 A, v" x' T***********************************************************/  
6 p+ G* y# B1 A 
6 m) Z/ K! d; ~& w 
; Y) V  J& E1 z |   
 
 
 
 |