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

📄 serial.lst

📁 W3100是WIZnet公司专门为以太网互联和嵌入式设备推出的硬件TCP/IP协议栈芯片
💻 LST
字号:
C51 COMPILER V8.02   SERIAL                                                                10/17/2006 16:52:41 PAGE 1   


C51 COMPILER V8.02, COMPILATION OF MODULE SERIAL
OBJECT MODULE PLACED IN SERIAL.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE SERIAL.C BROWSE DEBUG OBJECTEXTEND

line level    source

   1          /*
   2          ###############################################################################
   3          
   4          File Name :  SERIAL.C
   5          
   6          Version : 2.0
   7          
   8          Created :  2001/01/09
   9          
  10          Description :  Definition of functions referring to RS232C 
  11                         All of functions in 'SERIAL.H' are implemented by polling.
  12            
  13          Modified History 
  14          
  15                          Modified : 2002/03/15                              
  16                          Description : Eliminate unused function
  17                          Modified : 2002/10/20
  18                          Description : Version Up
  19                                        Add GetString()
  20                                        Delete PrintLn()
  21                                        Delete Print()
  22                                        Modify PutString() to Re-Entrance function
  23                                        Modify PutStringLn() to Re-Entrance function
  24          ###############################################################################
  25          */
  26          
  27          
  28          
  29          /*
  30          ###############################################################################
  31          Include Part
  32          ###############################################################################
  33          */
  34          
  35          #include <reg51.h>
  36          #include <serial.h>
  37          
  38          
  39          /*
  40          ###############################################################################
  41          Define Part
  42          ###############################################################################
  43          */
  44          
  45          
  46          /*
  47          ###############################################################################
  48          Grobal Variable Definition Part
  49          ###############################################################################
  50          */
  51          
  52          
  53          
  54          
  55          /*
C51 COMPILER V8.02   SERIAL                                                                10/17/2006 16:52:41 PAGE 2   

  56          ###############################################################################
  57          Function Implementation Part
  58          ###############################################################################
  59          */
  60          
  61          /*
  62          Description   :  Initialization of Serial Port(Ex.Baud Rate setting)
  63          Argument      :  
  64          Return Value  :  
  65          Note          :  
  66          */
  67          void InitSerial(void)
  68          {
  69   1              ET1 = 0;                /* TIMER1 INT DISABLE */
  70   1              TMOD = 0x20;
  71   1              PCON |= 0x80;
  72   1      
  73   1      //      TH1 = 0xFC;             /* X2 57600(SMOD=1) at 22.1184 MHZ */
  74   1              TH1 = 0xFD;             /* X2 57600(SMOD=1) at 16 MHZ */
  75   1      
  76   1              TR1 = 1;                /* START THE TIMER1 */  
  77   1              SCON = 0x52;            /* SERIAL MODE 1, REN=1, TI=1, RI=0 */
  78   1      
  79   1              /* Interrupt */
  80   1              ES   = 0;               /* Serial interrupt disable */
  81   1              RI   = 0;               
  82   1              TI   = 0;               
  83   1              while(TI && RI);                
  84   1      }
  85          
  86          /*
  87          Description   :  Output 1 character through Serial Port
  88          Argument      :  byData - character to output(INPUT)
  89          Return Value  :  
  90          Note          :
  91          */
  92          void PutByte(UCHAR byData)
  93          {
  94   1              // Write data into serial-buffer.
  95   1              SBUF = byData; 
  96   1              // Wait till data recording is finished.
  97   1              while(!TI);
  98   1              TI = 0;
  99   1      }
 100          
 101          /*
 102          Description   :  Read 1 character from Serial.
 103          Argument      :  
 104          Return Value  :   Read 1 character from Serial and Return.
 105          Note          :  
 106          */
 107          unsigned char GetByte(void)     
 108          {
 109   1              unsigned char byData;
 110   1              // Wait till data is received.
 111   1              while( !RI );           
 112   1              RI = 0;
 113   1              // Read data.
 114   1              byData = SBUF;          
 115   1              return byData;
 116   1      }
 117          
C51 COMPILER V8.02   SERIAL                                                                10/17/2006 16:52:41 PAGE 3   

 118          
 119          /*
 120          Description   :  Check to input to Serial or not.
 121          Argument      :  
 122          Return Value  :    1)If there's input, then returned value is '1'.
 123                             2)If there's no input, then returned value is '-1'.
 124          Note          :  
 125          */
 126          char IsPressedKey()
 127          {
 128   1              if( RI == 1 ) return 1;
 129   1              return -1;
 130   1      }
 131          
 132          
 133          /*
 134          Description   :  Output 1 Byte Hexadecimal digit to 2Byte ASCII character.  ex) 0x2E --> "2E"
 135          Argument      :   byData - character to output(INPUT)
 136          Return Value  :  
 137          Note          :  
 138          */
 139          void PutHTOA(UCHAR byData)
 140          {
 141   1              // HIGH DIGIT
 142   1              if((byData / 0x10) >= 10)
 143   1                      PutByte('A'+((byData/0x10)%0x0A));
 144   1              else
 145   1                      PutByte('0'+((byData/0x10)%0x0A));
 146   1              // LOW DIGIT
 147   1              if((byData % 0x10) >= 10)
 148   1                      PutByte('A' + ((byData%0x10)%0x0A));
 149   1              else
 150   1                      PutByte('0' + ((byData%0x10)%0x0A));
 151   1      }
 152          
 153          /*
 154          Description   : Output 2 Byte Integer to 4Byte ASCII character ex) 0x12FD --> "12FD"
 155          Argument      :    byData - Integer to output(INPUT)
 156          Return Value  :  
 157          Note          :  
 158          */
 159          void PutITOA(UINT byData)
 160          {
 161   1              PutHTOA(byData / 0x100);
 162   1              PutHTOA(byData % 0x100);
 163   1      }
 164          
 165          /*
 166          Description   :   Output 4 Byte Long to 8Byte ASCII character. ex) 0x001234FF --> "001234FF"
 167          Argument      :  byData - Long to output (INPUT)
 168          Return Value  :  
 169          Note          :  
 170          */
 171          void PutLTOA(unsigned long byData)
 172          {
 173   1              // upper 2 Byte
 174   1              PutITOA(byData / 0x10000);
 175   1              // lower 2 Byte
 176   1              PutITOA(byData % 0x10000);
 177   1      }
 178          
 179          /*
C51 COMPILER V8.02   SERIAL                                                                10/17/2006 16:52:41 PAGE 4   

 180          Description   :  Output to Serial.
 181          Argument      :  Str - Character Stream to output (INPUT)
 182          Return Value  :  
 183          Note          :  Version 2.0
 184          */
 185          void PutString(char *Str) reentrant 
 186          {
 187   1              UINT i;
 188   1              for (i = 0; Str[i] != '\0'; i++)        PutByte(Str[i]);
 189   1      
 190   1      }
 191          
 192          /*
 193          Description   :  Output to Serial and then specific character,'Carrage Return & New Line'.
 194          Argument      : Str -  Character Stream to output(INPUT)
 195          Return Value  :  
 196          Note          :  Version 2.0
 197          */
 198          void PutStringLn(char * Str) reentrant 
 199          {
 200   1              PutString(Str);
 201   1              PutByte(0x0a);
 202   1              PutByte(0x0d);
 203   1      }
 204          
 205          
 206          /*
 207          ###############################################################################
 208          Function Prototype Definition Part
 209          ###############################################################################
 210          */
 211          
 212          #ifndef __SERIAL_UNUSED
              
              /*
              Description   :  Read 1 line string from Serial.
              Argument      :  1 line string to be retuned
              Return Value  :  
              Note          :  Version 2.0
                               if First input character is '!' then display previous command and wait enter.
              */
              void GetString(char* str)
              {
                      char c;
                      char * tsrc = str;
                      char IsFirst = 1;
                      while((c=GetByte()) != 0x0D)
                      {      
                              if(IsFirst && c=='!')
                              {
                                      PutString(str);
                                      while(*str != '\0')str++;
                                      IsFirst = 0;
                                      continue;
                              }
                              if(c == 0x08 && tsrc != str)
                              {
                                      PutByte(0x08);
                                      PutByte(' ');
                                      PutByte(0x08);
                                      str--;
                                      continue;
C51 COMPILER V8.02   SERIAL                                                                10/17/2006 16:52:41 PAGE 5   

                              }
                              else if (c == 0x1B)
                              {
                                      while(tsrc != str)
                                      {
                                              PutByte(0x08);
                                              PutByte(' ');
                                              PutByte(0x08);
                                              str--;
                                      }
                                      IsFirst = 1;
                                      continue;                       
                              }
                              else if( (c < 32 || c > 126) && c != '\t')      continue; 
                              PutByte(c);
                              *str++ = c;
                              IsFirst = 0;
                      }
                      *str = '\0';
                      PutStringLn("");
              }
              
              #endif // end __SERIAL_UNUSED
 265          


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =    293    ----
   CONSTANT SIZE    =   ----    ----
   XDATA SIZE       =   ----    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =   ----       4
   IDATA SIZE       =   ----    ----
   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 + -