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

📄 rs232.lst

📁 世纪民生公司的带网络功能的单片机CS6209开发http服务器的演示源代码。
💻 LST
📖 第 1 页 / 共 2 页
字号:
C51 COMPILER V7.50   RS232                                                                 10/12/2006 15:31:40 PAGE 1   


C51 COMPILER V7.50, COMPILATION OF MODULE RS232
OBJECT MODULE PLACED IN .\Release\Rs232.obj
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE ..\..\lib\Rs232.c LARGE OPTIMIZE(9,SIZE) BROWSE ORDER MODDP2 INCDIR(..\..\i
                    -nc\) DEBUG OBJECTEXTEND PRINT(.\Release\Rs232.lst) OBJECT(.\Release\Rs232.obj)

line level    source

   1          /*
   2           * 
   3           * Rs232.c
   4           * 
   5           * Part of the Myson Century CS620X     demo program.
   6           *
   7           * Authors: LY Lin, WM Wang, IJ Chen, WH Lee
   8           *
   9           * Rs232.c contains RS232 driver routines.It use interrupt and a FIFO for RX data.
  10           * This file must compile with Getkey.c and Putchar.c if you want to use standard
  11           * IO routine such as printf,scanf,puts....                             
  12           * 
  13           * The defination of RS232_RXB_SIZE in RS232.h is the size of RX FIFO .
  14           *
  15           * This program was developed using the Keil 8051 C uVision 2 system.
  16           * The Keil compiler MUST be used if working with Myson Century supplied
  17           * firmware.
  18           *
  19           *
  20           * Note: To use RS232 driver functions we must call RS232_intr_init() first.
  21          */
  22          
  23          #include <stdio.h>
  24          #include <ctype.h>
  25          #include <stdlib.h>
  26          #include <string.h>
  27          #include "hpserver.h"
  28          #include "rs232.h"
  29          
  30          /*Define XON XOFF characters.*/
  31          #define XON  0x11
  32          #define XOFF 0x13
  33          
  34          /*Functions prototypes.*/
  35          void RS232_intr_init();
  36          char RS232_rx_empty();
  37          int RS232_rx_freelen();
  38          int RS232_rx_datalen();
  39          int RS232_rx_buffout(char *buff,int len);
  40          char RS232_rx_getchar();
  41          
  42          /*RS232 RX FIFO*/
  43          char RS232_rxb[RS232_RXB_SIZE];
  44          data int RS232_current_rxb;
  45          data int RS232_last_rxb;
  46          
  47          /*use to replace TI for Putchar function*/
  48          data char TXFLAG=0; 
  49          
  50          #if USE_XON_XOFF
  51          /*XOFF flag*/
  52          data char xoff_flag=0;
  53          #endif
  54          /************************************************************************
C51 COMPILER V7.50   RS232                                                                 10/12/2006 15:31:40 PAGE 2   

  55          /*      Function Name : RS232_intr_init                                                                         *
  56          /*                                                                                                                                              *
  57          /*      Arguments :                                                                                                             *
  58          /*                              None.                                                                                                   * 
  59          /*                                                                                                                                              *
  60          /*      Return : None.                                                                                                          *               
  61          /*                                                                                                                                              *
  62          /*                                                                                                                                              *
  63          /*  Comment :                                                                                                                   *
  64          /*                      This function initialize RS232 driver and enable interrupt.     *
  65          /*                      You must call this function before using the RS232                      *
  66          /*                      functions.                                                                                                      *
  67          /*                                                                                                                                              *
  68          /************************************************************************/
  69          void RS232_intr_init()
  70          {
  71   1      IP|=0x10;
  72   1      //IP|=0x40;
  73   1      SCON&=0x0FC;
  74   1      SCON|=0x10;
  75   1      IE|=0x10;
  76   1      //IE|=0x40;
  77   1      SBUF=XON;
  78   1      RS232_current_rxb=0;
  79   1      RS232_last_rxb=0;
  80   1      }
  81          /************************************************************************
  82          /*      Function Name : RS232_Update                                                                            *
  83          /*                                                                                                                                              *
  84          /*      Arguments :                                                                                                             *
  85          /*                              None.                                                                                                   * 
  86          /*                                                                                                                                              *
  87          /*      Return : None.                                                                                                          *               
  88          /*                                                                                                                                              *
  89          /*                                                                                                                                              *
  90          /*  Comment :                                                                                                                   *
  91          /*                      This function is interrupt service routine for RS232.           *
  92          /*                                                                                                                                              *
  93          /************************************************************************/
  94          void RS232_Update(void) interrupt 4              //4
  95          {
  96   1      data int tmp,freelen;
  97   1              /*calculate rx buffer free length*/
  98   1              if (RS232_current_rxb<RS232_last_rxb)
  99   1                      freelen=RS232_RXB_SIZE-(RS232_last_rxb-RS232_current_rxb)-1;
 100   1              else if (RS232_current_rxb>RS232_last_rxb)
 101   1                      freelen=RS232_current_rxb-RS232_last_rxb-1;
 102   1              else freelen=RS232_RXB_SIZE;
 103   1      
 104   1              /*RI, put RX char to FIFO.*/
 105   1              while (SCON&0x1)
 106   1              {
 107   2                      SCON=SCON&(~0x1);
 108   2                      tmp=(RS232_last_rxb+1)%RS232_RXB_SIZE;
 109   2      
 110   2                      if (freelen>0)
 111   2                      {
 112   3                              RS232_rxb[RS232_last_rxb]=SBUF;
 113   3                              RS232_last_rxb=tmp;
 114   3                              freelen--;
 115   3                      }
 116   2              }
C51 COMPILER V7.50   RS232                                                                 10/12/2006 15:31:40 PAGE 3   

 117   1      #if USE_XON_XOFF
 118   1              /*Xon,Xoff control*/
 119   1              if ((freelen<RS232_BUFF_RES) && (!xoff_flag))
 120   1              {
 121   2                      if (TXFLAG)
 122   2                      {
 123   3                              SCON=SCON&(~0x2);
 124   3                              SBUF=XOFF;
 125   3                              TXFLAG=0;
 126   3                              xoff_flag=1;
 127   3                      }
 128   2                      /*RS232 TX is busy.*/
 129   2                      else
 130   2                              xoff_flag=2;
 131   2              }
 132   1      #endif
 133   1              /*TI , put char to SBUF*/
 134   1              if (SCON&0x2)//TI
 135   1              {
 136   2                      SCON=SCON&(~0x2);
 137   2                      if (xoff_flag==2)
 138   2                      {
 139   3                              SBUF=XOFF;
 140   3                              TXFLAG=0;
 141   3                              xoff_flag=1;
 142   3                      }
 143   2                      else
 144   2                              TXFLAG=1;
 145   2              }
 146   1      }
 147          /************************************************************************
 148          /*      Function Name : RS232_rx_freelen                                                                        *
 149          /*                                                                                                                                              *
 150          /*      Arguments :                                                                                                             *
 151          /*                              None.                                                                                                   * 
 152          /*                                                                                                                                              *
 153          /*      Return :                                                                                                                        *
 154          /*                      The free length in bytes of RS232 RX FIFO.                                      *               
 155          /*                                                                                                                                              *
 156          /*  Comment :                                                                                                                   *
 157          /*                      This function return the free length of RS232 RX FIFO.          *
 158          /*                                                                                                                                              *
 159          /************************************************************************/
 160          int RS232_rx_freelen()
 161          {
 162   1      int ret_val;
 163   1              data int current_rxb,last_rxb;
 164   1              /*Critical section,disable interrupt*/
 165   1              IE&=(~0x10);
 166   1              current_rxb=RS232_current_rxb;
 167   1              last_rxb=RS232_last_rxb;
 168   1              IE|=0x10;
 169   1      
 170   1              /*Calculate RX FIFO free length.*/
 171   1              if (current_rxb<last_rxb)
 172   1                      ret_val=RS232_RXB_SIZE-(last_rxb-current_rxb)-1;
 173   1              else if (current_rxb>last_rxb)
 174   1                      ret_val=current_rxb-last_rxb-1;
 175   1              else ret_val=RS232_RXB_SIZE;
 176   1      
 177   1      return ret_val;
 178   1      }
C51 COMPILER V7.50   RS232                                                                 10/12/2006 15:31:40 PAGE 4   

 179          
 180          /************************************************************************

⌨️ 快捷键说明

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