2022年模糊PID控制温控系统设计方案C语言程序代码.docx
《2022年模糊PID控制温控系统设计方案C语言程序代码.docx》由会员分享,可在线阅读,更多相关《2022年模糊PID控制温控系统设计方案C语言程序代码.docx(22页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、精品学习资源/*模糊 PID 掌握温控系统仿真设计 C 程序代码*/ #include#define uchar unsigned char#define uint unsigned int #define PULSE 200#define number 0.035sbit SDO = P20;sbit SDI = P21;sbit CS = P22;sbit CLK = P23 ;sbit EOC = P24;sbit RS = P25;sbit RW = P26;sbit EN = P27;sbit KEY1= P30 ;sbit KEY2= P31 ;sbit KEY3= P32 ;sb
2、it KEY4= P33 ;sbit KEY5= P34 ;sbit IN1 = P35;sbit IN2 = P36;sbit ENA = P37;uchar flag;uchar flag_start;float S_temp=60.0;float P_temp=20.0;float Kp ;float Ki ;float Kd ; float Err=0.0;float Last_Err=0.0;float D_Err=0.0 ;float Sum_Err=0.0;float U=0.0;/*函数功能:延时*/ void delay_msuchar z欢迎下载精品学习资源uchar i;
3、uchar j;fori=z ;i0;i- forj=360;j0;j- ;void delay_usuchar zuchar i;fori=z ;i0;i- ;void LCD_WriteDatauchar DatRS = 1;P1 = Dat;delay_us10;EN = 1;delay_us10;EN = 0;void LCD_WriteCOMuchar comRS = 0;P1 = com;delay_us10;EN = 1;delay_us10;EN = 0;void Show_Numuchar x,uchar y,uchar n,float numuchar a3;uchar i
4、;uint Temp;Temp=intnum;fori=0 ;i0;i- LCD_WriteDataai-1+0x30 ;void Show_Kiuchar num_Kiuchar Temp;num_Ki=Ki*100 ;Temp=ucharnum_Ki;Show_Num10,2,1,Temp%10;Temp=Temp/10;Show_Num9,2,1,Temp%10;Temp=Temp/10;Show_Num7,2,1,Temp;void Show_charuchar x,uchar y,uchar chify%2 = 1LCD_WriteCOM0x80+x ;elseLCD_WriteCO
5、M0x80+0x40+x ;LCD_WriteDatach;void LCD_InitvoidRW = 0;EN = 0;LCD_WriteCOM0x38 ;LCD_WriteCOM0x0c ;LCD_WriteCOM0x06 ;LCD_WriteCOM0x01 ;/*函数功能:显示函数*/ void LCD_displayvoidShow_char1,1,T;delay_us10;欢迎下载精品学习资源Show_char0,1,P;delay_us10;Show_char1,1,T;delay_us10;Show_char2,1,:;delay_us10;Show_Num3,1,3,P_tem
6、p;delay_us10;Show_char10,1,S;delay_us10;Show_char11,1,T;delay_us10;Show_char12,1,:;delay_us10;Show_Num13,1,3,S_temp;delay_us10;Show_char0,2,P;delay_us10;Show_char1,2,:;delay_us10;Show_Num2,2,2,Kp;delay_us10;Show_char5,2,I;delay_us10;Show_char6,2,:;delay_us10;Show_char8,2,.;delay_us10; Show_KiKi ;del
7、ay_us10;Show_char12,2,D;delay_us10;Show_char13,2,:;delay_us10;Show_Num14,2,2,Kd;delay_us10;/*函数功能:定时器 2 初始化*/ void Timer2_InitRCAP2H =65536-300/256;欢迎下载精品学习资源RCAP2L =65536-300%256;TH2 = RCAP2H;TL2 = RCAP2L ;ET2 = 1;TR2 = 1;EA = 1;/*函数功能:键盘扫描,调整设置温度*/ void key_scanvoidifKEY1=0delay_ms1;ifKEY1=0S_temp
8、=S_temp+1;ifS_temp=200S_temp=200;while.KEY1 ;ifKEY2=0delay_ms1;ifKEY2=0ifS_temp0S_temp=S_temp-1;else ifS_temp=0S_temp=0;while.KEY2 ;ifKEY3=0delay_ms1;ifKEY3=0ifS_temp=10S_temp=S_temp-10;while.KEY4 ;ifKEY5=0delay_ms1;ifKEY5=0flag_start=1;while.KEY5 ;/*函数功能: PID 的运算*/ void PID_CalculateErr = S_temp -
9、P_temp;Sum_Err += Err;D_Err = Err - Last_Err;Last_Err = Err;U=Kp*Err+Ki*Sum_Err+Kd*D_Err;U=intU ;ifU=0欢迎下载精品学习资源elseifU=200U=200;flag=1;U=-U ;ifU=200U=200;欢迎下载精品学习资源flag=0;/*函数功能: PID 参数 Kp 的运算*/float fuzzy_kpfloat e, float ec/e,ec,表示误差,误差变化率欢迎下载精品学习资源糊论域属程度float Kp_calcu;uchar num,pe,pec;float code
10、 eRule7=-3.0,-2.0,-1.0,0.0,1.0,2.0,3.0; /误差 E 的模糊论域float code ecRule7=-3.0,-2.0,-1.0,0.0,1.0,2.0,3.0; / 误差变化率 EC 的模float eFuzzy2=0.0,0.0 ;/隶属于误差E 的隶float ecFuzzy2=0.0,0.0 ;/隶属于误差变化率 EC 的隶属程度float code kpRule4=0.0,8.0,16.0,24.0 ;/Kp 的模糊子集float KpFuzzy4=0.0,0.0,0.0,0.0 ;/ 隶 属 于欢迎下载精品学习资源Kp 的隶属程度int co
11、de KpRule77=/Kp 的模糊掌握表3,3,3,3,3,3,3,2,2,2,2,1,2,2,1,1,1,1,1,1,1,1,1,0,1,0,1,1,0,0,1,0,0,1,0,0,1,0,1,0,0,2,3,3,3,3,3,3,3 ;/*误差 E 隶属函数描述 */ ifeeRule0eFuzzy0 =1.0;pe = 0;else ifeRule0=e & eeRule1eFuzzy0 = eRule1-e/eRule1-eRule0 ;pe = 0;else ifeRule1=e & eeRule2欢迎下载精品学习资源eFuzzy0 = eRule2 -e/eRule2-eRule
12、1 ;pe = 1;else ifeRule2=e & eeRule3eFuzzy0 = eRule3 -e/eRule3-eRule2 ;pe = 2;else ifeRule3=e & eeRule4eFuzzy0 = eRule4-e/eRule4-eRule3 ;pe = 3;else ifeRule4=e & eeRule5eFuzzy0 = eRule5-e/eRule5-eRule4 ;pe = 4;else ifeRule5=e & eeRule6欢迎下载精品学习资源elseeFuzzy0 = eRule6-e/eRule6-eRule5 ;pe = 5;eFuzzy0 =0.
13、0;pe =5;欢迎下载精品学习资源eFuzzy1 =1.0 - eFuzzy0;/*误差变化率 EC 隶属函数描述 */ ifececRule0ecFuzzy0 =1.0;pec = 0;else ifecRule0=ec & ececRule1ecFuzzy0 = ecRule1 - ec/ecRule1-ecRule0;pec = 0 ;else ifecRule1=ec & ececRule2ecFuzzy0 = ecRule2 - ec/ecRule2-ecRule1;pec = 1;欢迎下载精品学习资源else ifecRule2=ec & ececRule3ecFuzzy0 =
14、ecRule3 - ec/ecRule3-ecRule2;pec = 2 ;else ifecRule3=ec & ececRule4ecFuzzy0 = ecRule4-ec/ecRule4-ecRule3 ;pec=3;else ifecRule4=ec & ececRule5ecFuzzy0 = ecRule5-ec/ecRule5-ecRule4 ;pec=4;else ifecRule5=ec & ececRule6ecFuzzy0 = ecRule6-ec/ecRule6-ecRule5 ;pec=5;欢迎下载精品学习资源elseecFuzzy0 =0.0;pec = 5;欢迎下载
15、精品学习资源ule2ecFuzzy1 = 1.0 - ecFuzzy0;/*查询模糊规章表 */ num =KpRulepepec;KpFuzzynum += eFuzzy0*ecFuzzy0 ;num =KpRulepepec+1;KpFuzzynum += eFuzzy0*ecFuzzy1 ;num =KpRulepe+1pec;KpFuzzynum += eFuzzy1*ecFuzzy0 ;num =KpRulepe+1pec+1 ;KpFuzzynum += eFuzzy1*ecFuzzy1 ;/*加权平均法解模糊*/ Kp_calcu=KpFuzzy0*kpRule0+KpFuzzy
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 2022 模糊 PID 控制 温控 系统 设计方案 语言 程序代码
限制150内