关于电容触摸按键实验

2019-07-20 06:26发布

请教一下,电容触摸按键实验中,当电容放电完,设置TPAD引脚为浮空输入,让电容充电。
同时设置TPAD引脚为输入捕获。
但输入模式和复用模式不是IO引脚的两种模式吗?难道通过设置不带上下拉就可以做到浮空输入了吗?

贴上实例代码

void TPAD_Reset(void)
{               
        GPIO_InitTypeDef GPIO_InitStructure;
       
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;  //PA5
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;//普通输出
        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;        //速度100MHz
        GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; //推挽
        GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN; //下拉
        GPIO_Init(GPIOA,&GPIO_InitStructure); //初始化PA5
         
        GPIO_ResetBits(GPIOA,GPIO_Pin_5);//输出0,放电

        delay_ms(5);
        TIM_ClearITPendingBit(TIM2, TIM_IT_CC1|TIM_IT_Update); //清除中断标志
        TIM_SetCounter(TIM2,0);                //归0
       

        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5; //PA5
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;//复用输出
        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;//速度100MHz
        GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; //推挽
        GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;//不带上下拉
        GPIO_Init(GPIOA,&GPIO_InitStructure); //初始化PA5
       
}

友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。