C51 COMPILER V9.56.0.0   BSP_UART                                                          03/14/2025 20:27:24 PAGE 1   


C51 COMPILER V9.56.0.0, COMPILATION OF MODULE BSP_UART
OBJECT MODULE PLACED IN .\Objects\bsp_uart.obj
COMPILER INVOKED BY: C:\Keil_v5\C51\BIN\C51.EXE ..\source\bsp\bsp_uart.c LARGE OPTIMIZE(8,SPEED) BROWSE INCDIR(..\source
                    -\app;..\source\bsp) DEBUG OBJECTEXTEND PRINT(.\Listings\bsp_uart.lst) TABS(2) OBJECT(.\Objects\bsp_uart.obj)

line level    source

   1          #include "bsp.h"
   2          
   3          
   4          unsigned char guc_Uartcnt = 0;            //UART计数使用
   5          unsigned char guc_Uartbuf[32] = {0};      //用于存放接收收据
   6          unsigned char guc_UartTxbuf[32] = {0};      //用于存放接收收据
   7          
   8          void bsp_uart_init(void)
   9          {
  10   1          //P1.1 P1.0 RS485 对上位机
  11   1        P1M0 = P1M0&0x0F|0x80;        //P1.1设置为推挽输出  TXD
  12   1        P1M0 = P1M0&0xF0|0x02;        //P1.0设置为上拉输入  RXD
  13   1        TXD_MAP = 0x11;             //TXD1映射P11 
  14   1          
  15   1                                       //采用模拟IO
  16   1        RXD_MAP = 0x10;             //RXD1映射P10   
  17   1        BRTSEL = 0X00;                                //UART1的波特率:00 T4 
  18   1        T4CON = 0x06;                       //T4工作模式：UART1波特率发生器
  19   1        
  20   1        //波特率计算
  21   1        //波特率 = 1/16 * (T4时钟源频率 / 定时器4预分频比) / (65536 - 0xFFCC)
  22   1        //       = 1/16 * ((16000000 / 1) / 52)
  23   1        //     = 19230(误差0.15%)
  24   1      
  25   1        //波特率19200
  26   1        //反推初值 = (65536 - ((T4时钟源频率 / 定时器4预分频比) * (1 / 16)) / 波特率)
  27   1        //       = (65536 - (16000000 * (1 / 16) / 19200))
  28   1        //       = (65536 - 52)
  29   1        //         = FFCC
  30   1        
  31   1        TH4 = 0xFF;
  32   1        TL4 = 0xCC;                          //波特率125000
  33   1        SCON2 = 0x02;                        //8位UART，波特率可变
  34   1        SCON = 0x10;                         //允许串行接收
  35   1        IE |= 0X10;                          //使能串口中断
  36   1        IE |= 0x10;               //使能串口中断
  37   1      }
  38          /***************************************************************************************
  39            * @说明   UART1中断服务函数
  40            * @参数   无
  41            * @返回值 无
  42            * @注     无
  43          ***************************************************************************************/
  44          void UART1_Rpt() interrupt UART1_VECTOR
  45          {
  46   1        if(SCON&0x01)
  47   1        {
  48   2          reset_rs485_recv_timeout();
  49   2          guc_Uartbuf[guc_Uartcnt++] = SBUF;//转存8位串口接收数据
  50   2          if(guc_Uartcnt >= 32)
  51   2          {
  52   3            //SCON &=~ 0x10;        //失能串口接收 
  53   3            guc_Uartcnt=0;
  54   3          }
C51 COMPILER V9.56.0.0   BSP_UART                                                          03/14/2025 20:27:24 PAGE 2   

  55   2          
  56   2          SCON &=~ 0x01;           //收到数据后，清除接收标志
  57   2        }
  58   1      }
  59          void bsp_uart_send_buff(unsigned char len)
  60          {
  61   1        unsigned char i=0;
  62   1        IE &=~ 0x10;                      //失能UART中断
  63   1        for(i=0;i<len;i++)
  64   1         {
  65   2          SBUF = guc_UartTxbuf[i];    //发送8位串口数据
  66   2          while(!(SCON & 0x02));
  67   2           
  68   2          SCON &=~ 0x02;                  //清除发送中断标志位
  69   2         }
  70   1        IE |= 0x10;                       //UART2中断使能
  71   1        guc_Uartcnt = 0;
  72   1        SCON |= 0x10;;                    //UART接收使能  
  73   1      }


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =    197    ----
   CONSTANT SIZE    =   ----    ----
   XDATA SIZE       =     65    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =   ----    ----
   IDATA SIZE       =   ----    ----
   BIT SIZE         =   ----    ----
END OF MODULE INFORMATION.


C51 COMPILATION COMPLETE.  0 WARNING(S),  0 ERROR(S)
