首页 > 代码库 > STM32 常用GPIO操作函数记录

STM32 常用GPIO操作函数记录

STM32读具体GPIOx的某一位是1还是0

 1 /** 2   * @brief  Reads the specified input port pin. 3   * @param  GPIOx: where x can be (A..G) to select the GPIO peripheral. 4   * @param  GPIO_Pin:  specifies the port bit to read. 5   *   This parameter can be GPIO_Pin_x where x can be (0..15). 6   * @retval The input port pin value. 7   */ 8 uint8_t GPIO_ReadInputDataBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin) 9 {10   uint8_t bitstatus = 0x00;11   12   /* Check the parameters */13   assert_param(IS_GPIO_ALL_PERIPH(GPIOx));14   assert_param(IS_GET_GPIO_PIN(GPIO_Pin)); 15   16   if ((GPIOx->IDR & GPIO_Pin) != (uint32_t)Bit_RESET)17   {18     bitstatus = (uint8_t)Bit_SET;19   }20   else21   {22     bitstatus = (uint8_t)Bit_RESET;23   }24   return bitstatus;25 }

 

STM32 常用GPIO操作函数记录