#i nclude <GLOBAL.h>
#i nclude <stdlib.h>
#i nclude <stdbool.h>
#i nclude <msp430x41x.h>//*========================================================
#define PulseOne BIT0
#define PulseTwo BIT1
#define PulseOneSt P2IN & BIT0
#define PulseTwoSt P2IN & BIT1
#define PulsePowerOut P6DIR |= BIT3;
#define PulsePowerHig P6OUT |= BIT3;
#define PulseOneDirIn P2DIR &= ~BIT0
#define PulseTwoDinIn P2DIR &= ~BIT1
//*参数定义:
//*========================================================
void PulseInit(void)
{
PulseOneDirIn;
PulseTwoDinIn;
PulsePowerOut;
PulsePowerHig;
P2IE = 0;
P2IES = 0;
P2IE |= PulseOne;
P2IES |= PulseOne;
P2IE |= PulseTwo;
P2IES |= PulseTwo;
}
void DataComper(void)
{
DptrDecData(AddsBuy,Overal,Residual);//---累计购买量-累计使用量=剩余量
if(DataThr>0)
{
//---检查是否到了关阀报警量
DptrDecData(Residual,BaoJing,GloBuf);//---剩余量-报警量
if(DataThr==0)
{
ShowBuy=1;
if(!ClosValveJgEn)
{
MotoStr(0);//-----------------------------------------------关阀
ClosValveJgEn=1;
}
else
{
MotoStr(1);//--------------------------------------------------开阀
}
}
else
{
if(!DisturbFg)
{
MotoStr(1);//--------------------------------------------------开阀
}
ShowBuy=0;
ClosValveJgEn=0;
}
OverdraftSt=0;
MeterSt[0]&=0xfe;
}
else
{
//---过零关阀
DptrDecData(Overal,AddsBuy,OverData); //---累计使用量-累计购买量=透支量
MotoStr(0);//--------------------------------------------------关阀
OverdraftSt=1;
ShowBuy=1;
MeterSt[0]|=0x01;
}
}
void PulseAdd(void)
{
if(SecondsConn&0x01)
{
if(!(PulseOneSt&BIT0))
{
if(PulseOneTimes<5)
{
PulseOneTimes++;
if(PulseOneTimes>2)
{
PulseOneEn=1;
}
}
}
else
{
PulseOneTimes=0;
}
if(!(PulseTwoSt&BIT1))
{
if(PulseTwoTimes<5)
{
PulseTwoTimes++;
if(PulseTwoTimes>2)
{
PulseTwoEn=1;
}
}
}
else
{
PulseTwoTimes=0;
}
if((PulseOneEn==1)&(PulseTwoEn==1))
{
if(!DisturbFg)
{
Overal[0]=Overal[0]>>4;
Overal[0]++;
if(Overal[0]>=10)
{
Overal[0]=0;
DataAddup(&Overal[1],3);
ComperEn=1;
DataComper();
DataSave();
}
Overal[0]=Overal[0]<<4;
PulseOneEn=0;
PulseTwoEn=0;
PulseAddEn=0;
}
}
SecondsConn&=0xfe;
}
}
#pragma vector=PORT2_VECTOR
__interrupt void P2ISR(void)
{
if(P2IFG&BIT0)
{
LPM4_EXIT;
BasicTimer=75;
}
if(P2IFG&BIT1)
{
LPM4_EXIT;
BasicTimer=75;
}
P2IFG = 0;
} |