📄 main.lst
字号:
C51 COMPILER V8.08 MAIN 04/01/2008 13:01:13 PAGE 1
C51 COMPILER V8.08, COMPILATION OF MODULE MAIN
OBJECT MODULE PLACED IN main.OBJ
COMPILER INVOKED BY: C:\SiLabs\MCU\IDEfiles\C51\Bin\C51.exe main.c DB OE LARGE
line level source
1 //------------------------------------------------------------------------------
2 // main.c
3 //------------------------------------------------------------------------------
4 // Copyright (C) 2005 Silicon Laboratories, Inc.
5 //
6 // Date: 05/16/06 13:15:34
7 // Target: C8051F34x
8 // Version: 1.31
9 //
10 // Description:
11 //
12 // This example uses HTTP to act as a web server.
13 //
14 // It runs on a C8051F340 connected to a CP2200 via AB4 board.
15 //
16 // This file contains the main routine, MCU initialization code, and
17 // callback functions used by the TCP/IP Library.
18 //
19 // Steps for running this example code:
20 //
21 // 1. Replace IP_SRC_ADDR in mn_userconst.h with the desired IP address.
22 //
23 // 2. Connect to the C8051F340.
24 //
25 // 3. Compile and build the project code.
26 //
27 // 4. Download the code to the C8051F340 and press "Go".
28 //
29 // 5. Open a web browser on the PC and enter "http:\\XXX.XXX.XXX.XXX"
30 // into the URL bar (where XXX.XXX.XXX.XXX is the IP address
31 // assigned in Step 1).
32 //
33 // 6. The web browser will display a "Hello World" HTML document.
34 //
35
36 #include "mn_userconst.h" // TCP/IP Library Constants
37 #include "mn_stackconst.h" // TCP/IP Library Constants
38 #include "mn_errs.h" // Library Error Codes
39 #include "mn_defs.h" // Library Type definitions
40 #include "mn_funcs.h" // Library Function Prototypes
41 #include "stdio.h" //************************************************
42 #include "string.h" //************************************************
43 #include "VFILE_DIR\index.h"
44 #include <c8051F340.h> // Device-specific SFR Definitions
45
46 //------------------------------------------------------------------------------
47 // Global Variable
48 //------------------------------------------------------------------------------
49 unsigned char HTML_BUFFER[400]; //************************************************
50 //------------------------------------------------------------------------------
51 // Function Prototypes
52 //------------------------------------------------------------------------------
53
54 // Initialization Routines
55 void PORT_Init (void);
C51 COMPILER V8.08 MAIN 04/01/2008 13:01:13 PAGE 2
56 void SYSCLK_Init (void);
57 void EMIF_Init(void);
58 int establish_network_connection();
59 // CGI Script
60 void get_data (PSOCKET_INFO socket_ptr); //************************************************
61 //-----------------------------------------------------------------------------
62 // Main Routine
63 //-----------------------------------------------------------------------------
64 void main(void)
65 {
66 1 int retval;
67 1
68 1 // Disable watchdog timer
69 1 PCA0MD = 0x00;
70 1
71 1 // Initialize the MCU
72 1 PORT_Init();
73 1 SYSCLK_Init();
74 1 EMIF_Init();
75 1
76 1 while(1)
77 1 {
78 2 // Initialize the TCP/IP stack.
79 2 if (mn_init() < 0)
80 2 {
81 3 // If code execution enters this while(1) loop, the stack failed to initialize.
82 3 // Verify that all boards are connected and powered properly.
83 3 while(1);
84 3 }
85 2
86 2 // Connect to the network
87 2 establish_network_connection();
88 2
89 2 // Add web page to virtual file system.
90 2 // The main page MUST be called index.htm or index.html.
91 2 mn_vf_set_entry((byte *)"index.html", INDEX_SIZE, index_html, VF_PTYPE_FLASH);
92 2 //*****************************************1********************************************
93 2 // Add CGI Script to Virtual File System
94 2 mn_pf_set_entry
95 2 (
96 2 (byte*)"get_data", // Script Name (ASCII)
97 2 get_data // Function Pointer
98 2 );
99 2 //*****************************************1********************************************
100 2
101 2 // Start the Application Layer Services
102 2 // If this routine exits, check the return value for an error code.
103 2 retval = mn_server();
104 2
105 2 }
106 1 }
107 //*****************************************2********************************************
108 //-----------------------------------------------------------------------------
109 // CGI Script: get_data
110 //-----------------------------------------------------------------------------
111 //
112 // This routine is called when the following is typed into the address bar
113 // of a web browser:
114 //
115 // http://<ip-address>/get_data?arg1=hello&arg2=donotdisplay
116 //
117 // where <ip-address> = the IP address of the embedded system
C51 COMPILER V8.08 MAIN 04/01/2008 13:01:13 PAGE 3
118 //
119
120 void get_data (PSOCKET_INFO socket_ptr)
121 {
122 1 byte msg_buff1[50];
123 1
124 1 int status1;
125 1
126 1 // Search for the type field and store the result in <msg_buff1>.
127 1 status1 = mn_http_find_value (BODYptr, (byte*)"arg1", msg_buff1);
128 1
129 1 // Check status1 and status2 to determine if msg_buff1 and msg_buff2 are valid.
130 1 if(status1){
131 2
132 2 // Build a web page in the HTML_BUFFER
133 2 sprintf(HTML_BUFFER, "<html>The value of \"arg1\" is \"%s\". </html>", msg_buff1);
134 2
135 2 // Fill the socket with data to send.
136 2 socket_ptr->send_ptr = HTML_BUFFER;
137 2 socket_ptr->send_len = strlen(HTML_BUFFER);
138 2
139 2 }
140 1 }
141 //*****************************************2********************************************
142 //-----------------------------------------------------------------------------
143 // establish_network_connection
144 //-----------------------------------------------------------------------------
145 //
146 // This function calls mn_ether_init() to initialize the CP2200 and attach to
147 // the network.
148 //
149 // If there is a network connection, the function returns 1.
150 //
151 // In the call to mn_ether_init(), NUM_AUTONEG_ATTEMPTS is set to 0, so the
152 // function will not return until it successfully auto-negotiates.
153 //
154 // mn_ether_init() will not be a blocking call if NUM_AUTONEG_ATTEMPTS is set
155 // to a value greater than 0.
156 //
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -