⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wiper.c

📁 车载雨刮器控制程序由CW环境开发已调试通过,实现间歇时间受控,喷水自动刮水功能
💻 C
📖 第 1 页 / 共 2 页
字号:
		}
		
		if(delay_ms_count == 0)
		{
			O_WIPER_RLY = 1;

			if(!delay400ms_flag)
			{
				wiper_dly_ms(400);
			}
			
			if(delay_ms_countb == 0)
			{
				O_WIPER_LOW = 1;
				high_check_flg = 0;
				low_check_flg = 1;
				delay2ms_flag = 0;
				delay400ms_flag = 0;
			}
		}
		
		washstop_flag = 0;
		cmd_start_flg = 0;
		int_stop_flg = 0;
		second = 0;
		cnt_wash = 0;
	}

	if((sentido == HIGH_DATA)&&(washstop_flag == 0))
	{
		//高速档启动
		O_NTB22N06 = 1;		// (反极性)急停MOS关闭
		O_WIPER_LOW = 0;
		
		if(!delay2ms_flag)
		{
			wiper_dly_ms(2);
		}
		
		if(delay_ms_count == 0)
		{
			O_WIPER_RLY = 0;		//继电器断开低速线
			
			if(!delay400ms_flag)
			{
				wiper_dly_ms(400);
			}
			
			if(delay_ms_countb == 0)
			{
				O_WIPER_HI = 1;
				high_check_flg = 1;
				low_check_flg = 0;
				delay2ms_flag = 0;
				delay400ms_flag = 0;
				cmd_start_flg = 0;
			}
		}
		
		int_stop_flg = 0;
		second = 0;
	}

	if((sentido == LOW_DATA) && (washstop_flag == 0))
	{
		//低速档启动
		O_NTB22N06 = 1;		// (反极性)急停MOS关闭

		O_WIPER_HI = 0;
		
		if(!delay2ms_flag)
		{
			wiper_dly_ms(2);
		}
		
		if(delay_ms_count == 0)
		{
			O_WIPER_RLY = 1;
			
			if(!delay400ms_flag)
			{
				wiper_dly_ms(400);
			}
			
			if(delay_ms_countb == 0)
			{
				O_WIPER_LOW = 1;
				high_check_flg = 0;
				low_check_flg = 1;
				delay2ms_flag = 0;
				delay400ms_flag = 0;
				cmd_start_flg = 0;
			}
		}
		
		int_stop_flg = 0;
		second = 0;
	}

	if((sentido == INT_DATA) && (!startup_flg) && (int_stop_flg == 0) && (washstop_flag == 0))
	{
		//间歇档启动
		O_NTB22N06 = 1;		// (反极性)急停MOS关闭
		int_on_dly_flg = 1;
		O_WIPER_HI = 0;
		
		if(!delay2ms_flag)
		{
			wiper_dly_ms(2);
		}
		
		if(delay_ms_count == 0)
		{
			O_WIPER_RLY = 1;
			if(!delay400ms_flag)
			{
				wiper_dly_ms(400);
			}
			
			if(delay_ms_countb == 0)
			{
				O_WIPER_LOW = 1;
				high_check_flg = 0;
				low_check_flg = 1;
				delay2ms_flag = 0;
				delay400ms_flag = 0;
				startup_flg = 0;
				cmd_start_flg = 1;
			}
		}
		
		if((I_WIP_PERCH) && (inter_on_delay > 400))
		{
			startup_flg = 1;
			cmd_start_flg = 0;
			int_on_dly_flg = 0;
			delay2ms_flag = 0;
			delay400ms_flag = 0;
		}
		
		int_flag = 1;
		
		if(int_once_flg == 1)
		{
			int_once_flg = 0;
			if((cnt_60s < 60) && (cnt_60s > 1))
			{
				int_cycl = cnt_60s;
			}
		}
		
		cnt_60s = 0;
	}

	if((sentido == STOP_DATA) && (!I_WIP_PERCH))
	{
		//停止档处理
		if(wash_flg == 1)
		{
			if(cnt_wash >= 2)
			{
				sentido3_flag = 0;
				wash_flg = 0;
				cnt_wash = 0;
				cnt_sentido3 = 0;
				wash_cnt_flg = 0;
				wash_time = 0;
			}
		}
		else
		{
			startup_flg = 0;	//when wiper motor reach the self-stop point,the self_stop pin is "0"
			O_WIPER_LOW = 0;
			O_WIPER_HI = 0;
			mos_break_flg = 1;	//TURN ON MOSFET
			int_stop_flg = 0;
			second = 0;
		}
	}

	if(sentido3_flag == 1)
	{
		//喷水档断开后刮水电机继续旋转  互锁
		if((!I_WIP_PERCH)&&(washstop_flag == 0))
		{
			wash_add_flg = 1;
		}
		
		if((I_WIP_PERCH) && (wash_add_flg == 1))
		{
			wash_add_flg = 0;
			cnt_wash++;
		}
	}

//------

	// 故障检测
	if(high_check_flg)
	{
		//high speed channel
		if(out5_is_result < HIGH_THRESHOLD)
		{
			// 雨刷HIGH故障 65 -> 6.1,6.0 = 10
			tx_can_wiper_msg.J1939_MESSAGE_UNION_PART.Data[6] &= 0xfc;
			tx_can_wiper_msg.J1939_MESSAGE_UNION_PART.Data[6] |= 0x02;
		}
		else
		{
			// 雨刷无故障 65 -> 6.1,6.0 = 11
			tx_can_wiper_msg.J1939_MESSAGE_UNION_PART.Data[6] |= 0x03;
		}
	}
	if(low_check_flg)
	{
		//low speed channel
		if(out14_is_result < LOW_THRESHOLD)
		{
			// 雨刷LOW故障 65 -> 6.1,6.0 = 01
			tx_can_wiper_msg.J1939_MESSAGE_UNION_PART.Data[6] &= 0xfc;
			tx_can_wiper_msg.J1939_MESSAGE_UNION_PART.Data[6] |= 0x01;
		}
		else
		{
			// 雨刷无故障 65 -> 6.1,6.0 = 11
			tx_can_wiper_msg.J1939_MESSAGE_UNION_PART.Data[6] |= 0x03;
		}
	}

//------

	if(inttime >= 1000)
	{
		//如到1秒钟 则INTTIME大于400
		second++;
		
		if((sentido == STOP_DATA)&&(wash_flg == 0))
		{
			cnt_60s++;
		}
		
		inttime = 0;
	}

	if(wash_time >= 1000)
	{
		//如到1秒钟 则WASH-TIME大于400
		cnt_sentido3++;
		wash_time = 0;
	}
	
	if(int_stop_flg ==1)
	{
		//如有间歇停止标志
		if(second >= int_cycl)
		{
			int_stop_flg = 0;
			O_NTB22N06 = 1;		// (反极性)急停MOS关闭
			second = 0;
		}
	}

}
/*============================================================================*/
// 函数名称:can接收雨刮器处理子程序
// 功    能:
// 输入参数:rc_can_msg
// 输出参数:
// 返回参数:
// 寄 存 器:
// 备    注:
/*----------------------------------------------------------------------------*/

void can_wiper_deal(void)
{
INT8U wiper;

	// 雨刮命令
	if(rc_can_msg.J1939_MESSAGE_UNION_PART.PDUFormat != 0xfd) return;
	if(rc_can_msg.J1939_MESSAGE_UNION_PART.PDUSpecific != 0xcc) return;
	
	// 雨刮65 -> 6.5,4,3,2
	wiper = rc_can_msg.J1939_MESSAGE_UNION_PART.Data[6] & 0x3c;
	wiper = wiper >> 2;
	if(wiper == 0)
	{
		// 雨刮OFF
		wiper_com_temp = 0;
		
		high_check_flg = 0;
		low_check_flg = 0;
	}
	if(wiper == 1)
	{
		// 雨刷LOW
		wiper_com_temp = 2;
	}
	if(wiper == 2)
	{
		// 雨刷HIGH
		wiper_com_temp = 3;
	}
	if(wiper == 4)
	{
		// 雨刮INTERMIT
		wiper_com_temp = 1;
	}

	// 防止连拉或连推雨刮控制杆所造成的命令串扰动
	if(wiper_com_temp != wiper_com_bak)
	{
		wiper_com_bak = wiper_com_temp;
	}
	else
	{
		wiper_control_com = wiper_com_temp;
	}

	// 喷水65 -> 6.7
	washer = rc_can_msg.J1939_MESSAGE_UNION_PART.Data[6] & 0xc0;
	washer = washer >> 6;
	if(washer == 0)
	{
		// 喷水关
		O_WASHER = 0;
		
	}
	if(washer == 1)
	{
		// 喷水开
		O_WASHER = 1;
		
		// 喷水 故障检测
		if(washer_check_cnt++ > 2)
		{
			washer_check_cnt = 0;
			
			if(out9_is_result < WASH_THRESHOLD)
			{
				// 喷水故障 65 -> 6.7,6.6 = 10
				tx_can_wiper_msg.J1939_MESSAGE_UNION_PART.Data[6] &= 0x3f;
				tx_can_wiper_msg.J1939_MESSAGE_UNION_PART.Data[6] |= 0x80;
			}
			else
			{
				// 喷水无故障 65 -> 6.7,6.6 = 01
				tx_can_wiper_msg.J1939_MESSAGE_UNION_PART.Data[6] &= 0x3f;
				tx_can_wiper_msg.J1939_MESSAGE_UNION_PART.Data[6] |= 0x40;
			}
			
		}
	}

}

/*============================================================================*/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -