/****
*******外部中断0初始化函数
*****/
void Exter0_Init(void)
{
	EA = 1;					//打开总中断
	EX0 = 1;				//打开外部中断
	IT0 = 1;				//下降沿触发
}

 

/****
*******	外部中断0服务函数 
*****/
void Exter0_Handler(void) interrupt 0
{
	pulse_num++;
	if(relay == 0)
	water_all+=0.00303;  						//1L水输出330个脉冲,每个脉冲是1/330=0.00303 L的水 
}

 

if(relay == 0)
		{
			if(time_1s == 1)
			{
				water_flow = pulse_num/5.5;			//单位L/min  瞬时水流量
				pulse_num = 0;
				time_1s = 0;
			}
		}

 

float flow_value = 0;									//瞬时流量
float flow_all = 0;


if(flag_5s == 1)														//5秒到达
			{
				flag_5s = 0;
				flow_value = pulse_num / 5.5 / 5.0;				//计算瞬时流量
				pulse_num = 0;
				flow_all += flow_value / 12.0;						//计算总计流量
			}

 

 

发表回复

后才能评论