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

📄 rs232.lst

📁 stc-isp开发板驱动程序
💻 LST
字号:
C51 COMPILER V7.06   RS232                                                                 09/13/2005 20:39:38 PAGE 1   


C51 COMPILER V7.06, COMPILATION OF MODULE RS232
OBJECT MODULE PLACED IN rs232.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE rs232.c OMF2 BROWSE DEBUG

stmt level    source

   1          #include <config.h>
   2          
   3          #define IN_UART
   4          
   5          #define  RECEBUFFER_COUNT  8
   6          #define  SENDBUFFER_COUNT  36
   7          
   8          unsigned char idata rs232_recedata=0x00;  //从接收缓冲中取得的数据
   9          
  10          unsigned char idata rs232_recerece=0x00;   // 发送位置的标志
  11          unsigned char idata rs232_recesend=0x00;   // 已经处理的位置标志
  12          unsigned char idata rs232_recebytes=0x00;  // 缓冲区还存在的字节数
  13          unsigned char idata rs232_recebuff[RECEBUFFER_COUNT];
  14          
  15          
  16          unsigned char idata rs232_sendrece=0x00;   // 发送位置的标志
  17          unsigned char idata rs232_sendsend=0x00;   // 已经处理的位置标志
  18          unsigned char idata rs232_sendbytes=0x00;  // 缓冲区还存在的字节数
  19          unsigned char idata rs232_sendbuff[SENDBUFFER_COUNT];
  20          
  21          void rs232_initialize(void)
  22          {       
  23   1          AUXR &=0x3f;    //设定定时器0,1为普通的12时钟速度  T0x12=0,T1x12=0
  24   1              SCON = 0x50;
  25   1              PCON = 0x80;
  26   1              TMOD &=0x0f;
  27   1              TMOD |=0x20;
  28   1              TH1  = 0xfe;  /* 22.1184MHz晶振, 57600bps  */
  29   1              TL1  = 0xfe;  /* 22.1184MHz晶振, 57600bps */
  30   1      //      TH1  = 0xfc;  /* 22.1184MHz晶振, 57600bps */
  31   1      //      TL1  = 0xfc;  /* 22.1184MHz晶振, 57600bps */
  32   1      //      TH1  = 0xfa;  /* 22.1184MHz晶振, 38400bps */
  33   1      //      TL1  = 0xfa;  /* 22.1184MHz晶振, 38400bps */
  34   1      //      TH1  = 0xf4;  /* 22.1184MHz晶振, 19200bps */
  35   1      //      TL1  = 0xf4;  /* 22.1184MHz晶振, 19200bps */
  36   1      //      TH1  = 0xe8;  /* 22.1184MHz晶振, 9600bps */
  37   1      //      TL1  = 0xe8;  /* 22.1184MHz晶振, 9600bps */
  38   1      
  39   1      
  40   1          TF1 = 0X00;     // 定时器1的溢出标志
  41   1              TR1 = 0x01;
  42   1          TI  = 0x00;
  43   1          RI  = 0x00;
  44   1          ET1 = 0x01;     // 定时器1的中断使能
  45   1          ES  = 0x01;   // 开放串口
  46   1        //  PS  = 0x01;   // 将串口的优先级设定为最高
  47   1      
  48   1       }
  49          
  50          
  51          
  52          // rs232 sendbuffer 的自动处理和安排
  53          void rs232_senddata(unsigned char ch)
  54          {
  55   1       if(rs232_sendbytes==0x00)       //如果缓冲区已经发送完毕,则要启动发送
C51 COMPILER V7.06   RS232                                                                 09/13/2005 20:39:38 PAGE 2   

  56   1          {rs232_sendbytes++;
  57   2               SBUF=ch; 
  58   2               }
  59   1      
  60   1       else  // 如果缓冲区还有其他数据等待发送
  61   1          {if(rs232_sendrece>=SENDBUFFER_COUNT)
  62   2                  rs232_sendrece=0x00;
  63   2                      
  64   2               rs232_sendbuff[rs232_sendrece]=ch;
  65   2               rs232_sendbytes++;
  66   2               rs232_sendrece++; 
  67   2               } 
  68   1      }
  69          
  70          unsigned char rs232_getdata(unsigned char access_mode)  //取得receive buffer时需要查询是否有串行数据
  71          {unsigned char idata return_value = 0;
  72   1       if(access_mode == 0x00)  //  查询receive buffer缓冲区中有多少个数据
  73   1          return_value= rs232_recebytes;  //返回缓冲区剩余数据的个数
  74   1       else if(access_mode == 0x01)  // 读取数据并将数据清除
  75   1         {if(rs232_recebytes!=0x00)  // 如果系统中有接收的串行数据
  76   2             {return_value=rs232_recebuff[rs232_recesend];
  77   3                  rs232_recebuff[rs232_recesend]=0x00;
  78   3                      rs232_recesend++;
  79   3              if(rs232_recesend>=RECEBUFFER_COUNT)  //如果越界,则跳转
  80   3                      rs232_recesend=0x00;
  81   3                      rs232_recebytes--;
  82   3              }
  83   2              else
  84   2                 return_value = 0x00;  //如果系统出错了,则返回0X00;
  85   2          }
  86   1      
  87   1       return return_value;
  88   1       }
  89          
  90          // 串行的中断处理程序
  91          void rs232r_isr(void)  interrupt 4
  92          {
  93   1       if(TI!=0x00)
  94   1         { TI = 0x00;
  95   2           TB8 =0x00;
  96   2           if(rs232_sendbytes>0x00)  //本次发送完毕的处理
  97   2                  rs232_sendbytes--;
  98   2               if(rs232_sendbytes>0x00)  //如果还需要发送
  99   2                 {if(rs232_sendsend>=SENDBUFFER_COUNT)
 100   3                         rs232_sendsend=0x00;
 101   3                  SBUF=rs232_sendbuff[rs232_sendsend];
 102   3                  rs232_sendsend++;           
 103   3                  }
 104   2          } 
 105   1       if(RI!=0x00)
 106   1         { RI = 0x00;  //清除接收标志
 107   2           RB8 =0x00;
 108   2           if(rs232_recerece>=RECEBUFFER_COUNT)
 109   2                  rs232_recerece=0x00;
 110   2           rs232_recebuff[rs232_recerece++] = SBUF; 
 111   2               rs232_recebytes++;
 112   2              }
 113   1      
 114   1       }


MODULE INFORMATION:   STATIC OVERLAYABLE
C51 COMPILER V7.06   RS232                                                                 09/13/2005 20:39:38 PAGE 3   

   CODE SIZE        =    224    ----
   CONSTANT SIZE    =   ----    ----
   XDATA SIZE       =   ----    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =   ----    ----
   IDATA SIZE       =     51       1
   BIT SIZE         =   ----    ----
   EDATA SIZE       =   ----    ----
   HDATA SIZE       =   ----    ----
   XDATA CONST SIZE =   ----    ----
   FAR CONST SIZE   =   ----    ----
END OF MODULE INFORMATION.


C51 COMPILATION COMPLETE.  0 WARNING(S),  0 ERROR(S)

⌨️ 快捷键说明

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