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

📄 wiper.c

📁 车载雨刮器控制程序由CW环境开发已调试通过,实现间歇时间受控,喷水自动刮水功能
💻 C
📖 第 1 页 / 共 2 页
字号:
/******************************************************************************
 注意:3个低端22N06控制是反极性的,0:导通,1:关闭
 查询 can_wiper_deal 处更改接收数据格式
 查询 故障检测 处更改发送数据格式

/******************************************************************************
 模块端口配置
 ----------------------------------------------------------------------------*/
#define I_WIP_PERCH I_ELOG0

#define O_WIPER_LOW	O_OUT14IN
#define O_WIPER_HI	O_OUT5IN
#define O_NTB22N06	O_OUT16IN
#define O_WASHER	O_OUT9IN
#define O_WIPER_RLY O_OUT14AON

// 雨刮寄存器
unsigned char	washer;				// 喷水命令寄存器
unsigned char	wiper_control_com;	// 雨刮命令寄存器
unsigned char	wiper_com_temp;		// 用于雨刮控制命令比较
unsigned char	wiper_com_bak;		// 用于雨刮控制命令备份比较
unsigned char	sentido;			// 雨刮器运行状态寄存器
unsigned char	cnt_sentido3;
unsigned char	second;
unsigned char	cnt_60s;
unsigned char	int_cycl;
unsigned char	cnt_wash;			// 喷水后雨刮器再刮三次计数器
unsigned int	shutdown;
unsigned int	inter_on_delay;
unsigned int	inttime;
unsigned int	wash_time;
unsigned int	delay_ms_countb;
unsigned int	delay_ms_count;
unsigned char	washer_check_cnt;	// 喷水检测延迟时间计数器

// 雨刮位标志
union WIPER_FLAG
{
	unsigned int WIPER_WORD;
	struct
	{
		unsigned int	bit0:1;
		unsigned int	bit1:1;
		unsigned int	bit2:1;
		unsigned int	bit3:1;
		unsigned int	bit4:1;
		unsigned int	bit5:1;
		unsigned int	bit6:1;
		unsigned int	bit7:1;
		unsigned int	bit8:1;
		unsigned int	bit9:1;
		unsigned int	bit10:1;
		unsigned int	bit11:1;
		unsigned int	bit12:1;
		unsigned int	bit13:1;
		unsigned int	bit14:1;
		unsigned int	bit15:1;
	}BITS;
}wiper_flag1;
#define washstop_flag	wiper_flag1.BITS.bit0
#define delay2ms_flag	wiper_flag1.BITS.bit1
#define delay400ms_flag	wiper_flag1.BITS.bit2
#define high_check_flg	wiper_flag1.BITS.bit3
#define low_check_flg	wiper_flag1.BITS.bit4
#define sentido3_flag	wiper_flag1.BITS.bit5
#define cmd_start_flg	wiper_flag1.BITS.bit6
#define int_on_dly_flg	wiper_flag1.BITS.bit7
#define wash_cnt_flg	wiper_flag1.BITS.bit8
#define int_flag		wiper_flag1.BITS.bit9
#define int_once_flg	wiper_flag1.BITS.bit10
#define wash_flg		wiper_flag1.BITS.bit11
#define startup_flg		wiper_flag1.BITS.bit12
#define int_stop_flg	wiper_flag1.BITS.bit13
#define mos_break_flg	wiper_flag1.BITS.bit14
#define wash_add_flg	wiper_flag1.BITS.bit15

// 雨刮数据
#define STOP_DATA		0x99
#define INT_DATA		0x88
#define HIGH_DATA		0x77
#define LOW_DATA		0x66
#define WATER_DATA		0x55
#define HIGH_THRESHOLD	0x30	// 雨刮器高速 10位ADC阈值
#define LOW_THRESHOLD	0x30	// 雨刮器低速 10位ADC阈值
#define WASH_THRESHOLD	0x10	// 雨刮器喷水 10位ADC阈值

/*-----------------------------------------------------------------------------
 任务函数预定义
 ----------------------------------------------------------------------------*/
void can_wiper_deal(void);
void wiper_1ms_control(void);
void wiper_control(void);
void wiper_init(void);
void wiper_dly_ms(unsigned int COUNT);
void wiper_command(void);

/******************************************************************************
 功能函数
 ----------------------------------------------------------------------------*/

/*============================================================================*/
// 函数名称:雨刮器初始化子程序
// 功    能:
// 输入参数:
// 输出参数:
// 返回参数:
// 寄 存 器:
// 备    注:
/*----------------------------------------------------------------------------*/
void wiper_init(void)
{
	O_NTB22N06 = 1;		// (反极性)急停MOS关闭
	O_WIPER_LOW = 0;	// 低速线关闭
	O_WIPER_HI = 0;		// 高速线关闭
	O_WIPER_RLY = 0;	// 高速线继电器断开

	shutdown = 0;
	inter_on_delay = 0;
	delay_ms_count = 2;
	delay_ms_countb = 400;
	sentido = STOP_DATA;		// 初始化默认关
	cnt_60s = 0;
	second = 0;
	cnt_wash = 0;
	cnt_sentido3 = 0;
	wash_time = 0;
	inttime = 0;
	int_cycl = 6;		// 初始化默认间歇6s
	washstop_flag = 0;
	washer_check_cnt = 0;

}
/*============================================================================*/
// 函数名称:雨刮器延时切换子程序
// 功    能:
// 输入参数: 
// 输出参数:
// 返回参数:
// 寄 存 器:
// 备    注:
/*----------------------------------------------------------------------------*/
void wiper_dly_ms(unsigned int COUNT)
{
	if(COUNT < 10)
	{
		delay2ms_flag = 1;
		delay_ms_count = COUNT;
	}
	else
	{
		delay400ms_flag = 1;
		delay_ms_countb = COUNT;
	}
}
/*============================================================================*/
// 函数名称:雨刮器命令接收子程序
// 功    能:
// 输入参数: 
// 输出参数:
// 返回参数:
// 寄 存 器:
// 备    注:
// 调用周期: 20ms
/*----------------------------------------------------------------------------*/
void wiper_command(void)
{
	if(cmd_start_flg == 0)
	{
		if(washer == 1)
		{
			//喷水开关按下
			wash_cnt_flg = 1;

			if(cnt_sentido3 > 0)
			{
				sentido = WATER_DATA;
				wash_flg = 1;
				washstop_flag = 1;
				sentido3_flag = 0;
			}
		}
		else
		{
			if(wiper_control_com == 1)
			{
				//间歇开关按下
				if(sentido == WATER_DATA)
				{
					sentido3_flag = 0;
					wash_flg = 0;
					cnt_wash = 0;
				}
				
				sentido = INT_DATA;
				wash_time = 0;
				cnt_sentido3 = 0;
				
				if(washstop_flag == 0)
				{
					wash_flg = 0;
				}
			}
			else
			{
				if(wiper_control_com == 3)
				{
					//高速开关按下
					if(sentido == WATER_DATA)
					{
						sentido3_flag = 0;
						wash_flg = 0;
						cnt_wash = 0;
					}
					
					sentido = HIGH_DATA;
					wash_time = 0;
					cnt_sentido3 = 0;
					
					if(washstop_flag == 0)
					{
						wash_flg = 0;
					}
				}
				else
				{
					if(wiper_control_com == 2)
					{
						//低速开关按下
						if(sentido == WATER_DATA)
						{
							sentido3_flag = 0;
							wash_flg = 0;
							cnt_wash = 0;
						}
						
						sentido = LOW_DATA;
						wash_time = 0;
						cnt_sentido3 = 0;
						
						if(washstop_flag == 0)
						{
							wash_flg = 0;
						}
					}
					else
					{
						if(wiper_control_com == 0)
						{
							//停止开关按下
							if(sentido == WATER_DATA)
							{
								sentido3_flag = 1;
							}
							
							sentido = STOP_DATA;
							wash_time = 0;
							cnt_sentido3 = 0;
							
							if(wash_flg ==0)
							{
								if(int_flag == 1)
								{
									int_flag = 0;
									int_once_flg = 1;
								}
							}
						}
					}
				}
			}
		}
	}

}
/*============================================================================*/
// 函数名称:雨刮器控制子程序
// 功    能:
// 输入参数: 
// 输出参数:
// 返回参数:
// 寄 存 器:
// 备    注:
// 调用周期: 1ms
/*----------------------------------------------------------------------------*/
void wiper_1ms_control(void)
{
	inttime++;
	if((delay2ms_flag) && (delay_ms_count > 0))
	{
		delay_ms_count--;
	}
	if((delay400ms_flag) && (delay_ms_countb > 0))
	{
		delay_ms_countb--;
	}
	if(int_on_dly_flg)
	{
		inter_on_delay++;
	}
	if(wash_cnt_flg == 1)
	{
		wash_time++;
	}

//------

	if(mos_break_flg == 1)
	{
		//如有关断输出标志 则等待2ms后接通MOS管
		shutdown++;
		if(shutdown > 1)
		{
			shutdown = 0;
			O_NTB22N06 = 0;		// (反极性)急停MOS启动
			mos_break_flg = 0;
			washstop_flag = 0;
		}
	}

	if((!I_WIP_PERCH) && (sentido == INT_DATA) && (startup_flg == 1))
	{
		//intermission stop STATE
		O_WIPER_LOW = 0;
		O_WIPER_HI = 0;		//stop state of intermission
		startup_flg = 0;
		inter_on_delay = 0;
		mos_break_flg = 1;		//TURN ON MOSFET
		int_stop_flg = 1;
		second = 0;
		cnt_60s = 0;
		low_check_flg = 0;
	}

}
/*============================================================================*/
// 函数名称:雨刮器控制子程序
// 功    能:
// 输入参数: 
// 输出参数:
// 返回参数:
// 寄 存 器:
// 备    注: 
// 调用周期: 20ms
/*----------------------------------------------------------------------------*/
void wiper_control(void)
{
	if(sentido == WATER_DATA)
	{
		//喷水档启动
		cnt_wash = 0;

		O_NTB22N06 = 1;		// (反极性)急停MOS关闭
		O_WIPER_HI = 0;
		
		if(!delay2ms_flag)
		{
			wiper_dly_ms(2);

⌨️ 快捷键说明

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