深入理解STM32的BRR寄存器和BSRR寄存器
1、BRR— bit RESET(置0) register //高16位无,低16位置1为0,不能写1
2 、BSRR— bit SET(设置1或0) register //低16位设置1为0
BSRR:用于低16位的作用是让指定的IO口置1;而高16位的作用是让指定的IO口置0。
static void IoUartTxd(IO_UART_STRUCT *uart)
{
if(uart->TxdByteCp < uart->TxdByte)
{
if(uart->TxdBit == 0)//起始位
{
uart->TxdCheck = 0;
uart->TxdPort->BRR = uart->TxdPin; //置低
}
else if(uart->TxdBit <= 8)//数据位
{
if(uart->TxdBuff[uart->TxdByteCp]&(1<<(uart->TxdBit-1)))
{
uart->TxdCheck++; //记录高电平个数
uart->TxdPort->BSRR = uart->TxdPin; //置高
}
else
{
uart->TxdPort->BRR = uart->TxdPin; //置低
}
}
else if(uart->Parity && uart->TxdBit <= 9) //校验位
{
if(uart->Parity == 1){if(uart->TxdCheck%2){uart->TxdPort->BRR = uart->TxdPin;}else{uart->TxdPort->BSRR = uart->TxdPin;}}//奇校验
if(uart->Parity == 2){if(uart->TxdCheck%2){uart->TxdPort->BSRR = uart->TxdPin;}else{uart->TxdPort->BRR = uart->TxdPin;}}//偶校验
}
else //停止位
{
uart->TxdPort->BSRR = uart->TxdPin;
}
if((++uart->TxdBit >= 10 && !uart->Parity) || uart->TxdBit >= 11){uart->TxdBit = 0; uart->TxdByteCp++;}
}
else if(uart->TxdByteCp > 0)
{
uart->TxdByte = 0;
uart->TxdByteCp = 0;
uart->Time->CR1 &= 0xfffe; // 失能
EXTI->IMR |= uart->ExitLine; // 开外部中断
}
}