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; // 开外部中断
  }
}

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值