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

📄 key.c

📁 TDA7540 收音机程序
💻 C
字号:
/***************************************************************************
Project  :   TDA7540 Jig board 
Compiler : ST7 HiCross C (HiWARE)
Module   :  Key.c
Version  :  V 1.0
Created  : 
Author   :  Jerry HE / ST-ShenZhen
Description
         -  Interrupt routine
Modified
	  -     
***************************************************************************/

#include "system.h"

#pragma INTO_ROM

// FST Jig board
static const unsigned char KeyValueTable[]=
{0,4,13,27,42,61,84,109,135,160,182,200,218,238};
//13 keys here


/*--------------------------------------------------------------------------
Routine : KeyBoard 
Input   : 
Output  :
Description 
        - Key main service routine
--------------------------------------------------------------------------*/ 

void KeyBoard()
{
	KeyCode = No_Key;
	if(F_ADKeyRead==1)
	{
		F_ADKeyRead=0;
		FirstLineKey=TransADToKeyCode(ADKey[0]);
		SecondLineKey=TransADToKeyCode(ADKey[1]);
		if((FirstLineKey==No_Key)||(SecondLineKey==No_Key))
		{
		     //here get the keycode
		       CurKeyCode= FirstLineKey;
	    	       if ( SecondLineKey!= No_Key) CurKeyCode = SecondLineKey + 13;
		}
		else
		{
			CurKeyCode = Unrecognized_Key;
		}
		//debouce and judge the keycode...
		if(CurKeyCode==PreKeyCode)
		{
			LongShortKeyProcess();  //
		}
		else
		PreKeyCode = CurKeyCode;
		
	}
}

/*--------------------------------------------------------------------------
Routine : TransADToKeyCode
Input   : 
Output  :
Description 
        - Tranfer the AD data to the exact code
--------------------------------------------------------------------------*/ 

unsigned char TransADToKeyCode(unsigned char ADValue)
{
    unsigned char i;
    for(i=1;i<=13 ;i++)
    {
    	if(ADValue < KeyValueTable[i])
	   break;
    }
    if(i>13) i=No_Key;
    return(i);
}

/*--------------------------------------------------------------------------
Routine : KeyTimer
Input   : 
Output  :
Description 
        - Timer for key service
--------------------------------------------------------------------------*/ 

void KeyTimer()
{
	if(KeyReadTimer!=0) KeyReadTimer--;
	if((LongShortKeyDelay!=0xFFFF)&&(LongShortKeyDelay!=0x0000))
		 LongShortKeyDelay--;    //:p
}

/*********************************************
	Function:		LongShortKeyProcess
	Description:	Judge the long short press key
	Write/Modify:	Perry.Liang
	Time:		2004-8-9- 16:32:10
*********************************************/ 

void LongShortKeyProcess()
{
//   Already push key
	KeyCode = CurKeyCode;  
	CurProcessingKey = KeyCode;
	if(CurProcessingKey == Unrecognized_Key)
	{
	   F_UnrecognizeKey = 1;
	   return;
	}
//Here is the short press key, responsible for the down edge of pressing
//Prepare for the long key
	if((LongShortKeyDelay==0)&&(CurProcessingKey!=No_Key)\
		&&(PreProcessingKey==No_Key))
	{
		switch(CurProcessingKey)
		{
		     case Key_VOLUP:
		     case Key_VOLDN:
			 	LongShortKeyDelay = HALF_SECOND;
			 	break;
		     case Key_SEEKUP:
		     case 	Key_SEEKDN:
			 	LongShortKeyDelay = HALF_SECOND;
			 	break;
		     default:
			 	LongShortKeyDelay = TWO_SECOND;
			 	break;
		}
	}
//Continue press or Long press conducting here
	if((PreProcessingKey == CurProcessingKey)&&(CurProcessingKey!=No_Key))
	{
		if(LongShortKeyDelay==0)
		{
			switch(CurProcessingKey)
			{
			  case Key_VOLUP:
			  case Key_VOLDN:
			  	  LongShortKeyDelay = ONE_FOURTH_SECOND;
				  KeyCode = PreProcessingKey;
			  	  break;
			  case Key_SEEKUP:
			  case Key_SEEKDN:
			  	  LongShortKeyDelay = ONE_FOURTH_SECOND;
				  KeyCode = PreProcessingKey |LONGKEY;
			  	  break;
			  default:
			  	  KeyCode = PreProcessingKey | LONGKEY;
				  LongShortKeyDelay = 0xFFFF;
			  	  break;
			}
		}
		else
		   KeyCode = No_Key;
	}

//Judge short release key and long release key//
       if((PreProcessingKey!=No_Key)&&(CurProcessingKey==No_Key))
       {
       	if((LongShortKeyDelay==0xFFFF)||(LongShortKeyDelay==0x0000))
		     KeyCode = PreProcessingKey | LONG_RELEASEKEY;
		else
		     KeyCode = PreProcessingKey | SHORTKEY;

		LongShortKeyDelay = 0;
       }
      
	PreProcessingKey = CurProcessingKey;
	F_UnrecognizeKey =0;
}


/*** (c) 2005  STMicroelectronics ****************** END OF FILE ***/

⌨️ 快捷键说明

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