这些函数有何区别

[复制链接]
3075|6
 楼主| dxf17043206 发表于 2011-5-2 22:31 | 显示全部楼层 |阅读模式
请问这两个函数有哪些区别,
  void GPIO_SetBits(GPIO_TypeDef* GPIOx, u16 GPIO_Pin)和
  void GPIO_WriteBit(GPIO_TypeDef* GPIOx, u16 GPIO_Pin, BitAction BitVal)
我感觉不出来有说明不一样的。
 楼主| dxf17043206 发表于 2011-5-2 22:32 | 显示全部楼层
并且这两个函数都是对同一个寄存器操作,为什么要用到两个函数,一个不就可以了吗
again_gyf 发表于 2011-5-2 22:33 | 显示全部楼层
Set=1
Write=0 or 1
趴趴熊 发表于 2011-5-3 08:03 | 显示全部楼层
明显参数不一样 - -
hgjinwei 发表于 2011-5-3 10:25 | 显示全部楼层
自己看源码嘛,这不一清二楚了吗?

  1. /**
  2.   * @brief  Sets the selected data port bits.
  3.   * @param  GPIOx: where x can be (A..G) to select the GPIO peripheral.
  4.   * @param  GPIO_Pin: specifies the port bits to be written.
  5.   *   This parameter can be any combination of GPIO_Pin_x where x can be (0..15).
  6.   * @retval None
  7.   */
  8. void GPIO_SetBits(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin)
  9. {
  10.   /* Check the parameters */
  11.   assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
  12.   assert_param(IS_GPIO_PIN(GPIO_Pin));
  13.   
  14.   GPIOx->BSRR = GPIO_Pin;
  15. }

  1. /**
  2.   * @brief  Sets or clears the selected data port bit.
  3.   * @param  GPIOx: where x can be (A..G) to select the GPIO peripheral.
  4.   * @param  GPIO_Pin: specifies the port bit to be written.
  5.   *   This parameter can be one of GPIO_Pin_x where x can be (0..15).
  6.   * @param  BitVal: specifies the value to be written to the selected bit.
  7.   *   This parameter can be one of the BitAction enum values:
  8.   *     @arg Bit_RESET: to clear the port pin
  9.   *     @arg Bit_SET: to set the port pin
  10.   * @retval None
  11.   */
  12. void GPIO_WriteBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, BitAction BitVal)
  13. {
  14.   /* Check the parameters */
  15.   assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
  16.   assert_param(IS_GET_GPIO_PIN(GPIO_Pin));
  17.   assert_param(IS_GPIO_BIT_ACTION(BitVal));
  18.   
  19.   if (BitVal != Bit_RESET)
  20.   {
  21.     GPIOx->BSRR = GPIO_Pin;
  22.   }
  23.   else
  24.   {
  25.     GPIOx->BRR = GPIO_Pin;
  26.   }
  27. }
banhushui 发表于 2011-5-3 12:37 | 显示全部楼层
确实有时看看源码一切都明白了:P
 楼主| dxf17043206 发表于 2011-5-3 21:23 | 显示全部楼层
呵呵,谢谢诸位。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

9

主题

16

帖子

1

粉丝
快速回复 在线客服 返回列表 返回顶部