整理自动控制鱼缸电路图Word文件下载.docx
《整理自动控制鱼缸电路图Word文件下载.docx》由会员分享,可在线阅读,更多相关《整理自动控制鱼缸电路图Word文件下载.docx(28页珍藏版)》请在冰豆网上搜索。
floattmp_new=0;
floattmp_old=0;
uchartmp_set1=30;
uchartmp_set2=35;
floattmp_set=50;
floatCtrl_P=0.8;
floatPWM=0;
floatcnt=0;
//喂食、光照、氧循环相关参量
uintFeedInterval=30;
//喂食间隔时间
uintFeedTime=10;
//喂食时间
uintOxygenInterval=30;
uintOxygenTime=10;
uintLightInterval=30;
uintLightTime=10;
uintFeedInterval_cnt;
uintFeedTime_cnt;
uintOxygenInterval_cnt;
uintOxygenTime_cnt;
uintLightInterval_cnt;
uintLightTime_cnt;
ucharTime_cnt=0;
//设定参数相关变量
ucharSetTimeFlg=0;
ucharSetTempFlg=0;
ucharSetFeedFlg=0;
ucharSetOxygenFlg=0;
ucharSetLightFlg=0;
ucharFeedFlg=0;
ucharOxygenFlg=0;
ucharLightFlg=0;
uchardata_zancun=0;
ucharTestNum=0;
voidInit_timer(void)
{
RCAP2H=(65536-38400)/256;
RCAP2L=(65536-38400)%256;
TH2=RCAP2H;
TL2=RCAP2L;
T2CON=0;
T2MOD=0;
ET2=1;
TR2=1;
EA=1;
}
voidZhengzhuan(void)
{
uchari;
for(i=0;
i〈128;
i++)
{
IN1=0;
IN2=1;
IN3=1;
IN4=1;
delay1ms
(1);
IN2=0;
delay1ms
(1);
IN1=1;
IN3=1;
IN4=1;
IN1=1;
IN3=0;
IN2=1;
IN3=0;
IN4=0;
IN4=0;
IN1=0;
}
voidFanzhuan(void)
uchari;
i<
128;
IN2=0;
}
voidPageClear(void)
write_com(0x80);
i〈16;
write_data(’’);
write_com(0xc0);
for(i=0;
i〈16;
write_data('
’);
}
voidKeyScan(void)
uchartemp;
P2=0xfe;
temp=P2;
temp=temp&0xf0;
if(temp!
=0xf0)
{
delay1ms(10);
temp=P2;
temp=temp&0xf0;
if(temp!
{
switch(temp)
{
case0xe0:
{
//TestNum=0;
data_zancun=0;
PageClear();
SetLightFlg=0;
SetFeedFlg=0;
SetTempFlg=0;
SetOxygenFlg=0;
SetTimeFlg++;
if(SetTimeFlg==7)
SetTimeFlg=1;
}break;
//时间
case0xd0:
TestNum=7;
data_zancun++;
if(data_zancun==3)
data_zancun=1;
//数字键7
case0xb0:
{data_zancun++;
data_zancun=1;
TestNum=4;
}break;
//数字键4
case0x70:
{data_zancun++;
TestNum=1;
//数字键1
}
while(temp!
{
temp=P2;
temp=temp&
0xf0;
}
}
P2=0xfd;
temp=P2;
temp=temp&0xf0;
temp=temp&0xf0;
{
{data_zancun++;
TestNum=0;
}break;
//数字键0
case0xd0:
TestNum=8;
//数字键8
{data_zancun++;
TestNum=5;
}break;
//数字键5
TestNum=2;
//数字键2
}
temp=P2;
0xf0;
}
P2=0xfb;
if(temp!
temp=P2;
if(temp!
case0xe0:
{
//TestNum=8;
SetLightFlg=0;
SetFeedFlg=0;
if(SetTimeFlg!
=0)
{
ds1302set();
SetTimeFlg=0;
}
data_zancun=0;
}break;
//确定键
TestNum=9;
//数字键9
case0xb0:
TestNum=6;
}break;
//数字键6
case0x70:
TestNum=3;
//数字键3
temp=temp&0xf0;
P2=0xf7;
temp=temp&
delay1ms(10);
temp=temp&
//TestNum=12;
PageClear();
SetTempFlg=0;
SetTimeFlg=0;
SetOxygenFlg++;
if(SetOxygenFlg==3)
SetOxygenFlg=1;
//氧气
{//TestNum=13;
data_zancun=0;
SetTimeFlg=0;
SetLightFlg++;
if(SetLightFlg==3)
SetLightFlg=1;
//照明
{//TestNum=14;
SetOxygenFlg=0;
SetFeedFlg++;
if(SetFeedFlg==3)
SetFeedFlg=1;
//喂食
SetTempFlg++;
if(SetTempFlg==3)
SetTempFlg=1;
}break;
//温度
while(temp!
}
if(SetTimeFlg)
switch(SetTimeFlg)
case1:
if(data_zancun==1)
time_date[6]&=0x0f;
time_date[6]|=TestNum<
<
4;
elseif(data_zancun==2)
time_date[6]&=0xf0;
time_date[6]|=TestNum;
}}break;
case2:
time_date[4]&=0x0f;
time_date[4]|=TestNum<
4;
time_date[4]&
=0xf0;
time_date[4]|=TestNum;
}}break;
case3:
time_date[3]&=0x0f;
time_date[3]|=TestNum<
〈4;
time_date[3]&=0xf0;
time_date[3]|=TestNum;
}}break;
case4:
time_date[2]&
=0x0f;
time_date[2]|=TestNum<
time_date[2]&
=0xf0;
time_date[2]|=TestNum;
}}break;
case5:
time_date[1]&
time_date[1]|=TestNum<
time_date[1]|=TestNum;
case6:
time_date[0]&
=0x0f;
time_date[0]|=TestNum<
〈4;
time_date[0]|=TestNum;
}}break;
elseif(SetTempFlg)
switch(SetTempFlg)
tmp_set2=TestNum*10+tmp_set2%10;
tmp_set2=TestNum+10*(tmp_set2/10);
tmp_set1=TestNum*10+tmp_set1%10;
}
tmp_set1=TestNum+10*(tmp_set1/10);
elseif(SetFeedFlg)
switch(SetFeedFlg)
case1:
FeedInterval=TestNum*10+FeedInterval%10;
FeedInterval=TestNum+10*(FeedInterval/10);
}}break;
case2:
FeedTime=TestNum*10+FeedTime%10;
}
FeedTime=TestNum+10*(FeedTime/10);
}}break;
elseif(SetLightFlg)
switch(SetLightFlg)
LightInterval=TestNum*10+LightInterval%10;
LightInterval=TestNum+10*(LightInterval/10);
LightTime=TestNum*10+LightTime%10;
LightTime=TestNum+10*(LightTime/10);
elseif(SetOxygenFlg)
switch(SetOxygenFlg)
OxygenInterval=TestNum*10+OxygenInterval%10;
OxygenInterval=TestNum+10*(OxygenInterval/10);
OxygenTime=TestNum*10+OxygenTime%10;
OxygenTime=TestNum+10*(OxygenTime/10);
}
}
voidMainPage(void)//主界面
tmp_set=(float)(tmp_set1+tmp_set2)/2。
0;
tmp_set+=1。
0;
TR0=0;
tempval=0;
ds1302get();
//读取当前时间
TR2=0;
i〈5;
sendChangeCmd();
tempval+=getTmpValue()/5.0;
TR2=1;
tmp_new=(float)tempval/100。
if(tmp_new—tmp_old〉0.1)
Ctrl_P=0。
5;
elseCtrl_P=0.65;
if(tmp_set-tmp_new>
=3)
PWM=1;
elseif(tmp_set>
tmp_new)
PWM=Ctrl_P*(tmp_set-tmp_new)/3.0;
elsePWM=0;
tmp_old=tmp_new;
TR0=1;
write_com(0x8b);
write_data(tempval/1000+’0'
);
write_data(tempval%1000/100+’0'
write_data(’。
’);
write_data(tempval%100/10+'
0’);
write_data(tempval%10+’0’);
write_data(’0’+((time_date[2]&0xf0)〉〉4));
//显示时
0’+