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

📄 pc_io.lst

📁 Embedded C 这本书的范例光碟程式
💻 LST
字号:
C51 COMPILER V7.07   PC_IO                                                                 06/12/2006 21:12:14 PAGE 1   


C51 COMPILER V7.07, 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          /*   PC_IO.C (v1.00)   Uses the UART, and Pins 3.1 (Tx) and 3.0 (Rx) */
   2          
   3          #include "Main.h"
   4          #include "PC_IO.h"
   5          
   6          // ------ Public variable definitions ------------------------------
   7          
   8          tByte In_read_index_G;      // Data in buffer that has been read 
   9          tByte In_waiting_index_G;   // Data in buffer not yet read
  10          tByte Out_written_index_G;  // Data in buffer that has been sent 
  11          tByte Out_waiting_index_G;  // Data in buffer not yet sent
  12          
  13          static void PC_LINK_IO_Send_Char(const char);
  14          
  15          #define RECV_BUFFER_LENGTH 8
  16          #define TRAN_BUFFER_LENGTH 70
  17          #define XON  0x11
  18          #define XOFF 0x13
  19          // ------ Private variables ----------------------------------------
  20          static tByte Recv_buffer[RECV_BUFFER_LENGTH];
  21          static tByte Tran_buffer[TRAN_BUFFER_LENGTH];
  22          /*
  23            PC_LINK_IO_Update()
  24            Checks for character in the UART (hardware) receive buffer
  25            Sends next character from the software transmit buffer
  26          */
  27          void PC_LINK_IO_Update(void)  
  28          {
  29   1         if (Out_written_index_G < Out_waiting_index_G)
  30   1         {
  31   2            PC_LINK_IO_Send_Char(Tran_buffer[Out_written_index_G]);     
  32   2            Out_written_index_G++;
  33   2         }
  34   1         else
  35   1         {  // No data to send - just reset the buffer index
  36   2            Out_waiting_index_G = 0;
  37   2            Out_written_index_G = 0;
  38   2         }
  39   1         // Only dealing with received bytes here
  40   1         // -> Just check the RI flag
  41   1         if (RI == 1)
  42   1         {
  43   2            // Flag only set when a valid stop bit is received, 
  44   2            // -> data ready to be read into the received buffer
  45   2            // Want to read into index 0, if old data has been read
  46   2            // (simple ~circular buffer)
  47   2            if (In_waiting_index_G == In_read_index_G)
  48   2            { 
  49   3               In_waiting_index_G = 0;
  50   3               In_read_index_G = 0;
  51   3            } 
  52   2            Recv_buffer[In_waiting_index_G] = SBUF;   // Read the data from UART buffer   
  53   2            if (In_waiting_index_G < RECV_BUFFER_LENGTH)
  54   2            {
  55   3              In_waiting_index_G++;     // Increment without overflowing buffer
C51 COMPILER V7.07   PC_IO                                                                 06/12/2006 21:12:14 PAGE 2   

  56   3            }    
  57   2            RI = 0;  // Clear RT flag
  58   2         }
  59   1      }
  60          
  61          /*
  62            PC_LINK_IO_Write_Char_To_Buffer()
  63            Stores a character in the 'write' buffer, ready for 
  64            later transmission
  65          */
  66          void PC_LINK_IO_Write_Char_To_Buffer(const char CHARACTER)
  67          {
  68   1         // Write to the buffer *only* if there is space
  69   1         // - No error reporting in this simple library...
  70   1         if (Out_waiting_index_G < TRAN_BUFFER_LENGTH)
  71   1         {
  72   2            Tran_buffer[Out_waiting_index_G] = CHARACTER;
  73   2            Out_waiting_index_G++;     
  74   2          }
  75   1      }
  76          
  77          /*
  78            PC_LINK_IO_Write_String_To_Buffer()
  79            Copies a (null terminated) string to the character buffer.  
  80            (The contents of the buffer are then passed over the serial link)
  81            STR_PTR - Pointer to the NULL-TERMINATED string.  
  82          */
  83          void PC_LINK_IO_Write_String_To_Buffer(const char* const STR_PTR)
  84          {
  85   1         tByte i = 0;
  86   1         while (STR_PTR[i] != '\0')
  87   1         {
  88   2            PC_LINK_IO_Write_Char_To_Buffer(STR_PTR[i]);
  89   2            i++;
  90   2         }
  91   1      }
  92          
  93          /*
  94            PC_LINK_IO_Get_Char_From_Buffer()
  95            Retrieves a character from the (software) buffer, if available
  96            The character from the buffer is returned, or - if no 
  97            data are available - PC_LINK_IO_NO_CHAR is returned.
  98          */
  99          
 100          char PC_LINK_IO_Get_Char_From_Buffer(void)
 101          {
 102   1         char Ch = PC_LINK_IO_NO_CHAR;
 103   1         if (In_read_index_G < In_waiting_index_G)// If there is new data in the buffer
 104   1         {
 105   2            Ch = Recv_buffer[In_read_index_G];
 106   2            if (In_read_index_G < RECV_BUFFER_LENGTH){
 107   3               In_read_index_G++;
 108   3            }
 109   2         }
 110   1         return Ch;
 111   1      }
 112          /*
 113            PC_LINK_IO_Send_Char()
 114            Based on Keil sample code, with added (loop) timeouts.
 115            Implements Xon / Off control.
 116            Uses on-chip UART hardware. 
 117          */
C51 COMPILER V7.07   PC_IO                                                                 06/12/2006 21:12:14 PAGE 3   

 118          void PC_LINK_IO_Send_Char(const char CHARACTER)
 119          {
 120   1         tLong Timeout1 = 0;
 121   1         tLong Timeout2 = 0;
 122   1         if (CHARACTER == '\n') {
 123   2            if (RI) {
 124   3               if (SBUF == XOFF) {
 125   4                  Timeout2 = 0;
 126   4                  do {
 127   5                     RI = 0;
 128   5                     Timeout1 = 0;    // Wait for uart (with simple timeout)
 129   5                     while ((++Timeout1) && (RI == 0));  
 130   5                     if (Timeout1 == 0) {
 131   6                      return;
 132   6                     } 
 133   5                  } while ((++Timeout2) && (SBUF != XON));
 134   4                  if (Timeout2 == 0){
 135   5                     return;
 136   5                  } 
 137   4                  RI = 0; 
 138   4               }
 139   3            }
 140   2            Timeout1 = 0;
 141   2            while ((++Timeout1) && (TI == 0));  
 142   2            if (Timeout1 == 0) {
 143   3              return;
 144   3            } 
 145   2            TI = 0;
 146   2            SBUF = 0x0D;  // Output CR  
 147   2          }
 148   1          if (RI){
 149   2            if (SBUF == XOFF){
 150   3               Timeout2 = 0;
 151   3               do {
 152   4                  RI = 0;
 153   4                  Timeout1 = 0;
 154   4                  while ((++Timeout1) && (RI == 0));  
 155   4                  if (Timeout1 == 0){
 156   5                     return;
 157   5                  } 
 158   4               } while ((++Timeout2) && (SBUF != XON));
 159   3               RI = 0; 
 160   3             }
 161   2          }
 162   1         Timeout1 = 0;
 163   1         while ((++Timeout1) && (TI == 0));  
 164   1         if (Timeout1 == 0)      {
 165   2            return;
 166   2         } 
 167   1         TI = 0;
 168   1         SBUF = CHARACTER;
 169   1      }
 170          


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =    442    ----
   CONSTANT SIZE    =   ----    ----
   XDATA SIZE       =   ----    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =     82      12
   IDATA SIZE       =   ----    ----
C51 COMPILER V7.07   PC_IO                                                                 06/12/2006 21:12:14 PAGE 4   

   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 + -