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

📄 key.c

📁 7541数字高频头源程序
💻 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	7
const unsigned char ADKeyTable[]=
{
	//0,30,75,115,148,184,225,255
	255,215,184,144,104,64,24,0
};

void GetOneLineADKey(unsigned char ADLine,unsigned char Linenum)
{
	unsigned char i,temp;
	
	temp=GetADValue(ADLine);
	if(temp==255)return;
	for(i=0;i<(AD_ONE_LINE_KEY_NUM+1);i++)
	{
		
		if(temp>=ADKeyTable[i])
		{
			Getkey=i+AD_ONE_LINE_KEY_NUM*Linenum;
			break;
		}
	}
}


void GetADKey(void)
{
	GetOneLineADKey(AD_KEY1,0);
	GetOneLineADKey(AD_KEY2,1);
	GetOneLineADKey(AD_KEY3,2);
	GetOneLineADKey(AD_KEY4,3);
	
	/*unsigned char i,temp;
	
	temp=GetADValue(AD_KEY1);
	for(i=0;i<8;i++)
	{
		if(ADKeyTable[i]>temp)
		{
			Getkey=i;
			break;
		}
	}
	
	temp=GetADValue(AD_KEY2);
	for(i=0;i<8;i++)
	{
		if(ADKeyTable[i]>temp)
		{
			Getkey=i+7;
			break;
		}
	}

	temp=GetADValue(AD_KEY3);
	for(i=0;i<8;i++)
	{
		if(ADKeyTable[i]>temp)
		{
			Getkey=i+14;
			break;
		}
	}

	temp=GetADValue(AD_KEY4);
	for(i=0;i<8;i++)
	{
		if(ADKeyTable[i]>temp)
		{
			Getkey=i+21;
			break;
		}
	}*/
}


static const unsigned char RemoteTable[21]=
{
    0x30,0x50,0xA8,0xC8,0x28,0x90,0x88,0xE0,0x60,0x70,
    0x10,0x00,0x80,0xF0,0x48,0x40,0xC0,0x08,0x68,0x20,
    0xA0
};

/*********************************************
	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;
				if((IrxBuffer[1] == 0xFF)
				&& (IrxBuffer[0] == ~IrxBuffer[1])
				&& (IrxBuffer[2] == ~IrxBuffer[3]) )
				  IrKey = IrxBuffer[2];
			}
		}
		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,temp;

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

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;
}


void KeyInit(void)
{
	//InitRotary();
	PD_ADKEY1=0;
	PO_ADKEY1=0;
	PD_ADKEY2=0;
	PO_ADKEY2=0;
	PD_ADKEY3=0;
	PO_ADKEY3=0;
	PD_ADKEY4=0;
	PO_ADKEY4=0;
}

/*********************************************
	Function:		KeyMain
	Description:	
	Write/Modify:	Perry.Liang
	Time:		2004-7-9- 10:46:15
*********************************************/
void KeyMain(void)
{
	Getkey=NOKEY;
	KeyCode=NOKEY;

	GetADKey();
	LongShortKeyProcess();

	//RotaryProcess();
}

void KeyTimer100ms(void)
{
	if ((KeyProcessTimer!=0xFF)&&(KeyProcessTimer>0))
		KeyProcessTimer--;

}  
/*********************************************************
				File End
*********************************************************/

⌨️ 快捷键说明

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