STM32函数GPIO_WriteBit问题
这个函数可以向多个端口写入数据吗?比如:GPIO_WriteBit(GPIOD,GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2,0X11);可以这样写么...
这个函数可以向多个端口写入数据吗?
比如:
GPIO_WriteBit(GPIOD,GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2,0X11);
可以这样写么? 展开
比如:
GPIO_WriteBit(GPIOD,GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2,0X11);
可以这样写么? 展开
展开全部
看stm32 library的资料应该这样写的:
GPIO_WriteBit(GPIOD,GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2,Bit_SET);
这是函数的说明
void GPIO_WriteBit ( GPIO_TypeDef * GPIOx,
uint16_t GPIO_Pin,
BitAction BitVal
)
Parameters:
GPIOx,: where x can be (A..G) to select the GPIO peripheral.
GPIO_Pin,: specifies the port bit to be written. This parameter can be one of GPIO_Pin_x where x can be (0..15).
BitVal,: specifies the value to be written to the selected bit. This parameter can be one of the BitAction enum values:
Bit_RESET: to clear the port pin
Bit_SET: to set the port pin
在stm32f10x_gpio.h
108行
typedef enum
{ Bit_RESET = 0,
Bit_SET
}BitAction;
stm32f10x_gpio.c里的原函数:
void GPIO_WriteBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, BitAction BitVal)
{
/* Check the parameters */
assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
assert_param(IS_GET_GPIO_PIN(GPIO_Pin));
assert_param(IS_GPIO_BIT_ACTION(BitVal));
if (BitVal != Bit_RESET)
{
GPIOx->BSRR = GPIO_Pin;
}
else
{
GPIOx->BRR = GPIO_Pin;
}
}
GPIO_WriteBit(GPIOD,GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2,Bit_SET);
这是函数的说明
void GPIO_WriteBit ( GPIO_TypeDef * GPIOx,
uint16_t GPIO_Pin,
BitAction BitVal
)
Parameters:
GPIOx,: where x can be (A..G) to select the GPIO peripheral.
GPIO_Pin,: specifies the port bit to be written. This parameter can be one of GPIO_Pin_x where x can be (0..15).
BitVal,: specifies the value to be written to the selected bit. This parameter can be one of the BitAction enum values:
Bit_RESET: to clear the port pin
Bit_SET: to set the port pin
在stm32f10x_gpio.h
108行
typedef enum
{ Bit_RESET = 0,
Bit_SET
}BitAction;
stm32f10x_gpio.c里的原函数:
void GPIO_WriteBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, BitAction BitVal)
{
/* Check the parameters */
assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
assert_param(IS_GET_GPIO_PIN(GPIO_Pin));
assert_param(IS_GPIO_BIT_ACTION(BitVal));
if (BitVal != Bit_RESET)
{
GPIOx->BSRR = GPIO_Pin;
}
else
{
GPIOx->BRR = GPIO_Pin;
}
}
更多追问追答
追问
所以结论是只能同时写入1或者同时写入0?
追答
不是啊,GPIO_WriteBit(GPIOD,GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2,Bit_SET);
是对GPIO_Pin_0,GPIO_Pin_1,GPIO_Pin_2写入1,其他位不变
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询