1.数只有1个位
uint8_t buf_index = 0;
while(1)
{
buf_index ^= 1;
}
以上,buf_index在0和1之间来回翻转
2.多位数的特定1个位
void HAL_GPIO_TogglePin(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin)
{
/* Check the parameters */
assert_param(IS_GPIO_PIN(GPIO_Pin));
GPIOx->ODR ^= GPIO_Pin;
}
以上,GPIOx->ODR的GPIO_Pin这一位翻转,其他位不变(可以简单推演得到)
3.总结:与0异或保持,与1异或翻转
参考真值表: