温度控制pid c语言程序,51单片机温度PID算法(C程序)

本文介绍了一个使用C语言编程的51单片机温度PID控制程序,包括PID控制器结构、数据类型定义、占空比调节参数、温度读取、PID算法计算等功能。通过设置目标温度和实时读取温度,实现对温度的精确控制。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#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 Response (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 set_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;

}

void write_byte(unsigned char val)

{

unsigned char i;

unsigned char temp;

EA=0;

TR0=0;

for(i=0;i<8;i++)

{ <

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值