您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 质量控制/管理 > 基于AT89C51单片机设计的pid算法的加热炉(含protues仿真图)
基于AT89C51单片机设计的pid算法的加热炉(含protues仿真图)#includereg52.h#includePID.h#includelcd1602.h#includeadc0809.hsbitup=P2^4;sbitdown=P2^5;uchars_xian1[]={Settemp:C};uchars_xian2[]={Reltemp:C};ucharvalue;ucharset_temp=200,rel_temp;//设定值和测量值voiddelay_ms(ucharms){uchari,j;for(i=0;ims;i++)for(j=0;j120;j++);}voidkey_up_down(){if(up==0)delay_ms(1);if(up==0)set_temp++;while(!up);if(down==0)delay_ms(1);if(down==0)set_temp--;while(!down);s_xian1[9]=set_temp/100+0x30;s_xian1[10]=(set_temp%100)/10+0x30;s_xian1[11]=(set_temp%100)%10+0x30;}voidmain(){lcd_init();while(1){key_up_down();rel_temp=adc0809();PID(set_temp,rel_temp);write_com(0x80);display(s_xian1);write_com(0xc0);display(s_xian2);}}#includereg52.h#includeadc0809.hucharmeasure,table[3];ucharvoltage;externuchars_xian2[];voiddelay1(){uchari=50;while(i--);}voidadc_init(){start=1;delay1();start=0;while(EOC==0);delay1();voltage=P1;}ucharadc0809(){uchardat,t;adc_init();dat=voltage*300.0/255;table[0]=dat/100;t=dat%100;table[1]=t/10;table[2]=t%10;s_xian2[9]=table[0]+'0';s_xian2[10]=table[1]+'0';s_xian2[11]=table[2]+'0';measure=table[0]*100+table[1]*10+table[2];returnmeasure;}#includereg52.h#includeintrins.h#includePID.h#defineDA_dataP3sbitDA_wr1=P2^3;ucharuk;voidDAC0832();voidPID_control(ucharset,ucharrel);voidPID(ucharset,ucharrel){ucharD_value=0;//设定值与实际值的差值if(setrel){D_value=set-rel;if(D_value20)uk=255;elsePID_control(set,rel);}else{D_value=rel-set;if(D_value10)uk=10;elsePID_control(set,rel);}DAC0832();}voidPID_control(ucharset,ucharrel){ucharKp=200,Ki=3,Kd=5;chare2=0,e1=0,e0=0;uintu0=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;}voidDAC0832(){DA_wr1=1;DA_data=uk;DA_wr1=0;_nop_();_nop_();_nop_();_nop_();DA_wr1=1;}#includereg52.h#includelcd1602.hvoiddelay(uchari){ucharj,m;for(j=0;j=i;j++)for(m=0;m100;m++);}voidwrite_com(ucharcom){rs=0;rw=0;P0=com;delay(5);e=1;delay(5);e=0;}voidwrite_data(uchardate){rs=1;rw=0;P0=date;delay(5);e=1;delay(5);e=0;}voidlcd_init(){e=0;write_com(0x38);write_com(0x06);write_com(0x0c);write_com(0x01);}voiddisplay(uchar*s){uchari;for(i=0;*s!=0;i++){write_data(*s);s++;}}
本文标题:基于AT89C51单片机设计的pid算法的加热炉(含protues仿真图)
链接地址:https://www.777doc.com/doc-2568445 .html