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

📄 softuart.lst

📁 嵌入式C8051F020源码
💻 LST
📖 第 1 页 / 共 4 页
字号:
C51 COMPILER V6.23a  SOFTUART                                                              04/15/2002 18:18:05 PAGE 1   


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

stmt level    source

   1          //------------------------------------------------------------------------------------
   2          //
   3          // Copyright 2001       Cygnal Integrated Products, Inc.
   4          //
   5          // FILE NAME            : SoftUart.c
   6          // TARGET DEVICE        : C8051F02x
   7          // Modify ON            : 01/10/02
   8          // Modify BY            : WWW.XHL.COM.CN
   9          //
  10          // Software UART program, using PCA as baud rate source.
  11          // PCA module 4 is used as receive baud rate source and START detector.  For START
  12          // detection, module 4 is configured in negative-edge capture mode.  For all other
  13          // SW_UART operations, module 4 is configured as a software timer.  Module match
  14          // interrupts are used to generate the baud rate.  Module 3 generates the transmit
  15          // baud rate in software timer mode. 
  16          // Code assumes an external crystal is attached between the XTAL1 and XTAL2 pins.
  17          // The frequency of the external crystal should be defined in the SYSCLK constant.
  18          // 
  19          // INITIALIZATION PROCEDURE:
  20          // 1) Define SYSCLK according to external crystal frequency.
  21          // 2) Define desired BAUD_RATE.
  22          // 3) Call SW_UART_INIT().
  23          // 4) Set SREN to enable SW_UART receiver.
  24          // 5) Set SES only if user-level interrupt support is desired.
  25          // 6) Call SW_UART_ENABLE().
  26          //
  27          // TO TRANSMIT:
  28          // 1) Poll STXBSY for zero.
  29          // 2) Write data to TDR.
  30          // 3) Set CCF1 to initiate transmit.
  31          // 4) STI will be set upon transmit completion.  An IE7 interrupt is generated if 
  32          //    user-level interrupts are enabled.
  33          //
  34          // TO RECEIVE:
  35          // 1) If in polled mode, poll SRI.  If in interrupt mode, check SRI in IE7 Interrupt
  36          //    Service Routine.
  37          // 2) Read data from RDR.
  38          // 
  39          // P1.2 ->  CEX0 (SW_UART0 TX)
  40          // P1.3 ->  CEX1 (SW_UART0 RX)
  41          // P1.4 ->  CEX0 (SW_UART1 TX)
  42          // P1.5 ->  CEX1 (SW_UART1 RX)
  43          
  44          //
  45          
  46          /*  端口配置
  47                  XBR0 = 0x27;    // XBAR0: Initial Reset Value
  48                  XBR1 = 0x00;    // XBAR1: Initial Reset Value
  49                  XBR2 = 0x44;    // XBAR2: Initial Reset Value
  50              P0MDOUT = 0x1D; // Output configuration for P0 
  51              P1MDOUT = 0x01; // Output configuration for P1 
  52                          // P0.0 = UART TX0        (Push-Pull Output)
  53                          // P0.1 = UART RX0        (Open-Drain Output/Input)
  54                          // P0.2 = SPI Bus SCK     (Push-Pull Output)
  55                          // P0.3 = SPI Bus MISO    (Push-Pull Output)
C51 COMPILER V6.23a  SOFTUART                                                              04/15/2002 18:18:05 PAGE 2   

  56                          // P0.4 = SPI Bus MOSI    (Push-Pull Output)
  57                          // P0.5 = SPI Bus NSS     (Open-Drain Output/Input)
  58                          // P0.6 = SMBus SDA       (Open-Drain Output/Input)
  59                          // P0.7 = SMBus SCL       (Open-Drain Output/Input)
  60          
  61          
  62                          // Port 1
  63          
  64                          // P1.0 = UART TX1        (Push-Pull Output)
  65                          // P1.1 = UART RX1        (Open-Drain Output/Input)
  66                          // P1.2 = PCA CEX0        (Push-Pull Output)
  67                          // P1.3 = PCA CEX1        (Push-Pull Output)
  68                          // P1.4 = PCA CEX2        (Push-Pull Output)
  69                          // P1.5 = PCA CEX3        (Push-Pull Output)
  70                          // P1.6 = GP I/O          (Open-Drain Output/Input)
  71                          // P1.7 = GP I/O          (Open-Drain Output/Input)
  72          */ 
  73          //-----------------------------------------------------------------------------------
  74          // Includes
  75          //-----------------------------------------------------------------------------------
  76          
  77          #include "TestSerial.h"
  78          
  79          #define BAUDRATE2               19200           // 用户定义的SW_UART 波特率
  80          #define UART2_TIMER             SYSCLK/BAUDRATE2/4      //对应一个位时间的PCA 计数值(PCA 配置为对SYSCLK/4 计数)
  81          #define UART2_STARTTIME UART2_TIMER*3/2         // 3/2 位时间用于接收到一个起始位后在起始位边沿之后RX 
  82                                                                                                  //应在一个位时间内保持低电平第一个位采样在下一个位时间的中间开始
  83          
  84          #define BAUDRATE3               19200           
  85          #define UART3_TIMER             SYSCLK/BAUDRATE3/4      
  86          #define UART3_STARTTIME UART3_TIMER*3/2         
  87                                                                                                  
  88          
  89          
  90          #define NULL ((void *) 0L)
  91          #define DB_SENDMAXSIZE2 0xf0
  92          #define DB_RECMAXSIZE2 0xf0
  93          
  94          #define DB_SENDMAXSIZE3 0xf0
  95          #define DB_RECMAXSIZE3 0xf0
  96          
  97          bit FlagRecComm2,SendItComm2;
  98          unsigned char CommSendBufferHead2, CommSendBufferTail2;
  99          unsigned char xdata CommSendBuffer2[DB_SENDMAXSIZE2]; 
 100          unsigned char CommRecBufferHead2, CommRecBufferTail2;
 101          unsigned char xdata CommRecBuffer2[DB_RECMAXSIZE2]; 
 102          
 103          bit FlagRecComm3,SendItComm3;
 104          unsigned char CommSendBufferHead3, CommSendBufferTail3;
 105          unsigned char xdata CommSendBuffer3[DB_SENDMAXSIZE3]; 
 106          unsigned char CommRecBufferHead3, CommRecBufferTail3;
 107          unsigned char xdata CommRecBuffer3[DB_RECMAXSIZE3]; 
 108          
 109          
 110          //-----------------------------------------------------------------------------------
 111          //Global VARIABLES
 112          //-----------------------------------------------------------------------------------
 113          bit     SRI0;                                   // SW_UART Receive Complete Indicator
 114          bit     STI0;                                   // SW_UART Transmit Complete Indicator
 115          bit     STXBSY0;                                // SW_UART TX Busy flag
 116          bit SREN0;                                      // SW_UART RX Enable
 117          bit     SES0;                                   // SW_UART User-level Interrupt Support Enable
C51 COMPILER V6.23a  SOFTUART                                                              04/15/2002 18:18:05 PAGE 3   

 118          sbit SW_RX0 = P1^3;             // SW_UART Receive pin
 119          sbit SW_TX0 = P1^2;             // SW_UART Transmit pin
 120          char TDR0;                                      // SW_UART TX Data Register
 121          char RDR0;                                      // SW_UART RX Data Register (latch)
 122          
 123          bit     SRI1;                                   // SW_UART Receive Complete Indicator
 124          bit     STI1;                                   // SW_UART Transmit Complete Indicator
 125          bit     STXBSY1;                                // SW_UART TX Busy flag
 126          bit SREN1;                                      // SW_UART RX Enable
 127          bit     SES1;                                   // SW_UART User-level Interrupt Support Enable
 128          sbit SW_RX1 = P1^5;             // SW_UART Receive pin
 129          sbit SW_TX1 = P1^4;             // SW_UART Transmit pin
 130          char TDR1;                                      // SW_UART TX Data Register
 131          char RDR1;                                      // SW_UART RX Data Register (latch)
 132          
 133          //------------------------------------------------------------------------------------
 134          // Function PROTOTYPES
 135          //------------------------------------------------------------------------------------
 136          
 137          void    SW_UART_INIT0();                        // SW_UART initialization routine
 138          void    SW_UART_ENABLE0();                      // SW_UART enable routine
 139          void    PCA_ISR();                                      // SW_UART interrupt service routine
 140          void    USER_ISR0(void);                        // SW_UART test interrupt service routine
 141          void    SW_UART_INIT1();                        // SW_UART initialization routine
 142          void    SW_UART_ENABLE1();                      // SW_UART enable routine
 143          void    USER_ISR1(void);                        // SW_UART test interrupt service routine
 144          
 145          
 146          
 147          void ClearCommRecBuffer2(void)
 148          {
 149   1              CommRecBufferHead2=CommRecBufferTail2=0;
 150   1              FlagRecComm2=0;
 151   1      }
 152          
 153          void SendCommChar2(char ch)                     //发送一字节
 154          {
 155   1              CommSendBuffer2[CommSendBufferTail2]=ch;   // 将欲发送的字节存入发送缓冲区
 156   1              CommSendBufferTail2++;                                     // 移动发送缓冲区队列指针
 157   1              if (CommSendBufferTail2==DB_SENDMAXSIZE2)  // 检查循环队列指针
 158   1              {       
 159   2                      CommSendBufferTail2=0;                                  
 160   2              }
 161   1              if (SendItComm2)                                                   // 空闲状态启动发送
 162   1              {        
 163   2                      STXBSY0 = 1;                                               // 发送标志置位
 164   2              TDR0 = CommSendBuffer2[CommSendBufferHead2]; 
 165   2                      CCF0 = 1;                                                          // 强制PCA模块0中断,启动发送
 166   2              }
 167   1              return ;
 168   1      }

⌨️ 快捷键说明

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