UINT8 TK_Init( UINT8 channel , UINT8 queryFreq, UINT8 ie )
{
UINT8 i,j;
UINT16 sum;
UINT16 OverTime;
if ( ( channel & BIT6 ) != 0 )/* not include BIT2 & BIT3 */
{
return FAIL;
}
P1_DIR_PU &= ~channel;
P1_MOD_OC &= ~channel;
if( queryFreq != 0 )?
{
TKEY_CTRL |= bTKC_2MS ;
}
/* Get Key_FreeBuf. Save the data in flash or macro define. */
/* DO NOT get Key_FreeBuf in Mass Production. */
for ( i = 0; i < TOUCH_NUM; i++ )
{
sum = 0;
j = SAMPLE_TIMES;
TK_SelectChannel( i );
//TKEY_CTRL |= TK_Code[i];
while( j-- )
{
OverTime = 0;
while( ( TKEY_CTRL & bTKC_IF ) == 0 )
{
if( ++OverTime == 0 )
{
return FAIL;
}
}
sum += TKEY_DAT;/*? */
}
Key_FreeBuf[i] = sum / SAMPLE_TIMES;
}
if( ie != 0 )/* Enable interrupt ?? */
{
IE_TKEY = 1;? ? ?
}
return SUCCESS;
}
/*******************************************************************************
* Function Name? : ABS
* Description? ? : ?ó??????????????????
* Input? ? ? ? ? : a,b
* Output? ? ? ? ?: None
* Return? ? ? ? ?: ??????????
*******************************************************************************/
UINT16 ABS(UINT16 a,UINT16 b)
{
? ? if(a>b)
? ? {
? ? ? ? return (a-b);
? ? }
? ? else
? ? {
? ? ? ? return (b-a);
? ? }
}
/*******************************************************************************
* Function Name? : TK_Measure
* Description? ? : Measure touch input.
* Input? ? ? ? ? : None
* Return? ? ? ? ?: None
*******************************************************************************/
UINT8 TK_Measure( void )
{
UINT8 i,j,num;
UINT16err;
UINT16 sum;
UINT16 OverTime;
for ( i = 0; i < TOUCH_NUM; i++ )
{
sum = 0;
j = SAMPLE_TIMES;
TK_SelectChannel( i );
? ? ? ? num = TK_Code[i] - 1;
while( j-- )
{
OverTime = 0;
while( ( TKEY_CTRL & bTKC_IF ) == 0 )
{
if( ++OverTime == 0 )
{
return FAIL;
}
}
sum += TKEY_DAT;/*? */
}
Key_DataBuf[i] = sum / SAMPLE_TIMES;
err =? ABS(Key_FreeBuf[i],Key_DataBuf[i]);
if( err > DOWM_THRESHOLD_VALUE )? ?
{
if((Press_Flag & (1<
{
YA_ON();
//beep_on();
}
? ? ? ? ? ? ? Press_Flag |= (1< ?
}
else if( err < UP_THRESHOLD_VALUE )? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? //???÷?§???ò????°???
{
if(Press_Flag & (1<
{
Press_Flag &= ~(1<
YA_OFF();
}
}
}
return SUCCESS;
}