您的位置:首页 > 教育 > 培训 > 跨境电商怎么做shopee_赣州市人才网_游戏推广对接平台_电商运营培训

跨境电商怎么做shopee_赣州市人才网_游戏推广对接平台_电商运营培训

2025/7/30 1:54:18 来源:https://blog.csdn.net/lyh030105/article/details/146598444  浏览:    关键词:跨境电商怎么做shopee_赣州市人才网_游戏推广对接平台_电商运营培训
跨境电商怎么做shopee_赣州市人才网_游戏推广对接平台_电商运营培训

目录

    • 一、如何分辨GPIO输入使用什么电频
    • 二、输入抖动问题如何消抖
    • 三、示例代码

一、如何分辨GPIO输入使用什么电频

先看原理图
在这里插入图片描述
即可知道他的初始输入状态需要高电平
在这里插入图片描述
判断可知使用上拉输入

二、输入抖动问题如何消抖

  • 电路图中, 按键输入有额外的电容电阻, 是为了消抖

在这里插入图片描述

  • 消抖方案:

    • 硬件消抖1, RC电路

    • 硬件消抖2, 施密特触发器
      在这里插入图片描述

    • 软件消抖: 延时法, 状态法, 统计法

一般软硬件配合

三、示例代码

.h

#ifndef _DRV_BTN_H_
#define _DRC_BTN_H_#include "stm32f10x.h"
#include "drv_systick.h"#define BTN_K1_Port GPIOA
#define BTN_K2_Port GPIOC
#define BTN_K1_Pin GPIO_Pin_0
#define BTN_K2_Pin GPIO_Pin_13/*** @brief 初始化* */
void BTN_Init(void);/*** @brief 按下后谈起* * @param keyport * @param keypin * @return ErrorStatus */
ErrorStatus BTN_IsClicked(GPIO_TypeDef *keyport,uint16_t keypin);/*** @brief 是否按下* * @param keyport * @param keypin * @return ErrorStatus */
ErrorStatus BTN_IsPressed(GPIO_TypeDef *keyport,uint16_t keypin);/*** @brief 是否放开* * @param keyport * @param keypin * @return ErrorStatus */
ErrorStatus BTN_IsReleased(GPIO_TypeDef *keyport,uint16_t keypin);#endif

.c

#include "drv_btn.h"void BTN_Init(void)
{//RCC时钟配置RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOC,ENABLE);GPIO_InitTypeDef BTN_InitStruct;BTN_InitStruct.GPIO_Mode = GPIO_Mode_IPU;BTN_InitStruct.GPIO_Pin = BTN_K1_Pin;GPIO_Init(BTN_K1_Port, &BTN_InitStruct);// 配置K2BTN_InitStruct.GPIO_Pin = BTN_K2_Pin;GPIO_Init(BTN_K2_Port, &BTN_InitStruct);}ErrorStatus BTN_IsClicked(GPIO_TypeDef *keyport,uint16_t keypin)
{uint8_t ret;// 先判断是否按下, 注意按下是高电平ret = GPIO_ReadInputDataBit(keyport, keypin);if (!ret)return ERROR;// 如果当前是按下, 开始等待10msMYSTK_DelayMs(10);// 再次判断ret = GPIO_ReadInputDataBit(keyport, keypin);if (!ret)return ERROR;// 如果仍然是按下, 再等待弹起while (0 != GPIO_ReadInputDataBit(keyport, keypin)){}return SUCCESS;
}ErrorStatus BTN_IsPressed(GPIO_TypeDef *keyport, uint16_t keypin)
{uint8_t ret;ret = GPIO_ReadInputDataBit(keyport, keypin);if (!ret)return ERROR;return SUCCESS;
}ErrorStatus BTN_IsReleased(GPIO_TypeDef *keyport, uint16_t keypin)
{uint8_t ret;ret = GPIO_ReadInputDataBit(keyport, keypin);if (ret)return ERROR;return SUCCESS;
}

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com