关于stm32固件库stm32f10x_gpio.c中uint8_t GPIO_ReadInputDataBit函数试解析

关于stm32固件库stm32f10x_gpio.c中uint8_t GPIO_ReadInputDataBit

代码出自stm32固件库stm32f10x_gpio.c
本人尝试解读上述代码中功能,以图加强学习效果
代码文本:
uint8_t GPIO_ReadInputDataBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin)
{
  uint8_t bitstatus = 0x00;
  
  /* Check the parameters */
  assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
  assert_param(IS_GET_GPIO_PIN(GPIO_Pin)); 
  
  if ((GPIOx->IDR & GPIO_Pin) != (uint32_t)Bit_RESET)
  {
    bitstatus = (uint8_t)Bit_SET;
  }
  else
  {
    bitstatus = (uint8_t)Bit_RESET;
  }
  return bitstatus;
}

上述代码为一个函数,函数功能是读取GPIO端口某一引脚的电平高低
函数参数分别端口号(GPIOA~G)和引脚序号(Pin1~16)
其中,Bit_RESET=0;Bit_SET=1
本人想加深对if ((GPIOx->IDR & GPIO_Pin) != (uint32_t)Bit_RESET)这一句的理解
GPIOx->IDR   是某端口的输入数据寄存器,假设其内容为0x1011 0110
GPIO_pin           是想要读取电平的那个引脚,假设想要读取第二个引脚,则其内容为 0x0000 0010
0x1011 0110&0x0000 0010=0x0000 0010!=Bit_RESET=0,返回值bitstatus=1,
函数成功读取到第二个引脚的电平
0x1011 0110
&
0x0000 0010
=0x0000 0010
形如上
ODR寄存器中的第二位和1相与,会得到ODR寄存器中的值本身
ODR寄存器中的其他位与零相与,都会得到零

初学stm32,妄加分享,如有错误,欢迎指正!
 

*** Using Compiler 'V5.06 update 5 (build 528)', folder: 'E:\STM32\ARM\ARMCC\Bin' Rebuild target 'Target 1' assembling startup_stm32f10x_md.s... compiling stm32f10x_cec.c... compiling misc.c... compiling stm32f10x_bkp.c... compiling stm32f10x_adc.c... compiling stm32f10x_dac.c... compiling stm32f10x_crc.c... compiling stm32f10x_fsmc.c... compiling core_cm3.c... compiling system_stm32f10x.c... compiling stm32f10x_dma.c... compiling stm32f10x_can.c... compiling stm32f10x_dbgmcu.c... compiling stm32f10x_gpio.c... compiling stm32f10x_exti.c... compiling stm32f10x_flash.c... compiling stm32f10x_i2c.c... compiling stm32f10x_iwdg.c... compiling stm32f10x_pwr.c... compiling stm32f10x_rcc.c... compiling stm32f10x_rtc.c... compiling stm32f10x_sdio.c... compiling stm32f10x_spi.c... compiling stm32f10x_usart.c... compiling stm32f10x_wwdg.c... compiling Delay.c... compiling Key.c... compiling LED.c... compiling MySPI.c... compiling OLED.c... compiling W25Q64.c... compiling stm32f10x_tim.c... compiling main.c... User\main.c(2): error: #5: cannot open source input file "gesture/gesture.h": No such file or directory #include "gesture/gesture.h" User\main.c: 0 warnings, 1 error compiling stm32f10x_it.c... compiling gesture.c... gesture.c(41): warning: #550-D: variable "lastTime" was set but never used static uint32_t lastTime = 0; gesture.c(42): warning: #177-D: variable "currentTime" was declared but never referenced uint32_t currentTime = 0; gesture.c: 2 warnings, 0 errors ".\Objects\Project.axf" - 1 Error(s), 2 Warning(s). Target not created. Build Time Elapsed: 00:00:02
最新发布
07-31
*** Using Compiler 'V5.06 update 5 (build 528)', folder: 'E:\app\ARM\ARMCC\Bin' Rebuild target 'Target 1' assembling startup_stm32f10x_md.s... compiling stm32f10x_can.c... compiling stm32f10x_adc.c... compiling system_stm32f10x.c... compiling stm32f10x_dac.c... compiling misc.c... compiling stm32f10x_crc.c... compiling stm32f10x_dbgmcu.c... compiling stm32f10x_bkp.c... compiling stm32f10x_cec.c... compiling stm32f10x_dma.c... compiling stm32f10x_exti.c... compiling stm32f10x_flash.c... compiling core_cm3.c... compiling stm32f10x_fsmc.c... compiling stm32f10x_gpio.c... compiling stm32f10x_i2c.c... compiling stm32f10x_rtc.c... compiling stm32f10x_iwdg.c... compiling stm32f10x_pwr.c... compiling stm32f10x_rcc.c... compiling stm32f10x_sdio.c... compiling stm32f10x_spi.c... compiling stm32f10x_tim.c... compiling stm32f10x_usart.c... compiling oled.c... compiling rtc.c... compiling stm32f10x_it.c... compiling ultrasonic.c... compiling main.c... compiling stm32f10x_wwdg.c... compiling buzzer.c... Hardwore\buzzer.c(71): warning: #223-D: function "TIM_SetPrescaler" declared implicitly TIM_SetPrescaler(BUZZER_TIM, prescaler); Hardwore\buzzer.c: 1 warning, 0 errors compiling delay.c... compiling key.c... compiling mpu6050.c... linking... .\Objects\Project.axf: Error: L6218E: Undefined symbol TIM_SetPrescaler (referred from buzzer.o). .\Objects\Project.axf: Error: L6218E: Undefined symbol Alarm (referred from key.o). .\Objects\Project.axf: Error: L6218E: Undefined symbol alarm_active (referred from key.o). .\Objects\Project.axf: Error: L6218E: Undefined symbol alarm_mode (referred from key.o). Not enough information to list image symbols. Not enough information to list load addresses in the image map. Finished: 2 information, 0 warning and 4 error messages. ".\Objects\Project.axf" - 4 Error(s), 1 Warning(s). Target not created. Build Time Elapsed: 00:00:10
07-09
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值