GPIO_SetBits 和 GPIO_WriteBit有什么差别吗

[复制链接]
19421|4
 楼主| cd4066 发表于 2012-5-29 11:45 | 显示全部楼层 |阅读模式
GPIO_SetBits 和 GPIO_WriteBit有什么差别吗?
看说明,只要参数对,二合可以达到同样的效果
香水城 发表于 2012-5-29 11:58 | 显示全部楼层
看看库里的源码就知道了:

  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. GPIOx->BSRR = GPIO_Pin;
  14. }

  15. /**
  16. * @brief Clears the selected data port bits.
  17. * @param GPIOx: where x can be (A..G) to select the GPIO peripheral.
  18. * @param GPIO_Pin: specifies the port bits to be written.
  19. * This parameter can be any combination of GPIO_Pin_x where x can be (0..15).
  20. * @retval None
  21. */
  22. void GPIO_ResetBits(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin)
  23. {
  24. /* Check the parameters */
  25. assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
  26. assert_param(IS_GPIO_PIN(GPIO_Pin));

  27. GPIOx->BRR = GPIO_Pin;
  28. }

  29. /**
  30. * @brief Sets or clears the selected data port bit.
  31. * @param GPIOx: where x can be (A..G) to select the GPIO peripheral.
  32. * @param GPIO_Pin: specifies the port bit to be written.
  33. * This parameter can be one of GPIO_Pin_x where x can be (0..15).
  34. * @param BitVal: specifies the value to be written to the selected bit.
  35. * This parameter can be one of the BitAction enum values:
  36. * @arg Bit_RESET: to clear the port pin
  37. * @arg Bit_SET: to set the port pin
  38. * @retval None
  39. */
  40. void GPIO_WriteBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, BitAction BitVal)
  41. {
  42. /* Check the parameters */
  43. assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
  44. assert_param(IS_GET_GPIO_PIN(GPIO_Pin));
  45. assert_param(IS_GPIO_BIT_ACTION(BitVal));

  46. if (BitVal != Bit_RESET)
  47. {
  48. GPIOx->BSRR = GPIO_Pin;
  49. }
  50. else
  51. {
  52. GPIOx->BRR = GPIO_Pin;
  53. }
  54. }
 
hsbjb 发表于 2012-5-29 15:17 | 显示全部楼层
比较一下库里的源码
无冕之王 发表于 2012-5-29 15:30 | 显示全部楼层
对比一下香主给的源码,区别应该很明显了
拿起书本 发表于 2012-5-29 22:12 | 显示全部楼层
GPIO_WriteBit与GPIO_SetBits,前面个是对一个io口进行写操作可以是写0或者写1,而后面一个可以对多个io口同时进行置位1
您需要登录后才可以回帖 登录 | 注册

本版积分规则

40

主题

113

帖子

0

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