#i nclude <GLOBAL.h>
#i nclude <stdlib.h>
#i nclude <stdbool.h>
#i nclude <msp430x41x.h>//------------------------------------------------------------------------ValveConTime=0x0f 电机开失控时间
#define MotoConOneOut P6DIR |= BIT1
#define MotoConOneHig P6OUT |= BIT1
#define MotoConOneLow P6OUT &=~ BIT1
#define MotoConTwoOut P6DIR |= BIT2
#define MotoConTwoHig P6OUT |= BIT2
#define MotoConTwoLow P6OUT &=~ BIT2
//------阀门状态检测电源供给
#define ValveStChkPowerDirOut P6DIR |= BIT0
#define ValveStChkPowerHig P6OUT |= BIT0
#define ValveStChkPowerLow P6OUT &=~ BIT0
//------阀门状态
#define ValveStOneIn P1DIR &=~ BIT6
#define ValveStTwoIn P1DIR &=~ BIT7
#define ValveStOne P1IN & BIT6
#define ValveStTwo P1IN & BIT7
void MotoOpen(void)
{
WDT();
MotoConOneHig;
MotoConTwoLow;
}
void MotoClos(void)
{
WDT();
MotoConOneLow;
MotoConTwoHig;
}
void ValveInit(void)
{
MotoConEn=0;
MotoClosEn=0;
MotoOpenEn=0;
MotoConOneLow;
MotoConTwoLow;
ValveStChkPowerDirOut;
ValveStChkPowerLow;
}
void MotoInit(void)
{
ValveInit();
MotoConOneOut;
MotoConOneLow;
MotoConTwoOut;
MotoConTwoLow;
}
void ValveStChk(void)
{
ValveStChkPowerHig;
ValveStOneIn;
ValveStTwoIn;
ValveOpenSt=0;
ValveClosSt=0;
WDT();
Delay(3000);
ValveErrSt=0;//
if(ValveStOne&BIT6)
{
if(ValveStTwo&BIT7)//两者都是高---错误
{
ValveErrSt=1;//------------错误状态
}
else
{
ValveClosSt=1;
}
}
else
{
if(ValveStTwo&BIT7)
{
ValveOpenSt=1;//-------------阀门开
}
else//两者都是低---错误
{
ValveErrSt=1;//------------阀门错误
}
}
ValveStChkPowerLow;
}
void MotoStop(void)
{
WDT();
SleepEn=1;
MotoConEn=0;
MotoClosEn=0;
MotoOpenEn=0;
MotoConOneLow;
MotoConTwoLow;
MeterSt[0]&=0xfc;//--------错误状态
if(ValveConTimes!=0)
{
MeterSt[0]&=0xfd;
if(ValveOpenSt)
{
MeterSt[0]|=0x01;//---阀门开
}
}
else
{
MeterSt[0]|=0x02;//--------错误状态
}
ValveConTimes=0;
PowerLowTimer=60;
}
//---void MotoStr(bool MotoSt)--------------------------------------------------
//---功能描述:-
//---输入条件:-MotoSt=1,执行开阀动作否则执行关阀动作。
//---输出项目:-无。
void MotoStr(bool MotoSt)
{
if(MotoSt)
{
MotoOpenEn=1;
MotoClosEn=0;
}
else
{
MotoOpenEn=0;
MotoClosEn=1;
}
SleepEn=0;
MotoConEn=1;
ValveConTimes=15;
}
void ValveCon(void)
{
if(MotoConEn)
{
if(ValveConTimes!=0)
{
ValveStChk();
if(MotoOpenEn)//------------------------------------------开阀动作
{
if(PowerLowFg|OverdraftSt|DisturbFg)//---如果低压,透支,干扰,禁止开阀
{
if(ValveClosSt)
{
MotoStop();
}
else
{
MotoClos();//-------------------------------------------关阀
}
}
else
{
if(ValveOpenSt)
{
MotoStop();
}
else
{
MotoOpen();
}
}
}
else
{
if(MotoClosEn)//--------------------------------------关阀动作
{
if(ValveClosSt)
{
MotoStop();
}
else
{
MotoClos();
}
}
}
}
else
{
MotoStop();
}
}
if(SecondsConn&0x08)
{
if(ValveConTimes!=0)
{
ValveConTimes--;
}
SecondsConn&=0xf7;
}
} |