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

📄 uart.lst

📁 51edn开发板程序
💻 LST
字号:
C51 COMPILER V7.50   UART                                                                  06/02/2008 20:59:09 PAGE 1   


C51 COMPILER V7.50, COMPILATION OF MODULE UART
OBJECT MODULE PLACED IN UART.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE UART.c BROWSE DEBUG OBJECTEXTEND

line level    source

   1          /******************************************************************
   2             本程序只供学习使用,未经作者许可,不得用于其它任何用途
   3          
   4                  欢迎访问我的USB专区:http://group.ednchina.com/93/
   5                  欢迎访问我的blog:   http://www.ednchina.com/blog/computer00
   6                                       http://computer00.21ic.org
   7          
   8          UART.C  file
   9          
  10          作者:Computer-lov
  11          建立日期: 2007.03.20
  12          修改日期: 2007.11.18
  13          版本:V1.1
  14          版权所有,盗版必究。
  15          Copyright(C) Computer-lov 2007-2017
  16          All rights reserved            
  17          *******************************************************************/
  18          
  19          #include "at89x52.H"
  20          
  21          #include "UART.h"
  22          #include "MyType.h"
  23          #include "config.h"
  24          
  25          uint8 Sending;
  26          
  27          //使用T2做波特率发生器可以获得更多的波特率设置。
  28          //删除本行将使用T1作为波特率发生器,最低波特率为300bps,最高为115200bps。
  29          #define USE_T2
  30          
  31          /********************************************************************
  32          函数功能:设置串口波特率。
  33          入口参数:波特率。
  34          返    回:无。
  35          备    注:无。
  36          ********************************************************************/
  37          uint32 UartSetBitRate(uint32 BitRate)
  38          { 
  39   1       EA=0;
  40   1      #ifdef USE_T2
  41   1       if(BitRate<=230400)
  42   1       {
  43   2        RCAP2L=0x10000-(Fclk/(BitRate*32));
  44   2        RCAP2H=(0x10000-(Fclk/(BitRate*32)))>>8;
  45   2       }
  46   1       BitRate=(Fclk/32)/(0x10000-((((uint32)RCAP2H)<<8)+RCAP2L));
  47   1      #else
               if(BitRate<225)
               {
                BitRate=225;
                PCON&=~0x80;  //波特率不加倍
                TH1=256-Fclk/(BitRate*12*16*2);
                TL1=256-Fclk/(BitRate*12*16*2);
                BitRate=(Fclk/12/32)/(0x100-((uint32)TH1));
               }
C51 COMPILER V7.50   UART                                                                  06/02/2008 20:59:09 PAGE 2   

               else if(BitRate<1200)
               {
                PCON&=~0x80;  //波特率不加倍
                TH1=256-Fclk/(BitRate*12*16*2);
                TL1=256-Fclk/(BitRate*12*16*2);
                BitRate=(Fclk/12/32)/(0x100-((uint32)TH1));
               }
               else if(BitRate<=115200)
               {
                PCON|=0x80;  //波特率加倍
                TH1=256-Fclk/(BitRate*12*16);
                TL1=256-Fclk/(BitRate*12*16);
                BitRate=(Fclk/12/16)/(0x100-((uint32)TH1));
               }
               else
               {
                BitRate=115200;
                PCON|=0x80;  //波特率加倍
                TH1=256-Fclk/(BitRate*12*16);
                TL1=256-Fclk/(BitRate*12*16);
                BitRate=(Fclk/12/16)/(0x100-((uint32)TH1));
               }
              #endif
  79   1       EA=1;
  80   1       return BitRate;
  81   1      }
  82          ////////////////////////End of function//////////////////////////////
  83          
  84          
  85          /********************************************************************
  86          函数功能:串口初始化。
  87          入口参数:无。
  88          返    回:无。
  89          备    注:无。
  90          ********************************************************************/
  91          void UartInit(void)
  92          {
  93   1       EA=0;
  94   1       
  95   1      #ifndef USE_T2
               TMOD&=0x0F;
               TMOD|=0x20;    //定时器1工作在模式2
               TCON=0x05;
              #endif
 100   1      
 101   1       SCON=0x50;       //串口工作在模式1
 102   1       
 103   1       UartSetBitRate(57600);  //波特率初始化为57600
 104   1      
 105   1      #ifdef USE_T2
 106   1       T2CON=0x34;     //使用T2作为波特率发生器
 107   1      #endif
 108   1      
 109   1       ES=1;         //串行中断允许
 110   1      
 111   1      #ifndef USE_T2
               TR1=1;        //启动定时器1
              #endif
 114   1      
 115   1       REN=1;        //允许接收 
 116   1       EA=1;         //允许中断
 117   1       Sending=0;    //允许发送
C51 COMPILER V7.50   UART                                                                  06/02/2008 20:59:09 PAGE 3   

 118   1      }
 119          ////////////////////////End of function//////////////////////////////
 120          
 121            
 122          /********************************************************************
 123          函数功能:串口中断处理。
 124          入口参数:无。
 125          返    回:无。
 126          备    注:无。
 127          ********************************************************************/
 128          void UartISR(void) interrupt 4
 129          {
 130   1       if(RI)    //收到数据
 131   1        {
 132   2         RI=0;   //清中断请求
 133   2        }
 134   1       else      //发送完一字节数据
 135   1        {
 136   2         TI=0;
 137   2         Sending=0;  //清正在发送标志
 138   2        }
 139   1      }
 140          ////////////////////////End of function//////////////////////////////
 141          
 142          /********************************************************************
 143          函数功能:往串口发送一字节数据。
 144          入口参数:d: 要发送的字节数据。
 145          返    回:无。
 146          备    注:无。
 147          ********************************************************************/
 148          void UartPutChar(uint8 d)
 149          {
 150   1       while(Sending);
 151   1       Sending=1;
 152   1       SBUF=d;
 153   1      }
 154          ////////////////////////End of function//////////////////////////////
 155          
 156          /********************************************************************
 157          函数功能:发送一个字符串。
 158          入口参数:pd:要发送的字符串指针。
 159          返    回:无。
 160          备    注:无。
 161          ********************************************************************/
 162          void Prints(uint8 * pd)
 163          {
 164   1       while((*pd)!='\0')
 165   1        {
 166   2         UartPutChar(*pd);
 167   2         pd++;
 168   2        }
 169   1      }
 170          ////////////////////////End of function//////////////////////////////
 171          
 172          /********************************************************************
 173          函数功能:将整数转按十进制字符串发送。
 174          入口参数:x:待显示的整数。
 175          返    回:无。
 176          备    注:无。
 177          ********************************************************************/
 178          /*void PrintLongInt(uint32 x)
 179          {
C51 COMPILER V7.50   UART                                                                  06/02/2008 20:59:09 PAGE 4   

 180           int8 i;
 181           uint8 display_buffer[10];
 182          
 183           for(i=9;i>=0;i--)
 184            {
 185             display_buffer[i]='0'+x%10;
 186             x/=10;
 187            }
 188           for(i=0;i<9;i++)
 189            {
 190             if(display_buffer[i]!='0')break;
 191            }
 192           for(;i<10;i++)UartPutChar(display_buffer[i]);
 193          }*/
 194          ////////////////////////End of function//////////////////////////////
 195          
 196          code uint8 HexTable[]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
 197          /********************************************************************
 198          函数功能:将短整数按十六进制发送。
 199          入口参数:待发送的整数。
 200          返    回:无。
 201          备    注:无。
 202          ********************************************************************/
 203          /*void PrintShortIntHex(uint16 x)
 204          {
 205           uint8 i;
 206           uint8 display_buffer[7];
 207           display_buffer[6]=0;
 208           display_buffer[0]='0';
 209           display_buffer[1]='x';
 210           for(i=5;i>=2;i--)
 211            {
 212             display_buffer[i]=HexTable[(x&0xf)];
 213             x>>=4;
 214            }
 215           Prints(display_buffer);
 216          }*/
 217          ////////////////////////End of function//////////////////////////////
 218          
 219          /********************************************************************
 220          函数功能:将整数按十六进制发送。
 221          入口参数:待发送的整数。
 222          返    回:无。
 223          备    注:无。
 224          ********************************************************************/
 225          /*
 226          void PrintLongIntHex(uint32 x)  //
 227          {
 228           uint8 i;
 229           uint8 display_buffer[11];
 230           display_buffer[10]=0;
 231           display_buffer[0]='0';
 232           display_buffer[1]='x';
 233           for(i=9;i>=2;i--)
 234            {
 235             display_buffer[i]=HexTable[(x&0xf)];
 236             x>>=4;
 237            }
 238           Prints(display_buffer);
 239          }
 240          */
 241          ////////////////////////End of function//////////////////////////////
C51 COMPILER V7.50   UART                                                                  06/02/2008 20:59:09 PAGE 5   

 242          
 243          
 244          /********************************************************************
 245          函数功能:发送一个byte的数据。
 246          入口参数:待发送的数据。
 247          返    回:无。
 248          备    注:无。
 249          ********************************************************************/
 250          /*void Printc(uint8 x)
 251          {
 252           while(Sending);
 253           Sending=1;
 254           SBUF=x;
 255          }*/
 256          ////////////////////////End of function//////////////////////////////
 257          
 258          
 259          /********************************************************************
 260          函数功能:以HEX格式发送一个byte的数据。
 261          入口参数:待发送的数据
 262          返    回:无。
 263          备    注:无。
 264          ********************************************************************/
 265          void PrintHex(uint8 x)
 266          {
 267   1       UartPutChar(HexTable[x>>4]);
 268   1       UartPutChar(HexTable[x&0xf]);
 269   1      }
 270          ////////////////////////End of function//////////////////////////////


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =    287    ----
   CONSTANT SIZE    =     16    ----
   XDATA SIZE       =   ----    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =      1       4
   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 + -