#include "reg51.h"
#include "intrins.h"
#include "math.h"
#include "string.h"
struct PID
{
unsigned int SetPoint; // 设定目标 Desired Value
unsigned int Proportion; // 比例常数 Proportional Const
unsigned int Integral; // 积分常数 Integral Const
unsigned int Derivative; // 微分常数 Derivative Const
unsigned int LastError; // Error[-1]
unsigned int PrevError; // Error[-2]
unsigned int SumError; // Sums of Errors
};
struct PID spid; // PID Control Structure
unsigned int rout; // PID Respon (Output)
unsigned int rin; // PID Feedback (Input)
sbit data1=P1^0;
sbit clk=P1^1;
sbit plus=P2^0;
sbit subs=P2^1;
sbit stop=P2^2;
sbit output=P3^4;
sbit DQ=P3^3;
unsigned char flag,flag_1=0;
unsigned char high_time,low_time,count=0;//占空比调节参数
unsigned char t_temper=25;
unsigned char temper;
unsigned char i;
unsigned char j=0;
unsigned int s;
void delay(unsigned char time)
{
unsigned char m,n;
for(n=0;n
for(m=0;m<2;m++){}
} 在线词典
void write_bit(unsigned char bitval)
{
EA=0;
DQ=0;
if(bitval==1)
电子信息工程就业{
_nop_();
DQ=1;
}
delay(5);
DQ=1;
_nop_();
_nop_();
EA=1;
}
practid
void write_byte(unsigned char val)
{
unsigned char i;
unsigned char temp;
EA=0;
TR0=0;
for(i=0;i<8;i++)
{
temp=val>>i;
temp=temp&1;
write_bit(temp);
}
delay(7);
// TR0=1;
EA=1;
}
unsigned char read_bit()
{
unsigned char i,value_bit;
EA=0;
DQ=0;
_nop_();
_nop_();
DQ=1;
for(i=0;i<2;i++){}
value_bit=DQ;
EA=1;
return(value_bit);
}
unsigned char read_byte()
{
unsigned char i,value=0;
EA=0;
for(i=0;i<8;i++)
{
if(read_bit())
value|=0x01<<i;
delay(4);
}
EA=1;
return(value);
}
unsigned char ret()
{
unsigned char prence;
EA=0;
DQ=0;
delay(30);
DQ=1;
delay(3);
prence=DQ;
delay(28);
EA=1;
return(prence);
}
void get_temper()
{
unsigned char i,j;
do
{
i=ret();
} while(i!=0);
i=0xcc;
write_byte(i);
i=0x44;
hitandrunwrite_byte(i);
delay(180);
do
{
i=ret();
} while(i!=0);
i=0xcc;
write_byte(i);
i=0xbe;
write_byte(i);
j=read_byte();
i=read_byte();
i=(i<<4)&0x7f;
s=(unsigned int)(j&0x0f); //得到小数部分
s=(s*100)/16;
j=j>>4;
temper=i|j;
}
void PIDInit (struct PID *pp)
{
memt ( pp,0,sizeof(struct PID)); //全部初始化为0
}
unsigned int PIDCalc( struct PID *pp, unsigned int NextPoint )
{
unsigned int dError,Error;
Error = pp->SetPoint - NextPoint; // 偏差
pp->SumError += Error; // 积分
dError = pp->LastError - pp->PrevError; // 当前微分
pp->PrevError = pp->LastError;
pp->LastError = Error;
return (pp->Proportion * Error // 比例项
netdb
+ pp->Integral * pp->SumError // 积分项
好朋友的英文
+ pp->Derivative * dError); // 微分项
}
void compare_temper()
{
unsigned char i;
if(t_temper>temper) //是否设置的温度大于实际温度
{
if(t_temper-temper>1) //设置的温度比实际的温度是否是大于1度
{
high_time=100; //如果是,则全速加热
low_time=0;
}
el //如果是在1度范围内,则运行PID计算
{
for(i=0;i<10;i++)
{
get_temper(); //获取温度
mamirin = s; // Read Input
rout = PIDCalc ( &spid,rin ); // Perform PID Interation
}
if (high_time<=100)
high_time=(unsigned char)(rout/800);
el
high_time=100;
low_time= (100-high_time);
}
}
el if(t_temper<=temper)
{
if(temper-t_temper>0)
{
high_time=0;
low_time=100;
}
el
{
for(i=0;i<10;i++)
英文歌曲大全{
get_temper();
rin = s; // Read Input
rout = PIDCalc ( &spid,rin ); // Perform PID Interation
}
if (high_time<100)
high_time=(unsigned char)(rout/10000);
el
high_time=0;
low_time= (100-high_time);
}
}
halfpipe
// el
// {}
}
void rve_T0() interrupt 1 using 1