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

📄 keyback.c

📁 我个人编写的车载dvd上的程序
💻 C
字号:
/*********************************************************
	Project:		ST FST(TDA7540)
	File name:	key.c
	Description:	
	Write/Modify:	Perry
	Time:		2005-11-22- 10:40:55
*********************************************************/

#include "public.h"

#define AD_ONE_LINE_KEY_NUM	12



static const unsigned char ADKeyTable[]=
{
	//227,182,146,108,67,23,0,
	0x3,0x7,0x10,0x18,0x25,0x35,0x45,0x55,0x70,0x85,0xc5,0xda,
};


/*********************************************
	Function:		GetOneLineADKey
	Description:	
	Write/Modify:	Perry.Liang
	Time:		2006-1-24- 15:41:18
*********************************************/
void GetOneLineADKey(unsigned char ADLine,unsigned char Linenum)
{
	unsigned char i,temp;
	
	temp=GetADValue(ADLine);
	if(temp>240)return;
	
	for(i=0;i<(AD_ONE_LINE_KEY_NUM+1);i++)
	{
		if(temp<=ADKeyTable[i])
		{
			Getkey=i+1+AD_ONE_LINE_KEY_NUM*Linenum;
                   
			break;
		}
	}


}


/*********************************************
	Function:		GetADKey
	Description:	
	Write/Modify:	Perry.Liang
	Time:		2006-1-24- 15:41:20
*********************************************/
void GetADKey(void)
{
	GetOneLineADKey(AD_KEY0,0);
	//GetOneLineADKey(AD_KEY1,1);
#ifdef SINO_MOS_ADD
	GetOneLineADKey(AD_KEY2,2);
#endif
}


static const unsigned char RemoteTable[20]=
{
    0x82,0xe2,0xe0,0x42,0xa2,0x92,0x60,0xa0,0x3a,0x78,
    0x7a,0x40,0x1a,0x58,0xda,0x80,0xd8,0x9a,0x5a,0x18,
  
};

/*********************************************
	Function:		Infra_Red
	Description:	
	Write/Modify:	Perry.Liang
	Time:		2004-7-2- 11:53:19
*********************************************/
void InfraRed(void)
{

	if (IrKey == 0xFF)
	{
		if (RemoDelay < 6) 
		{
			IrxBuffer[irbit/8] <<=  1;			 
			if (RemoDelay <= 2)
				(IrxBuffer[irbit/8]) &= 0xFE;	 // make 'low'
			else
				(IrxBuffer[irbit/8]) |= 0x01;	 // make 'high'
			 
			if(irbit<32)irbit++;
			if (irbit == 32)
			{
				irbit=0;
			#ifdef SINO_MOS
                          if(IrxBuffer[0] == ((IR_SYSTEM_CODE >> 8)&0xff) && IrxBuffer[1] == (IR_SYSTEM_CODE &0xff))
                          	     IrKey = IrxBuffer[2];

			#else
				if((IrxBuffer[1] == 0xFF)
				&& (IrxBuffer[0]+IrxBuffer[1]==255)
				&& (IrxBuffer[2]+IrxBuffer[3]==255))
			
				//&& (IrxBuffer[0] == ~IrxBuffer[1])
				//&& (IrxBuffer[2] == ~IrxBuffer[3]) )
					IrKey = IrxBuffer[2];
			#endif	
			}
		}
		else
			irbit=0;
	}
	RemoDelay = 0;
}

/*********************************************
	Function:		Ir_Timer
	Description:	
	Write/Modify:	Perry.Liang
	Time:		2004-7-2- 11:53:24
*********************************************/
void IrTimer(void)
{
	if (RemoDelay >= 200)
		IrKey = 0xFF;	
	else
		RemoDelay++;
}

/*********************************************
	Function:		GetRemote
	Description:	
	Write/Modify:	Perry.Liang
	Time:		2004-7-9- 10:46:07
*********************************************/
void GetRemote(void)
{
	unsigned char i;

	if(IrKey != 0xFF)
	{
		for(i=0;i<20;i++)
		{
			if(RemoteTable[i]==IrKey)
			{
				Getkey=i+31;
				break;
			}
		}
	}
}

#if 0
/*********************************************
	Function:		INTEncoder
	Description:	
	Write/Modify:	Perry.Liang
	Time:		2004-7-21- 10:47:53
*********************************************/
void INTEncoder(void)
{
	if(F_EncBackup!=Pin_EVA)
	{
		M_WAIT;
		if(Pin_EVB==Pin_EVA)
			GetEnc=P_EC_DN;
		else
			GetEnc=P_EC_UP;
	}
	F_EncBackup=Pin_EVA;
}

/*********************************************
	Function:		GetEncoder
	Description:	
	Write/Modify:	Perry.Liang
	Time:		2004-7-9- 10:46:03
*********************************************/
void GetEncoder(void)
{     
	if(GetEnc!=NOKEY && KeyCode==NOKEY)
	{
		KeyCode=GetEnc;
		GetEnc=NOKEY;
	}
}
#endif

/*********************************************
	Function:		LongShortKeyProcess
	Description:	
	Write/Modify:	Perry.Liang
	Time:		2006-1-24- 15:41:27
*********************************************/


void LongShortKeyProcess(void)
{
	if(Getkey != DBGetkey)
	{
		DBGetkey = Getkey;
		return;
	}    

	KeyCode = Getkey;
	CurrentKey = Getkey;

	//PUSH
	if (KeyProcessTimer==0 && PreviousKey==NOKEY 
		&& CurrentKey !=NOKEY)	
	{
		
		//LONG KEY TIME OR DEPRESS KEY TIME SET
		switch(CurrentKey)	
		{                                                                                                             
			case P_RM_VOLUP:
			case P_RM_VOLDN:
			case P_AD_VOLUP:
			case P_AD_VOLDN:
				KeyProcessTimer=HALF_SECOND ;
				break;

			//case P_AD_SEEKUP:
			//case P_AD_SEEKDN:
			case P_RM_SEEKUP:
			case P_RM_SEEKDN:
				KeyProcessTimer = ONE_SECOND;
				break;
					
			default  :   
				KeyProcessTimer = ONE_SECOND;
				break;
		}
	}

	//LONG OR DEPRESS KEY
	if( CurrentKey == PreviousKey 
		&& CurrentKey !=NOKEY)	
	{
		if (KeyProcessTimer==0)
		{
			//LONG
			switch(CurrentKey)	
			{
				case P_RM_VOLUP:
				case P_RM_VOLDN:
				case P_AD_VOLUP:
				case P_AD_VOLDN:
					KeyProcessTimer=ONE_TEN_SECOND;	
					KeyCode=PreviousKey;	
					break;
					
				default:
					KeyCode=PreviousKey | LONGKEY;	
					KeyProcessTimer=0xFF;
					break;
			}
		}
		else
			KeyCode=NOKEY;
	}

	//SHORT OR LONG RELEASE
	if ( PreviousKey!=NOKEY && CurrentKey == NOKEY)	
	{
		if (KeyProcessTimer==0xFF || KeyProcessTimer==0)
		{
			//LONG RELEASE
			KeyCode=PreviousKey | LONG_RELEASEKEY;	
		}
		else
		{
			//SHORT
			KeyCode=PreviousKey | SHORTKEY;   
		}
		KeyProcessTimer=0;		
	}

	PreviousKey=CurrentKey;
	
}

/*********************************************
	Function:		KeyInit
	Description:	
	Write/Modify:	Perry.Liang
	Time:		2006-1-24- 15:41:30
*********************************************/
void KeyInit(void)
{
	//InitRotary();
	//PD_REMOTE=0;//PF2--floating interrupt input for keyboard remote 
	//PO_REMOTE=1;

	/*PD_REMOTE=0;//PF2--floating input for detect panel open/close.(0-close,1-open)
	PO_REMOTE=0;


	PD_EVA=0;//PA2--floating input
	PO_EVA=0;

	PD_EVB=0;//PA3--floating input
	PO_EVB=0;*/

	//pull-up interrupt input


	
	PD_REMOTE=0;
	PCR1_REMOTE=1;
	PCR2_REMOTE=1;
	
	PDDR_ADKEY0=0;
	PCR1_ADKEY0=0;
	PCR2_ADKEY0=0;

	PDDR_ADKEY1=0;
	PCR1_ADKEY1=0;
	PCR2_ADKEY1=0;

	PDDR_ADKEY2=0;
	PCR1_ADKEY2=0;
	PCR2_ADKEY2=0;
#ifdef SINO_MOS
      ADC_TDRL |= y11100000;
    //  ADC_TDRH|=y00000001;
#else
	ADC_TDRH|=y11100000;
#endif
	IrKey = 0xFF;
	/*GetEnc=NOKEY;
	F_EncBackup=Pin_EVA;*/
	
}

/*********************************************
	Function:		KeyMain
	Description:	
	Write/Modify:	Perry.Liang
	Time:		2004-7-9- 10:46:15
*********************************************/
void KeyMain(void)
{
	Getkey=NOKEY;
	KeyCode=NOKEY;
	GetADKey();
	GetRemote();
	LongShortKeyProcess();
	//GetEncoder();
	/*if(Pin_REMOTE&&KeyCode!=S_AD_EJECT)//Detect panel open/close to disable/enable key process
	{
		KeyCode=NOKEY;
	}*/
}

/*********************************************
	Function:		KeyTimer100ms
	Description:	
	Write/Modify:	Perry.Liang
	Time:		2006-1-24- 15:41:32
*********************************************/
void KeyTimer10ms(void)
{
	if ((KeyProcessTimer!=0xFF)&&(KeyProcessTimer>0))
		KeyProcessTimer--;
}  
/*********************************************************
				File End
*********************************************************/

⌨️ 快捷键说明

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