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

📄 main.c

📁 使用silabs提供的协议栈做的一个基于c8051f的web服务器。ps:绝不是那个常见的简单web服务器。
💻 C
字号:
//------------------------------------------------------------------------------// main.c//------------------------------------------------------------------------------// Copyright (C) 2005 Silicon Laboratories, Inc.//// Date: 12/05/07 18:37:14// Target: C8051F34x //// Description://    This file contains the main routine, MCU initialization code, and//    callback functions used by the TCP/IP Library.//// Generated by TCP/IP Configuration Wizard Version 3.23//#include "mn_userconst.h"                      // TCP/IP Library Constants#include "mn_stackconst.h"                     // TCP/IP Library Constants#include "mn_errs.h"                           // Library Error Codes#include "mn_defs.h"                           // Library Type definitions#include "mn_funcs.h"                          // Library Function Prototypes#include "VFILE_DIR\index.h"#include <c8051F340.h>                         // Device-specific SFR Definitions//------------------------------------------------------------------------------// Function Prototypes//------------------------------------------------------------------------------// Initialization Routinesvoid PORT_Init (void);void SYSCLK_Init (void);void EMIF_Init(void);
//-----------------------------------------------------------------------------
// Main Routine
//-----------------------------------------------------------------------------
void main(void)
{

   // Disable watchdog timer
   PCA0MD = 0x00;

   // Initialize the MCU
   PORT_Init();
   SYSCLK_Init();

   EMIF_Init();

   // Initialize the TCP/IP stack.
   if (mn_init() < 0)
   {
      // If code execution enters this while(1) loop, the stack failed to initialize.
      // Verify that all boards are connected and powered properly.
      while(1);
   }

   // mn_ether_init() initializes the Ethernet controller.
   // FULL_DUPLEX indicates that the controller will be configured for
   //    full duplex operation.
   if (mn_ether_init(FULL_DUPLEX) < 0)
   {
      // If code execution enters this while(1) loop, the Ethernet controller failed
      // to initialize.
      // Verify that the Ethernet controller is connected and powered properly.
      // Verity that the EMIF has been configured at a speed compatible with the
      //    Ethernet controller.
      while(1);
   }

   // Add web page to virtual file system.
   // The main page MUST be called index.htm or index.html.
   mn_vf_set_entry((byte *)"index.html", INDEX_SIZE, index_html, VF_PTYPE_FLASH);

   // Use DHCP to obtain an IP address.
   if (mn_dhcp_start(PTR_NULL, dhcp_default_lease_time) <= 0)
   {
      // DHCP Error
      // The DHCP server did not assign a valid IP address.
      while(1);
   }

   // Start the Application Layer Services.
   if (mn_server() < 0)
   {
      // If mn_server returns a value less than zero, an error occurred.
      // Possible error codes are:
      // 1. PPP_LINK_DOWN: The PPP connection was terminated.
      // 2. DHCP_LEASE_EXPIRED: The DHCP lease expired.

      while(1);
   }

   // Release the DHCP lease.
   mn_dhcp_release();

   while(1);
}
//-----------------------------------------------------------------------------// Initialization Routines//-----------------------------------------------------------------------------//-----------------------------------------------------------------------------// PORT_Init//-----------------------------------------------------------------------------//// Configure the Interrupts, Crossbar and GPIO ports//void PORT_Init (void){}//-----------------------------------------------------------------------------// EMIF_Init//-----------------------------------------------------------------------------//// Configure the External Memory Interface for both on and off-chip access.//void EMIF_Init (void){   EMI0TC = EMIF_TIMING;      // This constant may be modified                              // according to SYSCLK to meet the                              // timing requirements for the CP2200   EMI0CN = BASE_ADDRESS;     // Page of XRAM accessed by EMIF}//-----------------------------------------------------------------------------// SYSCLK_Init//-----------------------------------------------------------------------------//// This routine initializes the system clock.//void SYSCLK_Init (void){    int i = 0;
    OSCICN |= 0x03;
    CLKSEL = 0x00;
}

⌨️ 快捷键说明

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