⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 uart.lst

📁 16C554VX1128MAX4359-MAX4456P89LPC952 驱动开发
💻 LST
字号:
C51 COMPILER V8.02   UART                                                                  05/23/2008 11:50:50 PAGE 1   


C51 COMPILER V8.02, COMPILATION OF MODULE UART
OBJECT MODULE PLACED IN Uart.OBJ
COMPILER INVOKED BY: D:\软件安装路径\C51\BIN\C51.EXE Uart.c BROWSE DEBUG OBJECTEXTEND

line level    source

   1          #include <reg952.h>
   2          #include <string.h>
   3          #include "uart.h"
   4          
   5          #define TBUF_SIZE 64
   6          #define RBUF_SIZE 64
   7          #define SIZEMASK  0x3F
   8          #define INT_DISABLE      EA=0
   9          #define INT_ENABLE       EA=1
  10          
  11          
  12          static idata unsigned char tbuf[TBUF_SIZE];
  13          static idata unsigned char rbuf[RBUF_SIZE];
  14          static  unsigned char t_in = 0;
  15          static  unsigned char t_out = 0;
  16          static  unsigned char t_disabled = 0;
  17          static  unsigned char r_in = 0;
  18          static  unsigned char r_out = 0;
  19          
  20          /*串口中断服务*/
  21          static void com_isr(void) interrupt 4 using 1 
  22          {
  23   1              EA=0;
  24   1              if (RI_0 != 0)
  25   1              {//接收处理
  26   2                      RI_0= 0;
  27   2                      if (((r_in +1)&SIZEMASK)!=r_out)
  28   2                      {
  29   3                              rbuf[r_in]=S0BUF;
  30   3                              r_in=(r_in+1)&SIZEMASK;
  31   3                      }
  32   2              }
  33   1              if (TI_0!=0)
  34   1              {//发送处理
  35   2                      TI_0=0;
  36   2                      if (t_in!=t_out)
  37   2                      {
  38   3                              S0BUF = tbuf[t_out];
  39   3                              t_out=(t_out+1)&SIZEMASK;
  40   3                      }
  41   2                      else
  42   2                              t_disabled =1;
  43   2              }
  44   1              EA=1;
  45   1      }
  46          
  47          /*字符发送函数*/
  48          
  49          int com_putchar(unsigned char c) reentrant
  50          {
  51   1              INT_DISABLE;
  52   1              if ((TBUF_SIZE-com_tbuflen())<=2) //若缓冲区满,则返回出错标志
  53   1              {
  54   2                      INT_ENABLE;
  55   2                      return (-1);
C51 COMPILER V8.02   UART                                                                  05/23/2008 11:50:50 PAGE 2   

  56   2              }
  57   1              tbuf[t_in] = c;
  58   1              t_in=(t_in+1)&SIZEMASK;
  59   1              if (t_disabled)
  60   1              {
  61   2                      t_disabled=0;
  62   2                      TI_0=1;
  63   2              }
  64   1              INT_ENABLE;
  65   1              return (0);
  66   1      }
  67          
  68          
  69          /*字符接受函数*/
  70          int com_getchar(void)
  71          {
  72   1              int c;
  73   1              if (com_rbuflen()==0)
  74   1                      return -1;
  75   1              INT_DISABLE;
  76   1              c=rbuf[r_out];
  77   1              r_out=(r_out+1)&SIZEMASK;
  78   1              INT_ENABLE;
  79   1              return (c);
  80   1      }
  81          
  82          /*计算接收缓冲器长度*/
  83          unsigned char com_rbuflen(void)
  84          {
  85   1              return ((r_in -r_out)&SIZEMASK);
  86   1      }
  87          
  88          
  89          unsigned char com_tbuflen(void)
  90          {
  91   1              return ((t_in-t_out)&SIZEMASK);
  92   1      }
  93          
  94          //-------------------------
  95          //初始化串口
  96          //-------------------------
  97          void UART0_Init()
  98          {
  99   1              t_in=0;         //清零发送缓冲区
 100   1              t_out=0;        
 101   1              t_disabled=1;   //禁止发送
 102   1              r_in=0;
 103   1              r_out=0;
 104   1      
 105   1              PCON=0x00;
 106   1              S0CON=0x50;  //使能接收选择串口模式1即8位uart
 107   1      //      S0STAT=0x60;   //选择独立的Tx/Rx中断,并禁止双缓冲
 108   1              S0STAT=0x40;   //选择组合的Tx/Rx中断,并禁止双缓冲
 109   1      //      BRGCON_0 =0x02;  //使能BRG,且选择波特率发生器0 用于产生UART0 模式1 的波特率               
 110   1              BRGR0_0=0xb0;   //57600baud @ 11.0592MHz        波特率=CCLK/((BRGR1_n, BRGR0_n)+16)
 111   1              BRGR1_0=0x00;
 112   1      //      BRGR0_0=11059200/baudrate-16
 113   1      
 114   1      //      BRGR0_0=0x50;   //115200baud @ 11.0592MHz       波特率=CCLK/((BRGR1_n, BRGR0_n)+16)
 115   1      //      BRGR1_0=0x00;
 116   1              BRGCON_0 =0x03;
 117   1              EA=1; //使能中断
C51 COMPILER V8.02   UART                                                                  05/23/2008 11:50:50 PAGE 3   

 118   1              ESR=1;  //ESR=Enable Serial Recieve
 119   1              EST=1;  //EST=Enable Serial Transmit
 120   1      }


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =    219    ----
   CONSTANT SIZE    =   ----    ----
   XDATA SIZE       =   ----    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =      5    ----
   IDATA SIZE       =    128    ----
   BIT SIZE         =   ----    ----
END OF MODULE INFORMATION.


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

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -