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

📄 uart.lst

📁 mifarea卡程序mifarea卡程序mifarea卡程序
💻 LST
字号:
C51 COMPILER V8.00   UART                                                                  04/23/2009 15:56:14 PAGE 1   


C51 COMPILER V8.00, COMPILATION OF MODULE UART
OBJECT MODULE PLACED IN .\out_sst89e564\uart.obj
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE source\uart.c LARGE BROWSE ORDER NOAREGS DEBUG OBJECTEXTEND PRINT(.\uart.ls
                    -t) OBJECT(.\out_sst89e564\uart.obj)

line level    source

   1          //////////////////////////////////////////////
   2          //      uart.c                                                                  //
   3          //      设置波特率(需要晶振频率支持)                  //
   4          //  晶振频率:11m0592,12m0,18m0,24m0            //
   5          //  design by: 刘俐训                       //
   6          //////////////////////////////////////////////
   7          
   8          #include<reg52.h>
   9          #include"uart.h"
  10          #include"stimer.h"
  11          #include"ascii.h"
  12          #include <v51rx2.h>      
  13          
  14          #include "intrsc.h"       
  15          
  16          #ifndef BUF_SIZE
  17          #define BUF_SIZE        32
  18          #define OBUF_SIZE       16
  19          #endif
  20          
  21          #ifndef enable
              #define enable()   EA=1
              #define disable()  EA=0
              #endif
  25          
  26          #define StartSend() TI=1
  27          
  28          static bit SbufWorking=0;
  29          
  30          static unsigned char idata InputBuf[BUF_SIZE];
  31          static unsigned char xdata OutputBuf[OBUF_SIZE];
  32          static unsigned int InputOutTime=0;
  33          static unsigned int OutputOutTime=0;
  34          
  35          #if (BUF_SIZE>256)
              static unsigned int data IBufGetIdx=0;
              static unsigned int data IBufPutIdx=0;
              #else
  39          static unsigned char data IBufGetIdx=0;
  40          static unsigned char data IBufPutIdx=0;
  41          #endif
  42          #if (OBUF_SIZE>256)
              static unsigned int data OBufGetIdx=0;
              static unsigned int data OBufPutIdx=0;
              #else
  46          static unsigned char data OBufGetIdx=0;
  47          static unsigned char data OBufPutIdx=0;
  48          #endif
  49          
  50          static bit PutInputData( void );
  51          static int GetInputData( void );
  52          static bit PutOutputData( unsigned char abyte );
  53          static bit GetOutputData( void );
  54          #define EnterCrtcl()  ES = 0
C51 COMPILER V8.00   UART                                                                  04/23/2009 15:56:14 PAGE 2   

  55          #define LeaveCrtcl()  ES = 1
  56          
  57          void InterruptCom(void) interrupt SIO_VECTOR using 1
  58          {
  59   1              if(RI)
  60   1              {
  61   2                      RI=0;
  62   2                      PutInputData();
  63   2              }
  64   1              
  65   1              if(TI)
  66   1              {
  67   2                      TI=0;
  68   2                      GetOutputData();
  69   2              }
  70   1      }
  71          
  72          bit PutInputData( void )
  73          {
  74   1              #if (BUF_SIZE!=256)
  75   1                      if( IBufGetIdx ==0 )
  76   1                      {
  77   2                              if( IBufPutIdx == BUF_SIZE-1 )
  78   2                                  return 0;
  79   2                      }
  80   1              #endif
  81   1              
  82   1              if(IBufPutIdx == IBufGetIdx-1)
  83   1              {
  84   2                      return 0;
  85   2              }
  86   1              InputBuf[IBufPutIdx] = SBUF;
  87   1              IBufPutIdx++;
  88   1              
  89   1              #if (BUF_SIZE != 256)
  90   1                      if(IBufPutIdx==BUF_SIZE)
  91   1                          IBufPutIdx=0;
  92   1              #endif
  93   1              
  94   1              return 1;
  95   1      }
  96          
  97          int GetInputData( void )
  98          {
  99   1              unsigned char tmp; 
 100   1              
 101   1          EnterCrtcl();
 102   1              if( IBufGetIdx == IBufPutIdx )
 103   1              {
 104   2                  LeaveCrtcl();
 105   2                      return -1;
 106   2              }
 107   1      
 108   1              tmp = InputBuf[IBufGetIdx++];
 109   1      
 110   1              #if (BUF_SIZE != 256)
 111   1                      if(IBufGetIdx==BUF_SIZE)
 112   1                              IBufGetIdx=0;
 113   1              #endif
 114   1              
 115   1              LeaveCrtcl();
 116   1              return tmp;
C51 COMPILER V8.00   UART                                                                  04/23/2009 15:56:14 PAGE 3   

 117   1      }
 118          
 119          bit GetOutputData( void )
 120          {
 121   1              if( OBufPutIdx == OBufGetIdx )
 122   1              {
 123   2                      SbufWorking=0;
 124   2                      return 0;
 125   2              }
 126   1      
 127   1              SBUF = OutputBuf[OBufGetIdx];
 128   1              OBufGetIdx++;
 129   1              #if (OBUF_SIZE != 256)
 130   1                      if(OBufGetIdx==OBUF_SIZE)
 131   1                          OBufGetIdx=0;
 132   1              #endif
 133   1          return 1;
 134   1      }
 135          
 136          bit PutOutputData( unsigned char abyte )
 137          {
 138   1              EnterCrtcl();
 139   1              #if (OBUF_SIZE!=256)
 140   1                      if( OBufGetIdx ==0 )
 141   1                              if( OBufPutIdx == OBUF_SIZE-1 )
 142   1                              {
 143   2                                  LeaveCrtcl();
 144   2                                  return 0;
 145   2                              }
 146   1              #endif
 147   1              
 148   1              if( OBufPutIdx == OBufGetIdx-1 )
 149   1              {
 150   2                  LeaveCrtcl();
 151   2                  return 0;
 152   2              }
 153   1              
 154   1              OutputBuf[OBufPutIdx++] = abyte;
 155   1              
 156   1              #if (OBUF_SIZE != 256)
 157   1                      if(OBufPutIdx==OBUF_SIZE)
 158   1                          OBufPutIdx=0;
 159   1              #endif
 160   1      
 161   1              if(!SbufWorking)
 162   1              {
 163   2                      SbufWorking = 1;
 164   2                      StartSend();
 165   2              }
 166   1              LeaveCrtcl();
 167   1              
 168   1              return 1;
 169   1      }
 170          
 171          void ComOpen(unsigned long clk, unsigned long baudrate)
 172          {       
 173   1              unsigned char tmp;
 174   1              
 175   1              if(baudrate >= 9000)
 176   1              {
 177   2                  PCON |= SMOD_;
 178   2                  tmp = (clk >> 4) / baudrate;
C51 COMPILER V8.00   UART                                                                  04/23/2009 15:56:14 PAGE 4   

 179   2              }
 180   1              else
 181   1              {
 182   2                  PCON &= ~SMOD_;
 183   2                  tmp = (clk >> 5) / baudrate;
 184   2              }
 185   1                  
 186   1          SetIntPri(SIO_VECTOR, 1);
 187   1          
 188   1              TI = RI = 0;
 189   1              SCON =  0x50;
 190   1              TMOD &= 0x0F;
 191   1              TMOD |= 0x20;
 192   1              TR1 = 1;
 193   1              TH1 = 256 - tmp;
 194   1              enable();
 195   1              ES=1;
 196   1      }
 197          
 198          unsigned int ComWrite( unsigned char *buf, unsigned int len )
 199          {
 200   1              unsigned int i;
 201   1              unsigned int starttime;
 202   1              
 203   1              for(i=0; i<len; i++)
 204   1              {
 205   2              starttime = GetTickCount();
 206   2                      while( !PutOutputData(buf[i]) )
 207   2                      {
 208   3                              if(OutputOutTime==0 || (GetTickCount() - starttime >= OutputOutTime))
 209   3                                  return i;
 210   3                      }
 211   2              }
 212   1              return i;
 213   1      }
 214          
 215          unsigned int ComRead( unsigned char *buf, unsigned int len )
 216          {
 217   1              unsigned int i;
 218   1              unsigned int starttime;
 219   1              int tmp;
 220   1      
 221   1              for(i=0; i<len; i++)
 222   1              {
 223   2              starttime = GetTickCount();
 224   2                      while((tmp = GetInputData()) < 0)
 225   2                      {
 226   3                              if(InputOutTime==0 || (GetTickCount() - starttime >= InputOutTime))
 227   3                                      return i;
 228   3                      }
 229   2                      buf[i] = (unsigned char)tmp;
 230   2              }
 231   1              return i;
 232   1      }
 233          
 234          void ComSetTimeOut(unsigned int iouttime, unsigned int oouttime)
 235          {
 236   1              InputOutTime=iouttime;
 237   1              OutputOutTime=oouttime;
 238   1      }
 239          
 240          unsigned int ComIBufBytesTell( void )
C51 COMPILER V8.00   UART                                                                  04/23/2009 15:56:14 PAGE 5   

 241          {
 242   1              unsigned int ii;
 243   1      
 244   1              if(IBufPutIdx>=IBufGetIdx)
 245   1              {
 246   2                      ii=(unsigned int)(IBufPutIdx-IBufGetIdx);
 247   2              }
 248   1              else
 249   1              {
 250   2                      ii=(unsigned int)(BUF_SIZE-IBufGetIdx+IBufPutIdx);
 251   2              }
 252   1              return ii;
 253   1      }
 254          
 255          void ComClear( unsigned char flag )
 256          {
 257   1              if( flag & 0x01 ) IBufGetIdx = IBufPutIdx;
 258   1              if( flag & 0x02 ) OBufGetIdx = OBufPutIdx;
 259   1      }


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =    741    ----
   CONSTANT SIZE    =   ----    ----
   XDATA SIZE       =     20      29
   PDATA SIZE       =   ----    ----
   DATA SIZE        =      4    ----
   IDATA SIZE       =     32    ----
   BIT SIZE         =      1    ----
END OF MODULE INFORMATION.


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

⌨️ 快捷键说明

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