完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
|
#include #include #include #include #define uchar unsigned char #define uint unsigned int ***it DATA = P1^1; //DS18B20接入口 uchar code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};//共阴极字型码 int temp; //温度值 int ss; //中间的一个变量 int dd; int j; uchar data b;//定时器中断次数 uchar data buf[4];//字型显示中间变量 int alarmH=400; //默认报警值 int alarmL=-500; //定义开关的接入口 ***it k1=P2^5;//+ ***it k2=P2^6;//- ***it k3=P2^7;//确认 ***it bell=P1^0;
***it Red=P1^6; //nouse ***it output=P3^5; unsigned int s; unsigned char high_time,low_time,count=0; bit set=0; bit Flag=0; int n; unsigned char set_temp; 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; // the control PID unsigned int rout;//the reaction of PID unsigned int rin;//the feedback of PID //函数的声明区 void key_to1(); //键盘++ void key_to2(); //键盘-- void delay(uint); //延时 void key(); //按键扫描子程序 void Show(); //显示 //函数的定义区 /*延时子函数*/ void delay(uint num) { while(num--) ; void Show() { if(temp>=0) display();//显示函数 if(temp<0) display00(); } void PIDInit(struct PID *pp) //jie gou bian liang chu shi hua { memset(pp,0,sizeof(struct PID)); }
unsigned int PIDCalc( struct PID *pp, unsigned int NextPoint ) { unsigned int dError,Error; Error=pp->SetPoint-NextPoint; // 偏差EK,设定值减去当前采样值 pp->SumError+=Error; // 积分,历史偏差累加 dError=pp->LastError-pp->PrevError; // 当前微分,偏差相减 pp->PrevError=pp->LastError; pp->LastError=Error; return (pp->Proportion * Error // 比例项 + pp->Integral * pp->SumError // 积分项 + pp->Derivative * dError); // 微分项 } compare_temper() { unsigned char i; if(set_temp>temp) { if(set_temp-temp>1) { high_time=100; low_time=0; } else { for(i=0;i<10;i++) { int ReadTemperature(); rin=s; rout=PIDCalc(&spid,rin); } if( high_time<=100) high_time=(unsigned char)(rout/800); else high_time=100; low_time=(100-high_time); } } else if(set_temp<=temp) { if(temp-set_temp>1) { high_time=0; low_time=100; } else { for(i=0;i<10;i++) { int ReadTemperature(); rin=s; rout=PIDCalc( &spid, rin ); } if(high_time<100) high_time=(unsigned char) (rout/10000); else high_time=0; low_time=(100-high_time); } } }
void main() { TCON=0x01; TMOD=0X01; TH0=(65536-5000)/256; TL0=(65536-5000)%256; EA=1; ET0=1; TR0=1; EX0=1;
for(n=0;n<500;n++)//显示启动LOGo"- - - -" {bell=0;logo();} Red=0; while(1) { key(); ss=ReadTemperature(); Show(); alarm(); if(Flag==1) {bell=!bell;} //蜂鸣器滴滴响 else {bell=0;} } } void sever_T1() interrupt 1 using 1 //control the turn of electict { if(++count<=(high_time)) output=1; else if(count<=100) { output=0; } else count=0; TH0=0X2f; TL0=0Xe0; }
void time0(void) interrupt 1 using 1 //每隔10ms执行一次此子程序 { TH0=(65536-5000)/256; TL0=(65536-5000)%256; temp=ss; }
|
|
相关推荐
1个回答
|
|
|
谢谢楼主的分享学习了
|
|
|
|
|
你正在撰写答案
如果你是对答案或其他答案精选点评或询问,请使用“评论”功能。
651 浏览 0 评论
712 浏览 0 评论
STM32F405驱动DS1302时钟模块,输出时间错乱该怎么排查?
4375 浏览 2 评论
stm32f405rgt6驱动DS1302ZN出现时间错乱问题
3176 浏览 1 评论
stm32用fsmc读取ad7606采集数据,数据不变,只有开发版复位才更新数据
2629 浏览 0 评论
/9
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2025-12-9 23:57 , Processed in 0.882140 second(s), Total 73, Slave 53 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191

淘帖
5004