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

📄 main.lst

📁 用c8051f340基于51单片机上网
💻 LST
📖 第 1 页 / 共 3 页
字号:
C51 COMPILER V8.08   MAIN                                                                  11/04/2008 18:45:33 PAGE 1   


C51 COMPILER V8.08, COMPILATION OF MODULE MAIN
OBJECT MODULE PLACED IN main.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.exe main.c DB OE

line level    source

   1          //-----------------------------------------------------------------------------
   2          // main.c
   3          //-----------------------------------------------------------------------------
   4          // Copyright 2006 Silicon Laboratories, Inc.
   5          // http://www.silabs.com
   6          //
   7          // Program Description:
   8          // 
   9          // This file contains the main routine for the CP220x Send and Receive example.
  10          // 
  11          // FID:            
  12          // Target:         Multiple
  13          // Tool chain:     Keil C51 7.20 / Keil EVAL C51
  14          //                 Silicon Laboratories IDE version 2.72 
  15          // Command Line:   See Readme.txt
  16          // Project Name:   CP220x_Ethernet_Routines
  17          //
  18          // 
  19          //
  20          // Release 1.1
  21          //    - Configures C8051F120 SYSCLK to 98 MHz
  22          //
  23          // Release 1.0
  24          //    -Initial Release (FB)
  25          //    -30 MAY 2006
  26          
  27          //-----------------------------------------------------------------------------
  28          // Includes
  29          //-----------------------------------------------------------------------------
  30          #include "global.h"
  31          #include "arp.h"
  32          #include "tcp.h"
  33          #include "http.h"
  34          #include "ip.h"
  35          #include "Analog.h"
  36          //-----------------------------------------------------------------------------
  37          // Function Prototypes
  38          //-----------------------------------------------------------------------------
  39          void main(void);
  40          
  41          //-----------------------------------------------------------------------------
  42          // Global Variables
  43          //-----------------------------------------------------------------------------
  44          
  45          ///IPADDRESS  xdata MYIP;
  46          MACADDRESS xdata MYMAC; 
  47          ///MACADDRESS xdata BROADCASTMAC;
  48          MACADDRESS xdata DESTMAC;
  49          
  50          // This sets my hardware address to 00:01:02:03:04:05
  51          UCHAR xdata my_hwaddr[6] _at_ 4001; 
  52          
  53          // Hardware addr to send a broadcast
  54          UCHAR code broadcast_hwaddr[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
  55          
C51 COMPILER V8.08   MAIN                                                                  11/04/2008 18:45:33 PAGE 2   

  56          // This sets my IP address to 192.168.0.10
  57          ULONG code  my_ipaddr = 0xC0A8000AL;
  58          
  59          // This sets my subnet mask to 255.255.255.0
  60          ULONG code my_subnet = 0xFFFFFF00L;
  61          
  62          
  63          ULONG code gateway_ipaddr =  0L;
  64          
  65          unsigned char xdata RX_BUFF[1500];
  66          unsigned char xdata TX_BUFF [256];
  67          
  68          UINT volatile event_word;
  69          char xdata text[20];  
  70          UCHAR idata debug;
  71          UCHAR idata rcve_buf_allocated;
  72          #define LINK_ERROR  0x20
  73          char xdata inbuf1[1500] _at_ 1000;
  74          char xdata outbuf1[1500] _at_ 2500;
  75          
  76          UINT volatile event_word;
  77          UCHAR xdata * rcve_frame(void);
  78          UCHAR idata rcve_buf_allocated;
  79          
  80          void eth_rcve(UCHAR xdata * inbuf);
  81          
  82          void CP220x_Send( MACADDRESS* pDestAddr, unsigned char* buffer, 
  83                            unsigned int buffer_length, unsigned int packet_type);
  84          
  85          unsigned int CP220x_Receive(unsigned char* buffer, unsigned int buffer_length);
  86          //-----------------------------------------------------------------------------
  87          // Main Routine
  88          //-----------------------------------------------------------------------------
  89          void main(void)
  90          {       
  91   1         unsigned char error_code;
  92   1         unsigned int i;
  93   1         unsigned int num_bytes;
  94   1      
  95   1         UINT  event_word_copy;
  96   1              UCHAR xdata * inbuf;
  97   1         //----------------------------------
  98   1         // MCU Initialization
  99   1         //----------------------------------
 100   1         
 101   1         // Initialize the MCU for Ethernet
 102   1         Reset_Init();
 103   1              init_tcp();
 104   1              init_http();
 105   1              
 106   1      ///     init_adc();
 107   1              init_arp();
 108   1         // Turn off yellow LED.   
 109   1         YELLOW_LED = 0;
 110   1      
 111   1         //----------------------------------
 112   1         // Initialize Global Variables
 113   1         //----------------------------------
 114   1      /*
 115   1         // Initialize broadcast MAC address 
 116   1         BROADCASTMAC.Int[0] = 0xFFFF;
 117   1         BROADCASTMAC.Int[1] = 0xFFFF;
C51 COMPILER V8.08   MAIN                                                                  11/04/2008 18:45:33 PAGE 3   

 118   1         BROADCASTMAC.Int[2] = 0xFFFF;
 119   1         
 120   1         // Initialize destination MAC address 
 121   1         DESTMAC.Int[0] = 0x0012;
 122   1         DESTMAC.Int[1] = 0x3F51;
 123   1         DESTMAC.Int[2] = 0x3589;
 124   1      
 125   1         // Initialize MYIP address 
 126   1         MYIP.Char[0] = 0;
 127   1         MYIP.Char[1] = 0;
 128   1         MYIP.Char[2] = 0;
 129   1         MYIP.Char[3] = 1;
 130   1      */   
 131   1         // Initialize Transmit Buffer
 132   1         for(i = 0; i < sizeof(TX_BUFF); i++)
 133   1         {
 134   2            TX_BUFF[i] = 0;
 135   2         }
 136   1      
 137   1         //----------------------------------
 138   1         // Infinite Execution Loop
 139   1         // This loop allows the CP220x
 140   1         // to be re-initialized each time
 141   1         // it is unplugged from a network.
 142   1         //----------------------------------
 143   1         
 144   1         do{ 
 145   2            
 146   2            //-------------------------------
 147   2            // Initialize the CP220x
 148   2            //-------------------------------
 149   2            
 150   2            //-----------------------------------------------------------------------
 151   2            // Part A: Hardware Reset and Reset Initialization
 152   2            //
 153   2            // Perform the hardware reset and recommended reset initialization 
 154   2            // procedure listed in the CP220x datasheet.
 155   2            //
 156   2            // After completion, check the return code for any of the following
 157   2            // possible errors:
 158   2            //    OSC_ERROR - oscillator error 
 159   2            //    CAL_ERROR - self-initialization error
 160   2            //    MEM_ERROR - external memory bus error
 161   2            //-----------------------------------------------------------------------
 162   2            
 163   2            EA = 0;                          // Disable Interrupts
 164   2            
 165   2            error_code = CP220x_HW_Reset();  // Reset and Initialize the CP220x
 166   2         
 167   2            // Check for the three possible error codes  
 168   2            if(error_code & (OSC_ERROR | CAL_ERROR | MEM_ERROR))
 169   2            {
 170   3               // Print an Error Message
 171   3               #if(UART_ENABLED)
 172   3               printf("\n\n *** Please Reset Device ***\n");
 173   3               #endif 
 174   3               
 175   3               // Place device in an infinite loop if an error occurs   
 176   3               while(1);
 177   3            }
 178   2            
 179   2            //-----------------------------------------------------------------------
C51 COMPILER V8.08   MAIN                                                                  11/04/2008 18:45:33 PAGE 4   

 180   2            // Part B: Physical Layer Initialization
 181   2            //
 182   2            // Initialize the physical layer (PHY) for Autonegotiation
 183   2            //
 184   2            // After completion, check the return code for any of the following
 185   2            // possible errors:
 186   2            //    LINK_ERROR - The device is not connected to a network or 
 187   2            //                 autonegotiation has failed. 
 188   2            //
 189   2            // If an error occurs, keep re-trying until the device is able to 
 190   2            // complete a successful auto-negotiation or is plugged into a network.    
 191   2            //-----------------------------------------------------------------------
 192   2      
 193   2            while(1){
 194   3                  
 195   3               error_code = PHY_Init();      // Initialize the physical layer
 196   3               
 197   3               if(error_code & LINK_ERROR)   // Check for the possible error codes
 198   3               {                             // On Failure:
 199   4                  YELLOW_LED = !YELLOW_LED;  // Toggle indicator
 200   4               } 
 201   3               
 202   3               else                          
 203   3               {                             // On Success:   
 204   4                  YELLOW_LED = 1;            // Turn on the indicator
 205   4                  break;                     // Exit initialization loop 
 206   4               }
 207   3      
 208   3            }
 209   2      
 210   2            //-----------------------------------------------------------------------
 211   2            // Part C: MAC Initialization
 212   2            //
 213   2            // Initialize the media acccess controller (MAC) 
 214   2            //
 215   2            // Currently, the MAC initialization routine does not return any errors. 
 216   2            //-----------------------------------------------------------------------
 217   2            
 218   2            MAC_Init();                      // Initialize the MAC
 219   2                                   
 220   2            
 221   2            //-----------------------------
 222   2            // Main Application Loop
 223   2            //-----------------------------   

⌨️ 快捷键说明

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