1、 基于 AT89C51 单片机设计的 pid 算法的 加热炉 (含 protues 仿真图)#include #include “PID.h“#include “lcd1602.h“#include “adc0809.h“sbit up =P24;sbit down=P25;uchar s_xian1= “Set temp: C“;uchar s_xian2= “Rel temp: C“;uchar value;uchar set_temp=200,rel_temp; /设定值 和 测量值void delay_ms(uchar ms)uchar i,j;for(i=0;i#include “a
2、dc0809.h“uchar measure,table3;uchar voltage;extern uchar s_xian2;void delay1()uchar i=50;while(i-);void adc_init()start=1;delay1();start=0;while(EOC=0);delay1();voltage=P1;uchar adc0809()uchar dat,t;adc_init();dat=voltage*300.0/255;table0=dat/100;t=dat%100;table1=t/10;table2=t%10;s_xian29 =table0+0;
3、s_xian210=table1+0;s_xian211=table2+0; measure=table0*100+table1*10+table2;return measure;#include #include #include“PID.h“#define DA_data P3sbit DA_wr1=P23;uchar uk;void DAC0832();void PID_control(uchar set,uchar rel);void PID(uchar set,uchar rel)uchar D_value=0; /设定值与实际值的差值if(setrel)D_value=set-re
4、l;if(D_value20)uk=255;elsePID_control(set,rel);elseD_value=rel-set;if(D_value10)uk=10;elsePID_control(set,rel);DAC0832();void PID_control(uchar set,uchar rel)uchar Kp=200,Ki=3,Kd=5;char e2=0,e1=0,e0=0;uint u0=0,u=0;e2=set-rel;u=Kp*(e2-e1)+Ki*e2+Kd*(e2-2e1+e0)+u0;uk=u;e0=e1;e1=e2;u0=u;void DAC0832()
5、DA_wr1=1;DA_data=uk;DA_wr1=0;_nop_();_nop_();_nop_();_nop_();DA_wr1=1;#include#include“lcd1602.h“void delay(uchar i)uchar j,m;for(j=0;j=i;j+)for(m=0;m100;m+);void write_com(uchar com)rs=0;rw=0;P0=com;delay(5);e=1;delay(5);e=0;void write_data(uchar date)rs=1;rw=0;P0=date;delay(5);e=1;delay(5);e=0;void lcd_init() e=0;write_com(0x38);write_com(0x06);write_com(0x0c); write_com(0x01);void display(uchar *s)uchar i;for(i=0;*s!=0;i+)write_data(*s);s+;