📄 main.lst
字号:
C51 COMPILER V7.20 MAIN 03/07/2006 14:49:11 PAGE 1
C51 COMPILER V7.20, COMPILATION OF MODULE MAIN
OBJECT MODULE PLACED IN MAIN.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE MAIN.C OPTIMIZE(9,SPEED) BROWSE DEBUG OBJECTEXTEND
line level source
1 //---------------------------------------------------------------------------
2 // Net MAIN.C
3 //
4 // 8051 Web Server project
5 // See Makefile for build notes
6 // Written for Keil C51 V5.1 compiler, notes:
7 // It uses big endian order, which is the same as the
8 // network byte order, unlike x86 systems.
9 // Use OPTIMIZE(2)or higher so that automatic variables get shared
10 // between functions, to stay within the 256 bytes idata space
11 //---------------------------------------------------------------------------
12 //
13 #include <string.h>
14 #include <stdlib.h>
15 #include "reg52.h"
16 #include "net.h"
17 #include "eth.h"
18 #include "serial.h"
19 #include "arp.h"
20 #include "ip.h"
21 #include "udp.h"
22 #include "timer.h"
23 #include "tcp.h"
24 #include "http.h"
25
26 // Global variables
27 UINT volatile event_word;
28 char xdata text[20];
29 UCHAR idata debug;
30 UCHAR idata rcve_buf_allocated;
31
32 // This sets my hardware address to 00:01:02:03:04:05
33 UCHAR code my_hwaddr[6] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05};
34
35 // Hardware addr to send a broadcast
36 UCHAR code broadcast_hwaddr[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
37
38 // This sets my IP address to 192.168.0.10
39 ULONG code my_ipaddr = 0xC0A8000AL;
40
41 //目的地址192.168.0.214
42 ULONG sender_ipaddr=0xC0A800D6L;
43
44 // This sets my subnet mask to 255.255.255.0
45 ULONG code my_subnet = 0xFFFFFF00L;
46
47 // Set to 0 if no gateway is present on network192.168.0.1
48 ULONG code gateway_ipaddr = 0xC0A80001L;
49
50 //--------------------------------------------------------------------------
51 // Initialize the memory management routines
52 // Initialize variables declared in main
53 //--------------------------------------------------------------------------
54
55 sbit RST = P1^1;//复位ip等信息
C51 COMPILER V7.20 MAIN 03/07/2006 14:49:11 PAGE 2
56 sbit RDY = P1^3;
57 //sbit DEBUG = P1^4;//如果为高,不发出调试信息
58 sbit BUSY = P1^5;//如果为低,则不允许向串口输入
59 //sbit RST_LEDS=P1^6;//用于复位大屏的保留
60
61 void init_main(void)
62 {
63 1 // Start the memory pool for incoming and outgoing Ethernet
64 1 // frames at 2000, with length = 1800(1500) bytes. Memory below 500
65 1 // is used for program variables
66 1 init_mempool((void xdata *)1000, 1800);
67 1 memset(text, 0, sizeof(text));//将text的设置为0
68 1 event_word = 0;
69 1 rcve_buf_allocated = FALSE;
70 1 debug = FALSE;//测试条件开启与否FALSE
71 1 //debug = TRUE;
72 1 }
73
74 //延时(thetime)毫秒 对于22.1184MHz
75 void Delay1ms(unsigned char thetime)
76 {
77 1 unsigned char j;
78 1 while (thetime!=0)
79 1 {
80 2 thetime--;
81 2 for(j=0;j<226;j++){}
82 2 }
83 1 }
84
85 void main (void)
86 {
87 1 UINT event_word_copy;
88 1 UCHAR xdata * inbuf;
89 1 UINT length;
90 1
91 1 init_main();
92 1 init_tcp();
93 1 init_http();
94 1 init_serial();
95 1 init_arp();
96 1 LED = 0;//开灯
97 1 init_8019();
98 1 init_timer2();
99 1
100 1 EA=1;//开启中断
101 1 ET2 = 1; // Enable timer 2 interrupt
102 1
103 1 if(debug)SendCommString("Init OK\r\n");
104 1 // The code below is a priority based RTOS. The event
105 1 // handlers are in priority order - highest priority first.
106 1 while (1)
107 1 {
108 2 // Query CS8900A to see if Ethernet frame has arrived
109 2 // If so, set EVENT_ETH_ARRIVED bit in event_word
110 2 query_8019();
111 2 // Use a copy of event word to avoid interference
112 2 // with interrupts
113 2 ET2=0;//EA = 0;
114 2 event_word_copy = event_word;
115 2 ET2=1;//EA = 1;
116 2
117 2 // See if an Ethernet frame has arrived 是否有网络数据传到
C51 COMPILER V7.20 MAIN 03/07/2006 14:49:11 PAGE 3
118 2 if (event_word_copy & EVENT_ETH_ARRIVED)
119 2 {
120 3 ET2=0;//EA = 0;
121 3 event_word &= (~EVENT_ETH_ARRIVED);//去除标志
122 3 ET2=1;//EA = 1;
123 3
124 3 // Allocate a buffer and read frame from
125 3 //从网络芯片中读取数据
126 3 inbuf = rcve_frame();
127 3 if (inbuf != NULL)
128 3 {
129 4 // Process the received Ethernet frame
130 4 //处理接受的数据帧
131 4 eth_rcve(inbuf);
132 4
133 4 // If the memory allocated for the rcve message has
134 4 // not already been freed then free it now
135 4 if (rcve_buf_allocated)//数据已经接受到了
136 4 {
137 5 free(inbuf);//释放内存
138 5 rcve_buf_allocated = FALSE;
139 5 }
140 4 }
141 3 }
142 2 // See if TCP retransmit timer has expired
143 2 // TCP重发超时
144 2 else if (event_word_copy & EVENT_TCP_RETRANSMIT)
145 2 {
146 3 EA = 0;
147 3 event_word &= (~EVENT_TCP_RETRANSMIT);
148 3 EA = 1;
149 3 tcp_retransmit();
150 3 }
151 2
152 2 // See if TCP inactivity timer has expired
153 2 //TCP 不活动
154 2 else if (event_word_copy & EVENT_TCP_INACTIVITY)
155 2 {
156 3 EA = 0;
157 3 event_word &= (~EVENT_TCP_INACTIVITY);
158 3 EA = 1;
159 3 tcp_inactivity();
160 3 }
161 2
162 2 // See if ARP retransmit timer has expired
163 2 else if (event_word_copy & EVENT_ARP_RETRANSMIT)
164 2 {
165 3 ET2=0;//EA = 0;
166 3 event_word &= (~EVENT_ARP_RETRANSMIT);//去除标志
167 3 ET2=1;//EA = 1;
168 3 arp_retransmit();
169 3 }
170 2
171 2 // See if it is time to age the ARP cache
172 2 else if (event_word_copy & EVENT_AGE_ARP_CACHE)
173 2 {
174 3 ET2=0;//EA = 0;
175 3 event_word &= (~EVENT_AGE_ARP_CACHE);//去除标志
176 3 ET2=1;//EA = 1;
177 3 age_arp_cache();
178 3 }
179 2 // See if an RS232 message has arrived
C51 COMPILER V7.20 MAIN 03/07/2006 14:49:11 PAGE 4
180 2 else if((event_word_copy & EVENT_RS232_ARRIVED)&&CommRecFlag)
181 2 {
182 3 //if(debug){SendCommString(" 232 Rec ");Serial_Send_Ch(CommRecLength);}
183 3
184 3 length=CommRecLength;
185 3 CommRecFlag=0;
186 3 CommRecLength=0;
187 3 if(CommRecBlock)inbuf=0x4000;
188 3 else inbuf=0x5000;
189 3 CommRecBlock=~CommRecBlock;//切换
190 3 ET2=0;
191 3 udp_send(inbuf-42,COMM_PORT1,length);
192 3 event_word &= (~EVENT_RS232_ARRIVED);//去除标志
193 3 ET2=1;
194 3 }
195 2 }
196 1 }
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 297 ----
CONSTANT SIZE = 34 ----
XDATA SIZE = 20 ----
PDATA SIZE = ---- ----
DATA SIZE = 6 6
IDATA SIZE = 2 ----
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 + -