新手上路
- 积分
- 21
- 金钱
- 21
- 注册时间
- 2020-4-15
- 在线时间
- 8 小时
|
10金钱
本帖最后由 Nyyyb112358 于 2022-2-24 21:00 编辑
代码和板子的淘宝的。
如下电路设计
gpio端口初始化为上拉输入
- GPIO_InitTypeDef GPIO_InitStructure;
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC,ENABLE);//使能PORTA,PORTC时钟
-
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;//PC2
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; //设置成上拉输入
- GPIO_Init(GPIOC, &GPIO_InitStructure);//初始化GPIOC2
复制代码 按键扫描函数
- while(!GPIO_ReadInputDataBit(GPIOC,GPIO_Pin_2))//当按键没有被按下时,一直循环
- {
- }
复制代码 根据函数pc2扫描到0的时候一直循环,而代码和电路分别上下拉,会不会有bug呢?
能否系统讲解下上下拉如何配置
|
|