void GM_Init(void) { // Enable the clock for GPIOB peripheral RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);

// Configure the GPIO pin 13 of port B as input with internal pull-up resistor
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);

}

uint8_t GM_GetNum(void) { // Read the input data of GPIO pin 13 of port B and return the value return GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_13); }

Explanation:

  • The function GM_Init() initializes the GPIO pin 13 of port B as an input pin with an internal pull-up resistor using the STM32F103C8T6 MCU's GPIO peripheral. This pin is commonly used to read a push-button input or a switch input.
  • The function GM_GetNum() reads the input data of GPIO pin 13 of port B and returns the value. This function is commonly used to get the status of a push-button or a switch input. The value returned is either 0 or 1, indicating if the input is low or high, respectively
void GM_Initvoid	RCC_APB2PeriphClockCmdRCC_APB2Periph_GPIOB ENABLE;		GPIO_InitTypeDef GPIO_InitStructure;	GPIO_InitStructureGPIO_Mode = GPIO_Mode_IPU;	GPIO_InitStructureGPIO_Pin = GPIO_Pin_13;ÅäÖÃGPIO

原文地址: https://www.cveoy.top/t/topic/g6U4 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录