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

📄 main.lst

📁 C8051F120单片机TCP协议栈,主体眶架,从美国人LIB库中导出
💻 LST
📖 第 1 页 / 共 2 页
字号:
C51 COMPILER V8.02   MAIN                                                                  08/27/2007 11:39:16 PAGE 1   


C51 COMPILER V8.02, COMPILATION OF MODULE MAIN
OBJECT MODULE PLACED IN main.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE main.c LARGE BROWSE MDU_F120 DEBUG OBJECTEXTEND

line level    source

   1          //------------------------------------------------------------------------------
   2          // main.c
   3          //------------------------------------------------------------------------------
   4          // Copyright (C) 2005 Silicon Laboratories, Inc.
   5          //
   6          // Date: 05/15/06 17:21:33
   7          // Target: C8051F12x 
   8          // Version: 1.31
   9          //
  10          // Description:
  11          //
  12          //    This is a TCP example.
  13          //    This code runs on a C8051F120 connected to a CP2200 via AB4 board.
  14          //
  15          //      This file contains the main routine, MCU initialization code, and 
  16          //    callback functions used by the TCP/IP Library.
  17          //
  18          // Steps for running this example code:
  19          //
  20          //    1. To run the example as a TCP Echo Server, set SERVER_MODE in main.c to 1.
  21          //       To run the example as a TCP Echo Client, set SERVER_MODE to 0.
  22          //
  23          //    2. If running in Client mode, place the IP address of the  PC which will
  24          //       be running the test application (TCP_SVR.exe) in IP_DEST_ADDR in
  25          //       mn_userconst.h.
  26          //
  27          //    3. Place the IP address of the embedded Ethernet controller (C8051F120
  28          //       and CP2200) in IP_SRC_ADDR in mn_userconst.h.
  29          //
  30          //    4. Connect to the C8051F120.
  31          //
  32          //    5. Compile and build the project code.
  33          //
  34          //    6. Download the code to the C8051F120.
  35          //
  36          //    7. If running in Client mode, run TCP_SVR.exe on the PC receiving the
  37          //       call. Then press "Go." Once the Ethernet controller has initialized,
  38          //       TCP_SVR.exe will wait for the embedded Ethernet controller to send
  39          //       a string, then echo the received string back. The embedded Ethernet
  40          //       controller will then take the string from TCP_SVR.exe and send it
  41          //       back, and so forth.
  42          //
  43          //    8. If running in Server mode, press "Go." Then run TCP_CLI.exe on the PC.
  44          //       By default, TCP_CLI.exe will send data to 216.233.5.26. If the
  45          //       embedded Ethernet controller is using a different IP address,
  46          //       execute TCP_CLI.exe from the command line using this syntax:
  47          //
  48          //       TCP_CLI.exe XXX.XXX.XXX.XXX
  49          //
  50          //       where XXX.XXX.XXX.XXX is the IP address of the embedded Ethernet controller.
  51          //       TCP_CLI.exe will send out a string and wait for the embedded Ethernet
  52          //       controller to echo it back. TCP_CLI.exe will then take the received string
  53          //       and send it to the embedded Ethernet controller, and so forth.
  54          //
  55          //    9. Once the TCP example has terminated, the user may ping the C8051F120
C51 COMPILER V8.02   MAIN                                                                  08/27/2007 11:39:16 PAGE 2   

  56          //       at the IP address defined in IP_DEST_ADDR.
  57          //
  58          
  59          #include "mn_userconst.h"                      // TCP/IP Library Constants
  60          #include "mn_stackconst.h"                     // TCP/IP Library Constants
  61          #include "mn_errs.h"                           // Library Error Codes
  62          #include "mn_defs.h"                           // Library Type definitions
  63          #include "mn_funcs.h"                          // Library Function Prototypes
  64          #include <c8051F120.h>                         // Device-specific SFR Definitions
  65          #include <string.h>
  66          
  67          
  68          //------------------------------------------------------------------------------
  69          // Function Prototypes
  70          //------------------------------------------------------------------------------
  71          
  72          // Initialization Routines
  73          void PORT_Init (void);
  74          void SYSCLK_Init (void);
  75          void EMIF_Init(void);
  76          int establish_network_connection();
  77          
  78          // Application Functions
  79          void TCP(void);
  80          
  81          //-----------------------------------------------------------------------------
  82          // Constant Definitions 
  83          
  84          #define DATA_BUFF_LEN   100
  85          byte data_buff[DATA_BUFF_LEN];
  86          int status=0;
  87          int statusnum=0;
  88          
  89          
  90          //-----------------------------------------------------------------------------
  91          // Main Routine
  92          //-----------------------------------------------------------------------------
  93          void main(void)
  94          {
  95   1         //int retval;
  96   1      
  97   1         // Disable watchdog timer
  98   1         WDTCN = 0xde;
  99   1         WDTCN = 0xad;
 100   1      
 101   1         // Initialize the MCU
 102   1         PORT_Init();
 103   1         SYSCLK_Init();
 104   1         EMIF_Init();
 105   1      
 106   1         while(1)
 107   1         {
 108   2            // Initialize the TCP/IP stack.
 109   2            if (mn_init() < 0)
 110   2            {
 111   3               // If code execution enters this while(1) loop, the stack failed to initialize.
 112   3               // Verify that all boards are connected and powered properly.
 113   3               while(1);
 114   3            }
 115   2      
 116   2            // Connect to the network
 117   2            establish_network_connection();
C51 COMPILER V8.02   MAIN                                                                  08/27/2007 11:39:16 PAGE 3   

 118   2      
 119   2            // Run the TCP example
 120   2            TCP();
 121   2      
 122   2            // Start the Application Layer Services
 123   2            // If this routine exits, check the return value for an error code.
 124   2         //   retval = mn_server();
 125   2      
 126   2         }
 127   1      }
 128          
 129          //-----------------------------------------------------------------------------
 130          // establish_network_connection
 131          //-----------------------------------------------------------------------------
 132          //
 133          // This function calls mn_ether_init() to initialize the CP2200 and attach to
 134          // the network.
 135          //
 136          // If there is a network connection, the function returns 1.
 137          //
 138          // In the call to mn_ether_init(), NUM_AUTONEG_ATTEMPTS is set to 0, so the
 139          // function will not return until it successfully auto-negotiates.
 140          //
 141          // mn_ether_init() will not be a blocking call if NUM_AUTONEG_ATTEMPTS is set
 142          // to a value greater than 0.
 143          //
 144          int establish_network_connection()
 145          {
 146   1         int retval;
 147   1      
 148   1         do
 149   1         {
 150   2            // mn_ether_init() initializes the Ethernet controller.
 151   2            // AUTO_NEG indicates that the controller will auto-negotiate.
 152   2            retval = mn_ether_init(AUTO_NEG, 0, 0);
 153   2      
 154   2            // If there is no link, poll link_status until it sets or the
 155   2            // CP2200 resets and then call mn_ether_init() again.
 156   2            if (retval == LINK_FAIL)
 157   2            {
 158   3               while(!link_status && !ether_reset);
 159   3            }
 160   2      
 161   2            // If retval is less than zero and is not LINK_FAIL, there is a 
 162   2            // hardware error.
 163   2            else if (retval < 0)
 164   2            {
 165   3               // Verify that the Ethernet controller is connected and powered properly.
 166   3               // Verity that the EMIF has been configured at a speed compatible with the
 167   3               //    Ethernet controller.
 168   3               while(1);
 169   3            }
 170   2      
 171   2         }while(retval < 0);
 172   1      
 173   1         return (1);
 174   1      
 175   1      }
 176          
 177          //-----------------------------------------------------------------------------
 178          // Application Functions
 179          //-----------------------------------------------------------------------------
C51 COMPILER V8.02   MAIN                                                                  08/27/2007 11:39:16 PAGE 4   

 180          
 181          //-----------------------------------------------------------------------------
 182          // TCP
 183          //-----------------------------------------------------------------------------
 184          //
 185          void TCP(void)
 186          {
 187   1       
 188   1         SCHAR socket_no;
 189   1         PSOCKET_INFO socket_ptr;
 190   1         byte data_buf[1300];
 191   1         word16 data_len=1300;
 192   1         int err=0;
 193   1         int i;
 194   1      
 195   1      
 196   1      
 197   1         // When dest_ip is null_addr any IP address is allowed to connect
 198   1        socket_no = mn_open(null_addr,ECHO_PORT,0,PASSIVE_OPEN,PROTO_TCP,\
 199   1                           STD_TYPE,data_buff,DATA_BUFF_LEN);
 200   1      
 201   1      
 202   1      //      socket_no = mn_open(ip_dest_addr,DEFAULT_PORT,ECHO_PORT,ACTIVE_OPEN,PROTO_TCP,\
*** WARNING C329 IN LINE 202 OF main.c: single-line comment contains line-continuation
 203   1                          //   STD_TYPE,data_buff,DATA_BUFF_LEN);
 204   1                                         
 205   1         if (socket_no < 0)
 206   1         {
 207   2            return;
 208   2         }
 209   1      
 210   1         socket_ptr = MK_SOCKET_PTR(socket_no);        // get pointer to the socket
 211   1      
 212   1         while(1)
 213   1         {
 214   2           // status = 0;
 215   2      
 216   2            /* mn_send sends the data and waits for an ACK. Some echo servers will

⌨️ 快捷键说明

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