CH554觸摸按鍵TIN0,TIN1正常按下LED亮抬起LED滅,TIN2,3只有第一次觸摸按下LED燈亮抬起LED燈不滅

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;

}


您好,加打印檢查一下是否確實(shí)由設(shè)置的閾值判斷為按鍵按下。同時可以設(shè)置標(biāo)志位,用標(biāo)志位的方式去控制LED燈,保證確實(shí)是由按鍵按下行為控制的LED燈,確保引腳不被其他外設(shè)復(fù)用。


你好我引腳P1.4、1.5只用于觸摸按鍵沒有引腳復(fù)用情況,我先試一下添加標(biāo)志位控制


只有登錄才能回復(fù),可以選擇微信賬號登錄

国产91精品新入口,国产成人综合网在线播放,九热这里只有精品,本道在线观看,美女视频a美女视频,韩国美女激情视频,日本美女pvp视频