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;

}


您好,加打印检查一下是否确实由设置的阈值判断为按键按下。同时可以设置标志位,用标志位的方式去控制LED灯,保证确实是由按键按下行为控制的LED灯,确保引脚不被其他外设复用。


你好我引脚P1.4、1.5只用于触摸按键没有引脚复用情况,我先试一下添加标志位控制


只有登录才能回复,可以选择微信账号登录