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

📄 pc_io.lst

📁 Keil uVision2(8052芯片)下用C语言开发的串行菜单结构的简单数据采集系统
💻 LST
字号:
C51 COMPILER V6.21  PC_IO                                                                  01/23/2002 18:05:23 PAGE 1   


C51 COMPILER V6.21, COMPILATION OF MODULE PC_IO
OBJECT MODULE PLACED IN PC_IO.OBJ
COMPILER INVOKED BY: C:\KEIL\C51\BIN\C51.EXE PC_IO.c OPTIMIZE(6,SIZE) BROWSE DEBUG OBJECTEXTEND

stmt level    source

   1          /*------------------------------------------------------------------*-
   2          
   3             PC_IO.C (v1.00)
   4          
   5            ------------------------------------------------------------------
   6          
   7             Core files for simple PC link library for 8051 family
   8          
   9             Uses the UART, and Pins 3.1 (Tx) and 3.0 (Rx) 
  10          
  11             See text for details (Chapter 9).
  12          
  13             COPYRIGHT
  14             ---------
  15          
  16             This code is associated with the book:
  17          
  18             EMBEDDED C by Michael J. Pont 
  19             [Pearson Education, 2002: ISBN: 0-201-79523-X].
  20          
  21             This code is copyright (c) 2001 by Michael J. Pont.
  22           
  23             See book for copyright details and other information.
  24          
  25          -*------------------------------------------------------------------*/
  26          
  27          #include "Main.h"
  28          #include "PC_IO.h"
  29          
  30          // ------ Public variable definitions ------------------------------
  31          
  32          tByte In_read_index_G;      // Data in buffer that has been read 
  33          tByte In_waiting_index_G;   // Data in buffer not yet read
  34          
  35          tByte Out_written_index_G;  // Data in buffer that has been sent 
  36          tByte Out_waiting_index_G;  // Data in buffer not yet sent
  37          
  38          // ------ Private function prototypes ------------------------------
  39          
  40          static void PC_LINK_IO_Send_Char(const char);
  41          
  42          // ------ Private constants ----------------------------------------
  43          
  44          // The receive buffer length
  45          #define RECV_BUFFER_LENGTH 8
  46          
  47          // The transmit buffer length
  48          #define TRAN_BUFFER_LENGTH 50
  49          
  50          #define XON  0x11
  51          #define XOFF 0x13
  52          
  53          // ------ Private variables ----------------------------------------
  54          
  55          static tByte Recv_buffer[RECV_BUFFER_LENGTH];
C51 COMPILER V6.21  PC_IO                                                                  01/23/2002 18:05:23 PAGE 2   

  56          static tByte Tran_buffer[TRAN_BUFFER_LENGTH];
  57          
  58          /*------------------------------------------------------------------*-
  59          
  60            PC_LINK_IO_Update()
  61          
  62            Checks for character in the UART (hardware) receive buffer
  63            Sends next character from the software transmit buffer
  64            
  65          -*------------------------------------------------------------------*/
  66          void PC_LINK_IO_Update(void)  
  67             {
  68   1         // Deal with transmit bytes here
  69   1      
  70   1         // Is there any data ready to send?
  71   1         if (Out_written_index_G < Out_waiting_index_G)
  72   1            {
  73   2            PC_LINK_IO_Send_Char(Tran_buffer[Out_written_index_G]);     
  74   2      
  75   2            Out_written_index_G++;
  76   2            }
  77   1         else
  78   1            {
  79   2            // No data to send - just reset the buffer index
  80   2            Out_waiting_index_G = 0;
  81   2            Out_written_index_G = 0;
  82   2            }
  83   1      
  84   1         // Only dealing with received bytes here
  85   1         // -> Just check the RI flag
  86   1         if (RI == 1)
  87   1            {
  88   2            // Flag only set when a valid stop bit is received, 
  89   2            // -> data ready to be read into the received buffer
  90   2      
  91   2            // Want to read into index 0, if old data has been read
  92   2            // (simple ~circular buffer)
  93   2            if (In_waiting_index_G == In_read_index_G)
  94   2               { 
  95   3               In_waiting_index_G = 0;
  96   3               In_read_index_G = 0;
  97   3               } 
  98   2            
  99   2            // Read the data from UART buffer   
 100   2            Recv_buffer[In_waiting_index_G] = SBUF;
 101   2      
 102   2            if (In_waiting_index_G < RECV_BUFFER_LENGTH)
 103   2               {
 104   3               // Increment without overflowing buffer
 105   3               In_waiting_index_G++;
 106   3               }
 107   2          
 108   2            RI = 0;  // Clear RT flag
 109   2            }
 110   1         }
 111          
 112          /*------------------------------------------------------------------*-
 113          
 114            PC_LINK_IO_Write_Char_To_Buffer()
 115          
 116            Stores a character in the 'write' buffer, ready for 
 117            later transmission
C51 COMPILER V6.21  PC_IO                                                                  01/23/2002 18:05:23 PAGE 3   

 118           
 119          -*------------------------------------------------------------------*/
 120          void PC_LINK_IO_Write_Char_To_Buffer(const char CHARACTER)
 121             {
 122   1         // Write to the buffer *only* if there is space
 123   1         // - No error reporting in this simple library...
 124   1         if (Out_waiting_index_G < TRAN_BUFFER_LENGTH)
 125   1            {
 126   2            Tran_buffer[Out_waiting_index_G] = CHARACTER;
 127   2            Out_waiting_index_G++;     
 128   2            }
 129   1         }
 130          
 131          
 132          /*------------------------------------------------------------------*-
 133          
 134            PC_LINK_IO_Write_String_To_Buffer()
 135          
 136            Copies a (null terminated) string to the character buffer.  
 137            (The contents of the buffer are then passed over the serial link)
 138          
 139            STR_PTR - Pointer to the NULL-TERMINATED string.  
 140          
 141          -*------------------------------------------------------------------*/
 142          void PC_LINK_IO_Write_String_To_Buffer(const char* const STR_PTR)
 143             {
 144   1         tByte i = 0;
 145   1      
 146   1         while (STR_PTR[i] != '\0')
 147   1            {
 148   2            PC_LINK_IO_Write_Char_To_Buffer(STR_PTR[i]);
 149   2            i++;
 150   2            }
 151   1         }
 152          
 153          /*------------------------------------------------------------------*-
 154          
 155            PC_LINK_IO_Get_Char_From_Buffer()
 156          
 157            Retrieves a character from the (software) buffer, if available
 158          
 159            The character from the buffer is returned, or - if no 
 160            data are available - PC_LINK_IO_NO_CHAR is returned.
 161          
 162          -*------------------------------------------------------------------*/
 163          char PC_LINK_IO_Get_Char_From_Buffer(void)
 164             {
 165   1         char Ch = PC_LINK_IO_NO_CHAR;
 166   1      
 167   1         // If there is new data in the buffer
 168   1         if (In_read_index_G < In_waiting_index_G)
 169   1            {
 170   2            Ch = Recv_buffer[In_read_index_G];
 171   2      
 172   2            if (In_read_index_G < RECV_BUFFER_LENGTH)
 173   2               {
 174   3               In_read_index_G++;
 175   3               }
 176   2            }
 177   1         
 178   1         return Ch;
 179   1         }
C51 COMPILER V6.21  PC_IO                                                                  01/23/2002 18:05:23 PAGE 4   

 180          
 181          /*------------------------------------------------------------------*-
 182          
 183            PC_LINK_IO_Send_Char()
 184          
 185            Based on Keil sample code, with added (loop) timeouts.
 186            Implements Xon / Off control.
 187          
 188            Uses on-chip UART hardware.
 189          
 190          -*------------------------------------------------------------------*/
 191          void PC_LINK_IO_Send_Char(const char CHARACTER)
 192             {
 193   1         tLong Timeout1 = 0;
 194   1         tLong Timeout2 = 0;
 195   1      
 196   1         if (CHARACTER == '\n')  
 197   1            {
 198   2            if (RI)  
 199   2               {
 200   3               if (SBUF == XOFF)  
 201   3                  {
 202   4                  Timeout2 = 0;
 203   4                  do {
 204   5                     RI = 0;
 205   5                      
 206   5                     // Wait for uart (with simple timeout)
 207   5                     Timeout1 = 0;
 208   5                     while ((++Timeout1) && (RI == 0));  
 209   5      
 210   5                     if (Timeout1 == 0)
 211   5                        {
 212   6                        // UART did not respond - error
 213   6                        // No error reporting in this simple library...
 214   6                        return;
 215   6                        } 
 216   5      
 217   5                     } while ((++Timeout2) && (SBUF != XON));
 218   4      
 219   4                  if (Timeout2 == 0)
 220   4                     {
 221   5                     // UART did not respond - error
 222   5                     // No error reporting in this simple library...
 223   5                     return;
 224   5                     } 
 225   4      
 226   4                  RI = 0; 
 227   4                  }
 228   3               }
 229   2      
 230   2            Timeout1 = 0;
 231   2            while ((++Timeout1) && (TI == 0));  
 232   2      
 233   2            if (Timeout1 == 0)
 234   2               {
 235   3               // UART did not respond - error
 236   3               // No error reporting in this simple library...
 237   3               return;
 238   3               } 
 239   2      
 240   2            TI = 0;
 241   2            SBUF = 0x0D;  // Output CR  
C51 COMPILER V6.21  PC_IO                                                                  01/23/2002 18:05:23 PAGE 5   

 242   2            }
 243   1        
 244   1         if (RI)  
 245   1            {
 246   2            if (SBUF == XOFF)  
 247   2               {
 248   3               Timeout2 = 0;
 249   3      
 250   3               do {
 251   4                  RI = 0;
 252   4      
 253   4                  // Wait for UART (with simple timeout)
 254   4                  Timeout1 = 0;
 255   4                  while ((++Timeout1) && (RI == 0));  
 256   4      
 257   4                  if (Timeout1 == 0)
 258   4                     {
 259   5                     // UART did not respond - error
 260   5                     // No error reporting in this simple library...
 261   5                     return;
 262   5                     } 
 263   4      
 264   4                  } while ((++Timeout2) && (SBUF != XON));
 265   3            
 266   3               RI = 0; 
 267   3               }
 268   2           }
 269   1      
 270   1         Timeout1 = 0;
 271   1         while ((++Timeout1) && (TI == 0));  
 272   1      
 273   1         if (Timeout1 == 0)
 274   1            {
 275   2            // UART did not respond - error
 276   2            // No error reporting in this simple library...
 277   2            return;
 278   2            } 
 279   1      
 280   1         TI = 0;
 281   1      
 282   1         SBUF = CHARACTER;
 283   1         }
 284          
 285          
 286          /*------------------------------------------------------------------*-
 287            ---- END OF FILE -------------------------------------------------
 288          -*------------------------------------------------------------------*/


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =    442    ----
   CONSTANT SIZE    =   ----    ----
   XDATA SIZE       =   ----    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =     62      12
   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 + -