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

📄 serial1.lst

📁 采用C8051F020单片机的串口通信应用资料
💻 LST
字号:
C51 COMPILER V6.23a  SERIAL1                                                               04/15/2002 18:18:04 PAGE 1   


C51 COMPILER V6.23a, COMPILATION OF MODULE SERIAL1
OBJECT MODULE PLACED IN Serial1.OBJ
COMPILER INVOKED BY: C:\keil\C51\BIN\c51.exe Serial1.c DB OE

stmt level    source

   1          //串口中断服务程序,仅需做简单调用即可完成串口输入输出的处理
   2          //出入均设有缓冲区,大小可任意设置。
   3          //*************************************************************************
   4          #include "TestSerial.h" 
   5          #define BAUDRATE1               115200          // 用户定义的UART1 波特率
   6          
   7          #define DB_SENDMAXSIZE1 0xf0
   8          #define DB_RECMAXSIZE1 0xf0
   9          
  10          
  11          extern unsigned char Count1ms;
  12          bit FlagRecComm1,SendItComm1;
  13          unsigned char   CommSendBufferHead1, CommSendBufferTail1;
  14          unsigned char   xdata CommSendBuffer1[DB_SENDMAXSIZE1]; 
  15          unsigned char   CommRecBufferHead1, CommRecBufferTail1;
  16          unsigned char   xdata CommRecBuffer1[DB_RECMAXSIZE1]; 
  17          
  18          /*****************************************************************
  19          Function: OpenComm
  20          Description: Sets the serial port up for debug use and resets
  21          the ring buffer pointers to 0.
  22          Parameters: None.
  23          Returns: Nothing.
  24          *****************************************************************/
  25          //                0xfd=19200,0xfa=9600,0xf4=4800,0xe8=2400,0xd0=1200
  26          
  27          void OpenComm1(void) 
  28          {
  29   1      //      SCON1=0xf0;             /*设置串行口1工作于方式3,主从式*/
  30   1                                      /*SM0_1  SM1_1 SM2_1 REN_1  TB8_1 RB8_1 TI_1 RI_1*/
  31   1                                      /* 1       1     1     1      0     0     0    0 */
  32   1                                      /*when SM2_1=1 receice addr    */       
  33   1              TMOD |= 0x20;   /* timer 1 mode 2: 8-Bit reload          */
  34   1              PCON|=0x10;//-->SMOD_1=1;       /*bps double*/                                  
  35   1              CKCON |= 0x10;          // Timer 1 derived from SYSCLK
  36   1              TH1 = -(SYSCLK/BAUDRATE1/16);  //11.0592  ->4800-115200
  37   1              TR1 = 1;                        // Start Timer 1
  38   1              SCON1 = 0x50;                   // Configure UART1 for mode 1, receiver enabled.
  39   1              CommSendBufferHead1=CommSendBufferTail1=0; // set the head and tail to the base of the ring buffer
  40   1              CommRecBufferHead1=CommRecBufferTail1=0; // set the head and tail to the base of the ring buffer
  41   1              SCON1|=0x10;//-->   REN1=1; 
  42   1              EIE2|=0x40; //-->       ES1=1;                  // allow the serial interrupt
  43   1              SendItComm1=1;
  44   1      }
  45          /*
  46          void SendCommAddress1(char ch)
  47          {
  48                  while (CommSendBufferTail1!=CommSendBufferHead1);
  49                  CommSendBufferTail1++;
  50                  if (CommSendBufferTail1==DB_SENDMAXSIZE1)
  51                  {       
  52                          CommSendBufferTail1=0;
  53                  }
  54                  SCON1|=0x08;//-->TB8_1=1;
  55                  SBUF1=ch;
C51 COMPILER V6.23a  SERIAL1                                                               04/15/2002 18:18:04 PAGE 2   

  56          }
  57          */
  58          void SendCommChar1(char ch)
  59          {
  60   1              CommSendBuffer1[CommSendBufferTail1]=ch; // copy the current byte
  61   1              CommSendBufferTail1++;  // move the pointer
  62   1              if (CommSendBufferTail1==DB_SENDMAXSIZE1)
  63   1              {                                               // check for pointer rollover
  64   2                      CommSendBufferTail1=0;
  65   2              }
  66   1              if (SendItComm1)
  67   1              {                                               // if a byte needs to be sent,
  68   2                      SCON1&=0xf7;//-->TB8_1=0;
  69   2                      SBUF1=CommSendBuffer1[CommSendBufferHead1]; // do it
  70   2              }
  71   1              return ;
  72   1      }
  73          /*
  74          bit CommSendBufferIsEmpty1(void)
  75          {
  76                  if (CommSendBufferTail1==CommSendBufferHead1) return true;
  77                  else return false;     
  78          }
  79          
  80          
  81          bit CommRecBufferIsEmpty1(void)
  82          {
  83                  if (CommRecBufferTail1==CommRecBufferHead1) return TRUE;
  84                  else return FALSE;     
  85          }
  86          void ClearCommSendBuffer1(void)
  87          {
  88                  CommSendBufferHead1=CommSendBufferTail1;
  89          }
  90          void ClearCommRecBuffer1(void)
  91          {
  92                  CommRecBufferHead1=CommRecBufferTail1;
  93                  RecDataFlag1=0;
  94          }
  95          */
  96          void SendCommBuffer1(unsigned char *base, unsigned char size) 
  97          {
  98   1      unsigned char i=0;
  99   1              if (size==0) return;
 100   1              while (i<size) 
 101   1              {                                       // copy bytes while the buffer has space and the block has data
 102   2                      CommSendBuffer1[CommSendBufferTail1]=base[i]; // copy the current byte
 103   2                      i++;
 104   2                      CommSendBufferTail1++; // move the pointer
 105   2                      if (CommSendBufferTail1==DB_SENDMAXSIZE1)
 106   2                      {                               // check for pointer rollover
 107   3                              CommSendBufferTail1=0;
 108   3                      }
 109   2              }
 110   1              if (SendItComm1)
 111   1              {                                       // if a byte needs to be sent,
 112   2                      SCON1&=0xf7;//-->TB8_1=0;
 113   2                      SBUF1=CommSendBuffer1[CommSendBufferHead1]; // do it
 114   2              }
 115   1      }
 116          
 117          void SendCommString1(unsigned char *base) 
C51 COMPILER V6.23a  SERIAL1                                                               04/15/2002 18:18:04 PAGE 3   

 118          {
 119   1      unsigned char i=0;
 120   1              if (base[0]==0) return;
 121   1              for (;;)
 122   1              {       
 123   2                      if (base[i]==0) break;
 124   2                      CommSendBuffer1[CommSendBufferTail1]=base[i]; // copy the current byte
 125   2                      CommSendBufferTail1++; // move the pointer
 126   2                      if (CommSendBufferTail1==DB_SENDMAXSIZE1)
 127   2                      {                                               // check for pointer rollover
 128   3                              CommSendBufferTail1=0;
 129   3                      }
 130   2                      i++;
 131   2              }
 132   1              if (SendItComm1)
 133   1              {                                                       // if a byte needs to be sent,
 134   2                      SCON1&=0xf7;//-->TB8_1=0;
 135   2                      SBUF1=CommSendBuffer1[CommSendBufferHead1]; // do it
 136   2              }
 137   1      }
 138          
 139          /*****************************************************************
 140          Function: CommISR
 141          Description: ISR for the serial port. Increments the ring
 142          buffer head pointer and sends out the next byte if
 143          the pointer has not caught the tail pointer.
 144          Parameters: None.
 145          Returns: Nothing.
 146          *****************************************************************/
 147          void CommISR1(void) interrupt 20 
 148          {
 149   1              if (SCON1&0x02);//-->_testbit_(TI_1))
 150   1              {                                                       // check and clear TI
 151   2                      CommSendBufferHead1++;  // advance the head pointer
 152   2                      if (CommSendBufferHead1==DB_SENDMAXSIZE1)
 153   2                      {                                               // watch out for rollover
 154   3                              CommSendBufferHead1=0;
 155   3                      }
 156   2                      if (CommSendBufferHead1!=CommSendBufferTail1)
 157   2                      {                                               // check for more data in the buffer
 158   3                              SBUF1=CommSendBuffer1[CommSendBufferHead1]; // send the next byte
 159   3                              SendItComm1=0;
 160   3                      }
 161   2                      else
 162   2                      {
 163   3                              SendItComm1=1;
 164   3                      }
 165   2              }
 166   1              if (SCON1&0x01) //if (_testbit_(RI_1))  
 167   1              {       
 168   2                      CommRecBuffer1[CommRecBufferTail1]=SBUF1;     //receive data           
 169   2                  CommRecBufferTail1++;
 170   2                  if (CommRecBufferTail1==DB_RECMAXSIZE1)
 171   2                  {
 172   3                      CommRecBufferTail1=0;
 173   3                  }
 174   2                      FlagRecComm1=1;
 175   2              }
 176   1              SCON1&=0xfc;
 177   1      }
 178          
 179          //*************************************
C51 COMPILER V6.23a  SERIAL1                                                               04/15/2002 18:18:04 PAGE 4   

 180          //read one byte from receive buffer
 181          
 182          bit GetCommChar1(unsigned char idata *ch)      
 183          { 
 184   1              if (CommRecBufferTail1==CommRecBufferHead1) return 0;     
 185   1              *ch=CommRecBuffer1[CommRecBufferHead1];
 186   1              CommRecBufferHead1++;
 187   1              if (CommRecBufferHead1==DB_RECMAXSIZE1)
 188   1              {
 189   2                      CommRecBufferHead1=0;
 190   2              }
 191   1              if (CommRecBufferTail1==CommRecBufferHead1) FlagRecComm1=0;
 192   1              return 1;
 193   1      }
 194          
 195          /*
 196          bit SendBufferIsEmpty1(void)
 197          {
 198                  if (CommSendBufferTail1==CommSendBufferHead1) return TRUE;
 199                  else return FALSE;     
 200          }
 201          bit RecBufferIsEmpty1(void)
 202          {
 203                  if (CommRecBufferTail1==CommRecBufferHead1) return TRUE;
 204                  else return FALSE;     
 205          }
 206          */
 207          bit GetCommCharWait1(unsigned char idata *ch,unsigned char T)  //T ms    
 208          { 
 209   1              Count1ms=T;*ch=0;
 210   1              while (Count1ms)
 211   1              {
 212   2                      if (CommRecBufferTail1!=CommRecBufferHead1) break;
 213   2              }
 214   1              if (Count1ms==0) return 0;
 215   1              *ch=CommRecBuffer1[CommRecBufferHead1];
 216   1              CommRecBufferHead1++;
 217   1              if (CommRecBufferHead1==DB_RECMAXSIZE1)
 218   1              {
 219   2                      CommRecBufferHead1=0;
 220   2              }
 221   1              if (CommRecBufferTail1==CommRecBufferHead1) FlagRecComm1=0;
 222   1              return 1;
 223   1      }
 224          
 225          void ClearCommRecBuffer1(void)
 226          {
 227   1              CommRecBufferHead1=CommRecBufferTail1;
 228   1      }
 229          


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =    420    ----
   CONSTANT SIZE    =   ----    ----
   XDATA SIZE       =    480    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =      4       6
   IDATA SIZE       =   ----    ----
   BIT SIZE         =      2    ----
END OF MODULE INFORMATION.


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

⌨️ 快捷键说明

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