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

📄 main.lst

📁 ZWIP 国内某16岁的博士写的基于51单片机的TCP IP协议, 非常好用!
💻 LST
字号:
C51 COMPILER V8.05a   MAIN                                                                 11/16/2006 19:20:21 PAGE 1   


C51 COMPILER V8.05a, COMPILATION OF MODULE MAIN
OBJECT MODULE PLACED IN .\main.obj
COMPILER INVOKED BY: C:\Keil\keil\C51\BIN\C51.EXE ..\App\main.c BROWSE DEBUG OBJECTEXTEND PRINT(.\main.lst) OBJECT(.\mai
                    -n.obj)

line level    source

   1          /*
   2           * Copyright (c) 2003 Electric Application Laboratory of NAN KAI University
   3           * All rights reserved.
   4           *
   5           * Redistribution and use in source and binary forms, with or without modification,
   6           * are permitted provided that the following conditions are met:
   7           *
   8           * 1. Redistributions of source code must retain the above copyright notice,
   9           *    this list of conditions and the following disclaimer.
  10           * 2. Redistributions in binary form must reproduce the above copyright notice,
  11           *    this list of conditions and the following disclaimer in the documentation
  12           *    and/or other materials provided with the distribution.
  13           * 3. The name of the author may not be used to endorse or promote products
  14           *    derived from this software without specific prior written permission.
  15           *
  16           * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
  17           * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  18           * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
  19           * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  20           * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
  21           * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  22           * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  23           * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
  24           * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
  25           * OF SUCH DAMAGE.
  26           *
  27           * Author: Li Zhanglin <wzzlin@nankai.edu.cn>
  28           *
  29           */
  30          
  31          #include "..\GloblDef\GloblDef.h"
  32          #include "..\TCPIP\TCPIPmem.h"
  33          #include "..\Netif\RTL8019.h"
  34          #include "..\TCPIP\IP.h"
  35          #include "..\Netif\etherif.h"
  36          #include "..\Netif\ARP.h"
  37          #include "..\TCPIP\Netif.h"
  38          #include "..\TCPIP\TCP.h"
  39          #include "..\App\main.h"
  40          
  41          #define DATA_SIZE       0x500
  42          BYTE DT_XDATA DataBlock[DATA_SIZE];
  43          BYTE DT_XDATA str[]="Hello,My name is cxh,I am Server!!";
  44          socket          DT_XDATA * DT_XDATA ExConn;
  45          socket          DT_XDATA * DT_XDATA     ExAccept;
  46          socket          DT_XDATA * DT_XDATA     ExListen;
  47          
  48          sbit led0=P1^4;
  49          sbit led1=P1^5;
  50          //#define LenTxBuf        2000    //Don't too small,because it will cause display abnormal.
  51          //#define LenRxBuf        50
  52          //unsigned char TxBuf[LenTxBuf],RxBuf[LenRxBuf];//收发缓冲区实体
  53          //unsigned char *inTxBuf,*outTxBuf,*inRxBuf,*outRxBuf;//收发缓冲区读写指针
  54          //bit TIflag=1;//Note:It must be 1.
C51 COMPILER V8.05a   MAIN                                                                 11/16/2006 19:20:21 PAGE 2   

  55          
  56          
  57          void OnReceive(void DT_XDATA * buf,WORD size)  REENTRANT_MUL
  58          {
  59   1              /* send back data */
  60   1              TCPSend(ExConn,buf,size);
  61   1      }
  62          void OnAcceptRecv(void DT_XDATA *buf,WORD size) REENTRANT_MUL
  63          {
  64   1              /* printf received data */
  65   1      
  66   1      void DT_XDATA *buff,*buff1;
  67   1             buff=buf;
  68   1             buff1="";
  69   1      #ifdef DEBUG
                      while(size--)
                              printf("%c",*((BYTE DT_XDATA *)buf)++);
              #endif
  73   1              if      ((char)(*((BYTE DT_XDATA *)buff))=='1') 
  74   1              {
  75   2                  led0=1;
  76   2                      led1=0;
  77   2              TCPSend(ExAccept,buff1,1);
  78   2              }
  79   1         else if      ((char)(*((BYTE DT_XDATA *)buff))=='2') 
  80   1              {
  81   2                  led0=0;
  82   2                      led1=1;
  83   2              TCPSend(ExAccept,buff1,1);
  84   2              }
  85   1              else if         ((char)(*((BYTE DT_XDATA *)buff))=='3') 
  86   1              {
  87   2                  led0=0;
  88   2                      led1=0;
  89   2              TCPSend(ExAccept,buff1,1);
  90   2              }
  91   1              else if         ((char)(*((BYTE DT_XDATA *)buff))=='4') 
  92   1              {
  93   2                  led0=1;
  94   2                      led1=1;
  95   2              TCPSend(ExAccept,buff1,1);
  96   2              }
  97   1              /* send back data */
  98   1              else TCPSend(ExAccept,buf,size);
  99   1      }
 100          void OnAccept(socket DT_XDATA *pNewSocket) REENTRANT_MUL
 101          {
 102   1              ExAccept = pNewSocket;
 103   1              pNewSocket->recv = OnAcceptRecv;
 104   1              pNewSocket->close = OnClose;
 105   1      }
 106          void OnClose(socket DT_XDATA * pSocket) REENTRANT_MUL
 107          {
 108   1              TCPClose(pSocket);      /* we close too */
 109   1      }
 110          void Timer() REENTRANT_MUL interrupt 1
 111          {
 112   1              TH0 = 0x3C;     /*TIMER_24M_25MS_H;*/
 113   1              TL0 = 0xAA;     /*TIMER_24M_25MS_L;*/
 114   1              
 115   1              NetIfTimer();
 116   1              ARPTimer();
C51 COMPILER V8.05a   MAIN                                                                 11/16/2006 19:20:21 PAGE 3   

 117   1              TCPTimer();
 118   1      }
 119          
 120          void SerialInit()
 121          {
 122   1              /* set TI to 1, set TR1 to 1 */
 123   1      
 124   1              TMOD=TMOD&0x0F;
 125   1              TMOD=TMOD|0x20;
 126   1              TL1=0xFD,TH1=0xFD;//19200 , 22.1184MHz
 127   1              SCON=0x50;PCON=0x00;
 128   1              TR1=1;
 129   1      
 130   1      /*      SCON = 0x52;/* SM0 SM1 =1 SM2 REN TB8 RB8 TI RI */
 131   1      /*      TMOD = 0x20;  GATE=0 C/T-=0 M1 M0=2 GATE C/T- M1 M0 */
 132   1      /*      TH1 = 0xE6;  TH1=E6 4800 when at 24MHz,TH1=F3,9600,24MHz */
 133   1      /*      PCON = 0x80;
 134   1              TCON = 0x40;/* 01101001 TF1 TR1 TF0 TR0 IE1 IT1 IE0 IT */
 135   1      }
 136          
 137          /*void InitSerialBuffer(void) reentrant//串口缓冲区初始化
 138          {
 139                  inTxBuf=TxBuf;outTxBuf=TxBuf;
 140                  inRxBuf=RxBuf;outRxBuf=RxBuf;
 141                  ES=1;
 142          }
 143          */
 144          
 145          
 146          
 147          void InterruptInit()
 148          {
 149   1              TMOD |= 0x01;
 150   1              TH0 = 0x3C;     /*TIMER_24M_25MS_H;*/
 151   1              TL0 = 0xAA;     /*TIMER_24M_25MS_L;*/
 152   1              TR0 = 1;
 153   1              
 154   1              /* open interrupt for rtl and timer */
 155   1              EA = 1;
 156   1              /* EX0 = 1; */
 157   1              ET0 = 1;
 158   1      }
 159          main()
 160          {
 161   1              struct SMemHead DT_XDATA *MemHead;
 162   1              struct SEtherDevice DT_XDATA DevRTL;
 163   1              BYTE    DT_XDATA EtherAddr[ETHER_ADDR_LEN] = {0x52,0x54,0x4c,0x30,0x2e,0x2f};
 164   1              IP_ADDR         IPAddr  = 0xc0a8020d;   /* 192.168.2.13 *//* ca71e590:202.113.229.144 *//* ca711075:202.113.16.117 
             -*/
 165   1              IP_ADDR         NetMask = 0xffffff00;   /* 255.255.255.0 */
 166   1              IP_ADDR         GateWay = 0xc0a80201;   /* 192.168.2.1  */
 167   1              
 168   1              led0=0;
 169   1              led1=0;
 170   1              /*
 171   1               * init
 172   1               */
 173   1              /* init. the order is not important */
 174   1              NetIfInit();
 175   1              ARPInit();
 176   1              TCPInit();
 177   1              MemInit();
C51 COMPILER V8.05a   MAIN                                                                 11/16/2006 19:20:21 PAGE 4   

 178   1              RTLInit(EtherAddr);     
 179   1              
 180   1              /* init Devcie struct and init this device */
 181   1              EtherDevInit(&DevRTL,EtherAddr,RTLSendPacket,RTLReceivePacket);
 182   1      
 183   1              /* add this device to NetIf */
 184   1              NetIfAdd(IPAddr,NetMask,GateWay,EtherInput,EtherOutput,&DevRTL);
 185   1      
 186   1              /*
 187   1               * start use socket 
 188   1               */
 189   1              SerialInit();
 190   1              InterruptInit();
 191   1              TRACE("start");
 192   1              
 193   1              /* Illustrate how to listen as a server */
 194   1              ExListen = TCPSocket(IPAddr);
 195   1              ExAccept = NULL;
 196   1              TCPListen(ExListen,TCP_DEFAULT_PORT,OnAccept);
 197   1              
 198   1              /* Illustrate how to connect to a server */
 199   1              ExConn = TCPSocket(IPAddr);
 200   1              if(TCPConnect(ExConn,0xc0a8020e,1001,OnReceive,OnClose) == TRUE)
 201   1              {
 202   2                      /* Illustrate how to Use TCPSend() */
 203   2                      TCPSend(ExConn,str,sizeof(str));
 204   2      
 205   2                      /* Illustrate how to Use TCPSendEx() */
 206   2                      while(1)
 207   2                      {
 208   3                              if((MemHead = TCPAllocate(DATA_SIZE)) == NULL)
 209   3                                      break;
 210   3                              MemCopy(MemHead->pStart,DataBlock,DATA_SIZE);
 211   3                              if(TCPSendEx(ExConn,MemHead) == FALSE)
 212   3                                      break;
 213   3                      }
 214   2              }
 215   1              
 216   1              TCPAbort(ExConn); 
 217   1      
 218   1              while(1);
 219   1      }
 220          
 221          
 222          
 223          


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =    665    ----
   CONSTANT SIZE    =      7    ----
   XDATA SIZE       =   1321      16
   PDATA SIZE       =   ----    ----
   DATA SIZE        =   ----      23
   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 + -