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

📄 switchinput.c

📁 此程序为DP256的开关采集实验程序,已经通过实验证明
💻 C
📖 第 1 页 / 共 2 页
字号:
/******************************************************************************************
*							BECU Switch Module of LIN system
*Orginator:	Wang junpeng
*Date:		14th, June, 2005
*Basic Function: Sample BECU switch signal, and transfered through LIN Bus.
*Integrated with LINDriver_Master:
*
*
*
*
*
*
********************************************************************************************
*/


#define	SWITCHIN_GLOBALS

#include "LIN_Header.h"
const unsigned char	Swt_stHS_Ena_C	= (SWT_IN0_HS |SWT_IN1_HS |SWT_IN2_HS |SWT_IN3_HS |SWT_IN4_HS |SWT_IN5_HS |SWT_IN6_HS |SWT_IN7_HS);


#if SWT_IN0_EN	== 1
	const	unsigned int	Swt_tiCH0Debounce_C		= 50;//20;	
#endif

#if SWT_IN1_EN	== 1
	const	unsigned int	Swt_tiCH1Debounce_C		= 100;//20;	
#endif

#if SWT_IN2_EN	== 1
	const	unsigned int	Swt_tiCH2Debounce_C		= 20;	
#endif

#if SWT_IN3_EN	== 1
	const	unsigned int	Swt_tiCH3Debounce_C		= 150;//20;	
#endif

#if SWT_IN4_EN	== 1
	const	unsigned int	Swt_tiCH4Debounce_C		= 20;	
	const	unsigned int	Swt_tiCH4DebounceH_C	= 20;	
#endif

#if SWT_IN5_EN	== 1
	const	unsigned int	Swt_tiCH5Debounce_C		= 20;	
#endif

#if SWT_IN6_EN	== 1
	const	unsigned int	Swt_tiCH6Debounce_C		= 200;	
#endif

#if SWT_IN7_EN	== 1
	const	unsigned int	Swt_tiCH7Debounce_C		= 20;	
#endif



/************************************
*Function Name: Swt_GetInput
*Parameter: 	NONE
*Orignator: 	Wang junpeng
*Date:			14th, June, 2005
*Discription:	Read Swticth input pin state
*
**************************************/

void Swt_GetInput(void)
{
	Swt_stTemp	=	Swt_stTest;//SWT_IN_DATA;
#if SWT_IN0_EN	== 1
	if(Swt_stCH0Err	== SWT_STATE_UNKNOWN)
	{
		if(Swt_stTemp & SWT_IN0_INDEX) Swt_stCH0_mp0	= 1;
		else	Swt_stCH0_mp0	= 0;
			
		Swt_tiCH0		= LIN_GetCurrentTime();
		Swt_stCH0Err	|= SWT_STATE_DEBOUNCE;
		Swt_stCH0Err	&= ~SWT_STATE_UNKNOWN;
	}
//--------------------------------------------------------------
	else if((Swt_stCH0Err & SWT_STATE_DEBOUNCE) == SWT_STATE_DEBOUNCE)
	{
		if(Swt_stTemp & SWT_IN0_INDEX) 
		{
			if(Swt_stCH0_mp0	== 0)
			{//set error flag & add err counter
				Swt_nCH0ErrCntr++;
				if(Swt_nCH0ErrCntr > SWT_ERR_MAX_COUNT)
				{
					Swt_stCH0Err		|= SWT_STATE_ERR;
					Swt_stCH0			= SWT_STATE_ERR;
					//Swt_StateChanged(0);
					//LIN_MsgStatus[7]	|= LIN_MSG_UPDATED;
				}

				Swt_stCH0_mp0	= 1;	
				Swt_tiCH0		= LIN_GetCurrentTime();
				Swt_stCH0Err	|= SWT_STATE_DEBOUNCE;				
			}
			else if(LIN_CheckTimeOut(Swt_tiCH0, LIN_GetCurrentTime(),Swt_tiCH0Debounce_C))
			{
				Swt_nCH0ErrCntr	=0;
				Swt_stCH0Err		&= ~(SWT_STATE_DEBOUNCE | SWT_STATE_ERR);

#if	SWT_IN0_HS
				Swt_stCH0			= SWT_STATE_ON;
#else
				Swt_stCH0			= SWT_STATE_OFF;
#endif
				
				//LIN_MsgStatus[7]	|= LIN_MSG_UPDATED;
			}
		}
		else
		{
			if(Swt_stCH0_mp0	== 1)
			{
				Swt_nCH0ErrCntr++;
				if(Swt_nCH0ErrCntr > SWT_ERR_MAX_COUNT)
				{
					Swt_stCH0Err	|= SWT_STATE_ERR;
					Swt_stCH0		= SWT_STATE_ERR;
					//LIN_MsgStatus[7]|= LIN_MSG_UPDATED;
				}

				Swt_stCH0_mp0	= 0;	
				Swt_tiCH0		= LIN_GetCurrentTime();
				Swt_stCH0Err	|= SWT_STATE_DEBOUNCE;
			}
			else if(LIN_CheckTimeOut(Swt_tiCH0, LIN_GetCurrentTime(),Swt_tiCH0Debounce_C))
			{
				Swt_nCH0ErrCntr	=0;
				Swt_stCH0Err		&= ~(SWT_STATE_DEBOUNCE | SWT_STATE_ERR);
				Swt_stCH0			= Swt_stCH0_mp0;

#if	SWT_IN0_HS
				Swt_stCH0			= SWT_STATE_OFF;
#else
				Swt_stCH0			= SWT_STATE_ON;
#endif
				
				//LIN_MsgStatus[7]	|= LIN_MSG_UPDATED;
			}
		}
	}
//--------------------------------------------------------------
	else
	{
		if(Swt_stTemp & SWT_IN0_INDEX) 
		{
			if(Swt_stCH0_mp0	== 0)
			{
				Swt_stCH0_mp0	= 1;	
				Swt_tiCH0		= LIN_GetCurrentTime();
				Swt_stCH0Err	|= SWT_STATE_DEBOUNCE;
			}
		}
		else
		{
			if(Swt_stCH0_mp0	== 1)
			{
				Swt_stCH0_mp0	= 0;	
				Swt_tiCH0		= LIN_GetCurrentTime();
				Swt_stCH0Err	|= SWT_STATE_DEBOUNCE;
			}
		}
	}
#endif

#if SWT_IN1_EN	== 1
	if(Swt_stCH1Err	== SWT_STATE_UNKNOWN)
	{
		if(Swt_stTemp & SWT_IN1_INDEX) Swt_stCH1_mp0	= 1;
		else	Swt_stCH1_mp0	= 0;
			
		Swt_tiCH1		= LIN_GetCurrentTime();
		Swt_stCH1Err	|= SWT_STATE_DEBOUNCE;
		Swt_stCH1Err	&= ~SWT_STATE_UNKNOWN;
	}
//--------------------------------------------------------------
	else if((Swt_stCH1Err & SWT_STATE_DEBOUNCE) == SWT_STATE_DEBOUNCE)
	{
		if(Swt_stTemp & SWT_IN1_INDEX) 
		{
			if(Swt_stCH1_mp0	== 0)
			{//set error flag & add err counter
				Swt_nCH1ErrCntr++;
				if(Swt_nCH1ErrCntr > SWT_ERR_MAX_COUNT)
				{
					Swt_stCH1Err	|= SWT_STATE_ERR;
					Swt_stCH1		= SWT_STATE_ERR;
					//LIN_MsgStatus[7]|= LIN_MSG_UPDATED;
				}

				Swt_stCH1_mp0	= 1;	
				Swt_tiCH1		= LIN_GetCurrentTime();
				Swt_stCH1Err	|= SWT_STATE_DEBOUNCE;				
			}
			else if(LIN_CheckTimeOut(Swt_tiCH1, LIN_GetCurrentTime(),Swt_tiCH1Debounce_C))
			{
				Swt_nCH1ErrCntr	=0;
				Swt_stCH1Err		&= ~(SWT_STATE_DEBOUNCE | SWT_STATE_ERR);

#if	SWT_IN1_HS
				Swt_stCH1			= SWT_STATE_ON;
#else
				Swt_stCH1			= SWT_STATE_OFF;
#endif
				
				//Swt_stCH1			= Swt_stCH1_mp0;
				//LIN_MsgStatus[7]	|= LIN_MSG_UPDATED;
			}
		}
		else
		{
			if(Swt_stCH1_mp0	== 1)
			{
				Swt_nCH1ErrCntr++;
				if(Swt_nCH1ErrCntr > SWT_ERR_MAX_COUNT)
				{
					Swt_stCH1Err	|= SWT_STATE_ERR;
					Swt_stCH1		= SWT_STATE_ERR;
					//LIN_MsgStatus[7]|= LIN_MSG_UPDATED;
				}

				Swt_stCH1_mp0	= 0;	
				Swt_tiCH1		= LIN_GetCurrentTime();
				Swt_stCH1Err	|= SWT_STATE_DEBOUNCE;
			}
			else if(LIN_CheckTimeOut(Swt_tiCH1, LIN_GetCurrentTime(),Swt_tiCH1Debounce_C))
			{
				Swt_nCH1ErrCntr	=0;
				Swt_stCH1Err		&= ~(SWT_STATE_DEBOUNCE | SWT_STATE_ERR);
				//Swt_stCH1			= Swt_stCH1_mp0;
				//LIN_MsgStatus[7]	|= LIN_MSG_UPDATED;

#if	SWT_IN1_HS
				Swt_stCH1			= SWT_STATE_OFF;
#else
				Swt_stCH1			= SWT_STATE_ON;
#endif
				
			}
		}
	}
//--------------------------------------------------------------
	else
	{
		if(Swt_stTemp & SWT_IN1_INDEX) 
		{
			if(Swt_stCH1_mp0	== 0)
			{
				Swt_stCH1_mp0	= 1;	
				Swt_tiCH1		= LIN_GetCurrentTime();
				Swt_stCH1Err	|= SWT_STATE_DEBOUNCE;
			}
		}
		else
		{
			if(Swt_stCH1_mp0	== 1)
			{
				Swt_stCH1_mp0	= 0;	
				Swt_tiCH1		= LIN_GetCurrentTime();
				Swt_stCH1Err	|= SWT_STATE_DEBOUNCE;
			}
		}
	}
#endif

#if SWT_IN2_EN	== 1
	if(Swt_stCH2Err	== SWT_STATE_UNKNOWN)
	{
		if(Swt_stTemp & SWT_IN2_INDEX) Swt_stCH2_mp0	= 1;
		else	Swt_stCH2_mp0	= 0;
			
		Swt_tiCH2		= LIN_GetCurrentTime();
		Swt_stCH2Err	|= SWT_STATE_DEBOUNCE;
		Swt_stCH2Err	&= ~SWT_STATE_UNKNOWN;
	}
//--------------------------------------------------------------
	else if((Swt_stCH2Err & SWT_STATE_DEBOUNCE) == SWT_STATE_DEBOUNCE)
	{
		if(Swt_stTemp & SWT_IN2_INDEX) 
		{
			if(Swt_stCH2_mp0	== 0)
			{//set error flag & add err counter
				Swt_nCH2ErrCntr++;
				if(Swt_nCH2ErrCntr > SWT_ERR_MAX_COUNT)
				{
					Swt_stCH2Err	|= SWT_STATE_ERR;
					Swt_stCH2		= SWT_STATE_ERR;
					//LIN_MsgStatus[7]|= LIN_MSG_UPDATED;
					//VirtualWiper();
				}

				Swt_stCH2_mp0	= 1;	
				Swt_tiCH2		= LIN_GetCurrentTime();
				Swt_stCH2Err	|= SWT_STATE_DEBOUNCE;				
			}
			else if(LIN_CheckTimeOut(Swt_tiCH2, LIN_GetCurrentTime(),Swt_tiCH2Debounce_C))
			{
				Swt_nCH2ErrCntr	=0;
				Swt_stCH2Err		&= ~(SWT_STATE_DEBOUNCE | SWT_STATE_ERR);
				//Swt_stCH2			= Swt_stCH2_mp0;
				//LIN_MsgStatus[7]	|= LIN_MSG_UPDATED;

#if	SWT_IN2_HS
				Swt_stCH2			= SWT_STATE_ON;
//				VirtualWiper();
#else
				Swt_stCH2			= SWT_STATE_OFF;
#endif
			}
		}
		else
		{//Brush Motor Check In(position)
			if(Swt_stCH2_mp0	== 1)
			{
				Swt_nCH2ErrCntr++;
				if(Swt_nCH2ErrCntr > SWT_ERR_MAX_COUNT)
				{
					Swt_stCH2Err	|= SWT_STATE_ERR;
					Swt_stCH2		= SWT_STATE_ERR;
					//LIN_MsgStatus[7]|= LIN_MSG_UPDATED;
				}

				Swt_stCH2_mp0	= 0;	
				Swt_tiCH2		= LIN_GetCurrentTime();
				Swt_stCH2Err	|= SWT_STATE_DEBOUNCE;
			}
			else if(LIN_CheckTimeOut(Swt_tiCH2, LIN_GetCurrentTime(),Swt_tiCH2Debounce_C))
			{
				Swt_nCH2ErrCntr	=0;
				Swt_stCH2Err		&= ~(SWT_STATE_DEBOUNCE | SWT_STATE_ERR);
				//Swt_stCH2			= Swt_stCH2_mp0;
				//LIN_MsgStatus[7]	|= LIN_MSG_UPDATED;

#if	SWT_IN2_HS
				Swt_stCH2			= SWT_STATE_OFF;
#else
				Swt_stCH2			= SWT_STATE_ON;
#endif
			}
		}
	}
//--------------------------------------------------------------
	else
	{
		if(Swt_stTemp & SWT_IN2_INDEX) 
		{
			if(Swt_stCH2_mp0	== 0)
			{
				Swt_stCH2_mp0	= 1;	
				Swt_tiCH2		= LIN_GetCurrentTime();
				Swt_stCH2Err	|= SWT_STATE_DEBOUNCE;
			}
		}
		else
		{
			if(Swt_stCH2_mp0	== 1)
			{
				Swt_stCH2_mp0	= 0;	
				Swt_tiCH2		= LIN_GetCurrentTime();
				Swt_stCH2Err	|= SWT_STATE_DEBOUNCE;
			}
		}
	}
#endif

#if SWT_IN3_EN	== 1
	if(Swt_stCH3Err	== SWT_STATE_UNKNOWN)
	{
		if(Swt_stTemp & SWT_IN3_INDEX) Swt_stCH3_mp0	= 1;
		else	Swt_stCH3_mp0	= 0;
			
		Swt_tiCH3		= LIN_GetCurrentTime();
		Swt_stCH3Err	|= SWT_STATE_DEBOUNCE;
		Swt_stCH3Err	&= ~SWT_STATE_UNKNOWN;
	}
//--------------------------------------------------------------
	else if((Swt_stCH3Err & SWT_STATE_DEBOUNCE) == SWT_STATE_DEBOUNCE)
	{
		if(Swt_stTemp & SWT_IN3_INDEX) 
		{
			if(Swt_stCH3_mp0	== 0)
			{//set error flag & add err counter
				Swt_nCH3ErrCntr++;
				if(Swt_nCH3ErrCntr > SWT_ERR_MAX_COUNT)
				{
					Swt_stCH3Err	|= SWT_STATE_ERR;
					Swt_stCH3		= SWT_STATE_ERR;
					//LIN_MsgStatus[7]|= LIN_MSG_UPDATED;
				}

				Swt_stCH3_mp0	= 1;	
				Swt_tiCH3		= LIN_GetCurrentTime();
				Swt_stCH3Err	|= SWT_STATE_DEBOUNCE;				
			}
			else if(LIN_CheckTimeOut(Swt_tiCH3, LIN_GetCurrentTime(),Swt_tiCH3Debounce_C))
			{
				Swt_nCH3ErrCntr	=0;
				Swt_stCH3Err		&= ~(SWT_STATE_DEBOUNCE | SWT_STATE_ERR);
				//Swt_stCH3			= Swt_stCH3_mp0;
				//LIN_MsgStatus[7]	|= LIN_MSG_UPDATED;

#if	SWT_IN3_HS
				Swt_stCH3			= SWT_STATE_ON;
#else
				Swt_stCH3			= SWT_STATE_OFF;
#endif
			}
		}
		else
		{
			if(Swt_stCH3_mp0	== 1)
			{
				Swt_nCH3ErrCntr++;
				if(Swt_nCH3ErrCntr > SWT_ERR_MAX_COUNT)
				{
					Swt_stCH3Err	|= SWT_STATE_ERR;
					Swt_stCH3		= SWT_STATE_ERR;
					//LIN_MsgStatus[7]|= LIN_MSG_UPDATED;
				}

				Swt_stCH3_mp0	= 0;	
				Swt_tiCH3		= LIN_GetCurrentTime();
				Swt_stCH3Err	|= SWT_STATE_DEBOUNCE;
			}
			else if(LIN_CheckTimeOut(Swt_tiCH3, LIN_GetCurrentTime(),Swt_tiCH3Debounce_C))
			{
				Swt_nCH3ErrCntr	=0;
				Swt_stCH3Err		&= ~(SWT_STATE_DEBOUNCE | SWT_STATE_ERR);

#if	SWT_IN3_HS
				Swt_stCH3			= SWT_STATE_OFF;
#else
				Swt_stCH3			= SWT_STATE_ON;
#endif
				Swt_GetKeyPos();
				
				//Swt_stCH3			= Swt_stCH3_mp0;
				//LIN_MsgStatus[7]	|= LIN_MSG_UPDATED;
			}
		}
	}
//--------------------------------------------------------------
	else
	{
		if(Swt_stTemp & SWT_IN3_INDEX) 
		{
			if(Swt_stCH3_mp0	== 0)
			{
				Swt_stCH3_mp0	= 1;	
				Swt_tiCH3		= LIN_GetCurrentTime();
				Swt_stCH3Err	|= SWT_STATE_DEBOUNCE;
			}
		}
		else
		{
			if(Swt_stCH3_mp0	== 1)
			{
				Swt_stCH3_mp0	= 0;	
				Swt_tiCH3		= LIN_GetCurrentTime();
				Swt_stCH3Err	|= SWT_STATE_DEBOUNCE;
			}
		}
	}
#endif

#if SWT_IN4_EN	== 1
	if(Swt_stCH4Err	== SWT_STATE_UNKNOWN)
	{
		if(Swt_stTemp & SWT_IN4_INDEX) Swt_stCH4_mp0	= 1;
		else	Swt_stCH4_mp0	= 0;
			
		Swt_tiCH4		= LIN_GetCurrentTime();
		Swt_stCH4Err	|= SWT_STATE_DEBOUNCE;
		Swt_stCH4Err	&= ~SWT_STATE_UNKNOWN;
	}
//--------------------------------------------------------------
	else if((Swt_stCH4Err & SWT_STATE_DEBOUNCE) == SWT_STATE_DEBOUNCE)
	{
		if(Swt_stTemp & SWT_IN4_INDEX) 
		{
			if(Swt_stCH4_mp0	== 0)

⌨️ 快捷键说明

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