我正试着在我的新的核心板上运行一个简单的程序,
我制作这个程序是为了当我按下用户的按钮(蓝色的)时,打开和关闭绿色的led,
#include "stm32f4xx.h"
#include "stm32f4xx_nucleo.h"
#include "system_stm32f4xx.h"
#include "stm32f4xx_hal_gpio.h"
#include "stm32f4xx_hal_rcc.h"
GPIO_InitTypeDef GPIO_InitStructure;
int main(void) {
HAL_Init();
__GPIOA_CLK_ENABLE();
GPIO_InitStructure.Pin = GPIO_PIN_5;
GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStructure.Pull = GPIO_PULLUP;
GPIO_InitStructure.Speed = GPIO_SPEED_HIGH;
HAL_GPIO_Init(GPIOA, &GPIO_InitStructure);
__GPIOC_CLK_ENABLE();
GPIO_InitStructure.Pin = GPIO_PIN_13;
GPIO_InitStructure.Mode = GPIO_MODE_INPUT;
GPIO_InitStructure.Pull = GPIO_PULLDOWN;
GPIO_InitStructure.Speed = GPIO_SPEED_FAST;
HAL_GPIO_Init(GPIOC, &GPIO_InitStructure);
while (1) {
if (HAL_GPIO_ReadPin(GPIOC, GPIO_PIN_13)) {
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, GPIO_PIN_RESET);
} else {
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, GPIO_PIN_SET);
}
}
}但是我得到了错误的结果:
程序似乎只在第一次运行时才检查蓝色按钮的状态,我不知道为什么,
如果您对问题的来源有任何想法,或者您有一个正在运行的程序来切换led按钮,请帮助我。
发布于 2019-11-21 19:49:17
每当您下载代码到您的板上,微停留在重置模式,这就是为什么您的代码似乎无法工作。一旦您按下黑色重置按钮,它将运行您的代码从main(),一切都将运行良好。
只要记得每次你在你的微电脑上闪现新代码时都要重置。
https://stackoverflow.com/questions/29496072
复制相似问题