?? main.lst
字號:
C51 COMPILER V7.05 MAIN 10/22/2008 23:56:44 PAGE 1
C51 COMPILER V7.05, 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
stmt level source
1 //---------------------------------------------------------------------------
2 // Copyright (c) 2002 Jim Brady
3 // Do not use commercially without author's permission
4 // Last revised August 2002
5 // Net MAIN.C
6 //
7 // 8051 Web Server project
8 // See Makefile for build notes
9 // Written for Keil C51 V5.1 compiler, notes:
10 // It uses big endian order, which is the same as the
11 // network byte order, unlike x86 systems.
12 // Use OPTIMIZE(2)or higher so that automatic variables get shared
13 // between functions, to stay within the 256 bytes idata space
14 // 它使用大的 endian 命令, 是相同於那網絡字節命令,不像 x86 系統。
15 // 使用最佳化 (2) 或更高地所以 自動變量 在功能之間分享,
16 // 停留在 256 個字節 idata 空間里面
17 //---------------------------------------------------------------------------
18
19 #include <string.h>
20 #include <stdlib.h>
21 #include "C8051f.h"
22 #include "net.h"
23 #include "eth.h"
24 #include "serial.h"
25 #include "timer.h"
26 #include "analog.h"
27 #include "arp.h"
28 #include "tcp.h"
29 #include "http.h"
30 #include "ip.h"
31
32 sbit LED = P2^0;
33
34 // Global variables
35 UINT volatile event_word;
36 char xdata text[20];
37 UCHAR idata debug;
38 UCHAR idata rcve_buf_allocated;
39
40
41 // This sets my hardware address to 00:01:02:03:04:05
42 UCHAR code my_hwaddr[6] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05};
43
44 // Hardware addr to send a broadcast
45 UCHAR code broadcast_hwaddr[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
46
47 // This sets my IP address to 192.168.0.10
48 ULONG code my_ipaddr = 0xC0A85B10L;
49
50 // This sets my subnet mask to 255.255.255.0
51 ULONG code my_subnet = 0xFFFFFF00L;
52
53 // Set to 0 if no gateway is present on network
54 ULONG code gateway_ipaddr = 0;
55
C51 COMPILER V7.05 MAIN 10/22/2008 23:56:44 PAGE 2
56 //--------------------------------------------------------------------------
57 // Initialize the memory management routines
58 // Initialize variables declared in main
59 //--------------------------------------------------------------------------
60
61 unsigned int Count1msInc;
62 unsigned char Count1ms,Count10ms,Count1s;
63 unsigned char TimeSecond,TimeMinute;
64
65 void init_main(void)
66 {
67 1 // Start the memory pool for incoming and outgoing Ethernet
68 1 // frames at 1000, with length = 1500 bytes. Memory below 500
69 1 // is used for program variables
70 1 init_mempool((void xdata *)1000, 1500);
71 1 memset(text, 0, sizeof(text));
72 1 event_word = 0;
73 1 rcve_buf_allocated = FALSE;
74 1 debug = FALSE;
75 1 }
76
77 void PORT_Init (void)
78 {
79 1 XBR0 = 0x07; // Enable SMBus, SPI0, and UART0
80 1 XBR1 = 0x00;
81 1 XBR2 = 0x44; // Enable crossbar and weak pull-ups
82 1 EMI0TC = 0x21;
83 1 P74OUT = 0xFF;
84 1 P0MDOUT = 0x15;
85 1 }
86
87 void SPI0_Init (void)
88 {
89 1 SPI0CFG = 0x07; // data sampled on 1st SCK rising edge
90 1 // 8-bit data words
91 1 SPI0CFG|=0xC0; //CKPOL =1;
92 1
93 1 SPI0CN = 0x03; // Master mode; SPI enabled; flags
94 1 // cleared
95 1 SPI0CKR = SYSCLK/2/8000000-1; // SPI clock <= 8MHz (limited by
96 1 // EEPROM spec.)
97 1 }
98
99 void Timer0_Init (void)
100 {
101 1 CKCON|=0x8;
102 1 TMOD|=0x1; //16Bit
103 1 Count10ms=10;
104 1 Count1s=0;
105 1 TR0 = 0; // STOP Timer0
106 1 TH0 = (-SYSCLK/1000) >> 8; // set Timer0 to overflow in 1ms
107 1 TL0 = -SYSCLK/1000;
108 1 TR0 = 1; // START Timer0
109 1 IE|= 0x2;
110 1 }
111 void SYSCLK_Init (void)
112 {
113 1 int i; // delay counter
114 1 OSCXCN = 0x67; // start external oscillator with
115 1 // 18.432MHz crystal
116 1 for (i=0; i < 256; i++) ; // Wait for osc. to start up
117 1 while (!(OSCXCN & 0x80)) ; // Wait for crystal osc. to settle
C51 COMPILER V7.05 MAIN 10/22/2008 23:56:44 PAGE 3
118 1 OSCICN = 0x88; // select external oscillator as SYSCLK
119 1 // source and enable missing clock
120 1 // detector
121 1 // OSCICN = 0x07; //interal 16MHZ
122 1 }
123 void Timer0_ISR (void) interrupt 1 //1ms
124 {
125 1 TH0 = (-SYSCLK/1000) >> 8;
126 1 TL0 = -SYSCLK/1000;
127 1 if (Count1ms) Count1ms--;
128 1 Count1msInc++;
129 1 if (Count10ms) Count10ms--;
130 1 else
131 1 {
132 2 Count10ms=10; //10ms
133 2 if (Count1s) Count1s--;
134 2 else
135 2 {
136 3 Count1s=100; //1s
137 3 TimeSecond++;
138 3 if (TimeSecond>=60)
139 3 {
140 4 TimeSecond=0; //1min
141 4 TimeMinute++;
142 4 if (TimeMinute==60) TimeMinute=0;
143 4 }
144 3 }
145 2 }
146 1 }
147
148
149 void Delay1ms(unsigned char T)
150 {
151 1 Count1ms=T;
152 1 while (Count1ms);
153 1 }
154
155 /*通過SPI發送一字節*/
156 #define CHIP595_SELECT P5 &= ~(0x10); // P54
157 #define CHIP_NOSELECT P5 |= 0xf8; // P53-57
158
159 void SendSPIByte(unsigned char ch)
160 {
161 1 SPIF = 0;
162 1 SPI0DAT = ch;
163 1 while (SPIF == 0); // wait for data transfer to be completed
164 1 }
165
166 void LightONOFF(bit b)
167 {
168 1 // CHIP_NOSELECT;
169 1 // CHIP595_SELECT;
170 1 // SendSPIByte(0x0);
171 1 if (b)
172 1 {
173 2 // SendSPIByte(0x01);
174 2 LED=0;
175 2 }
176 1 else
177 1 {
178 2 // SendSPIByte(0x00);
179 2 LED=1;
C51 COMPILER V7.05 MAIN 10/22/2008 23:56:44 PAGE 4
180 2 }
181 1 // CHIP_NOSELECT;
182 1
183 1
184 1 }
185
186
187 void main (void)
188 {
189 1 UINT j, event_word_copy;
190 1 UCHAR xdata * inbuf;
191 1
192 1 WDTCN = 0xDE; // Disable watchdog timer
193 1 WDTCN = 0xAD;
194 1
195 1 EMI0CF =0x24; // share low 4K XRAM
196 1 SYSCLK_Init (); // initialize oscillator
197 1 Timer0_Init();
198 1 PORT_Init (); // initialize crossbar and GPIO
199 1 SPI0_Init (); // initialize SPI0
200 1
201 1 init_main();
202 1 init_tcp();
203 1 init_http();
204 1
205 1 EA=1;
206 1 init_serial();
207 1 SendCommString("Init OK\r\n");
208 1
209 1 init_adc();
210 1 init_timer2();
211 1 init_arp();
212 1 init_8019();
213 1
214 1
215 1
216 1 j = 0;
217 1 ET2 = 1; // Enable timer 2 interrupt
218 1
219 1 // The code below is a priority based RTOS. The event
220 1 // handlers are in priority order - highest priority first.
221 1 while (1)
222 1 {
223 2 // Query CS8900A to see if Ethernet frame has arrived
224 2 // If so, set EVENT_ETH_ARRIVED bit in event_word
225 2 query_8019();
226 2
227 2 // Use a copy of event word to avoid interference
228 2 // with interrupts
229 2 EA = 0;
230 2 event_word_copy = event_word;
231 2 EA = 1;
232 2
233 2 // See if an Ethernet frame has arrived
234 2 if (event_word_copy & EVENT_ETH_ARRIVED)
235 2 {
236 3 EA = 0;
237 3 event_word &= (~EVENT_ETH_ARRIVED);
238 3 EA = 1;
239 3
240 3 // Allocate a buffer and read frame from CS8900A
241 3 inbuf = rcve_frame();
C51 COMPILER V7.05 MAIN 10/22/2008 23:56:44 PAGE 5
242 3 if (inbuf != NULL)
243 3 {
244 4 // Process the received Ethernet frame
245 4 eth_rcve(inbuf);
246 4
247 4 // If the memory allocated for the rcve message has
248 4 // not already been freed then free it now
249 4 if (rcve_buf_allocated)
250 4 {
251 5 free(inbuf);
252 5 rcve_buf_allocated = FALSE;
253 5 }
254 4 }
255 3 }
256 2
257 2 // See if TCP retransmit timer has expired
258 2 else if (event_word_copy & EVENT_TCP_RETRANSMIT)
259 2 {
260 3 EA = 0;
261 3 event_word &= (~EVENT_TCP_RETRANSMIT);
262 3 EA = 1;
263 3 tcp_retransmit();
264 3 }
265 2
266 2 // See if TCP inactivity timer has expired
267 2 else if (event_word_copy & EVENT_TCP_INACTIVITY)
268 2 {
269 3 EA = 0;
270 3 event_word &= (~EVENT_TCP_INACTIVITY);
271 3 EA = 1;
272 3 tcp_inactivity();
273 3 }
274 2
275 2 // See if ARP retransmit timer has expired
276 2 else if (event_word_copy & EVENT_ARP_RETRANSMIT)
277 2 {
278 3 EA = 0;
279 3 event_word &= (~EVENT_ARP_RETRANSMIT);
280 3 EA = 1;
281 3 arp_retransmit();
282 3 }
283 2
284 2 // See if it is time to age the ARP cache
285 2 else if (event_word_copy & EVENT_AGE_ARP_CACHE)
286 2 {
287 3 EA = 0;
288 3 event_word &= (~EVENT_AGE_ARP_CACHE);
289 3 EA = 1;
290 3 age_arp_cache();
291 3 }
292 2
293 2 // See if it is time to read the analog inputs
294 2 else if (event_word_copy & EVENT_READ_ANALOG)
295 2 {
296 3 EA = 0;
297 3 event_word &= (~EVENT_READ_ANALOG);
298 3 EA = 1;
299 3 // Read one of the 3 analog inputs each time
300 3 read_analog_inputs();
301 3 }
302 2
303 2 // See if an RS232 message has arrived. It is
C51 COMPILER V7.05 MAIN 10/22/2008 23:56:44 PAGE 6
304 2 // not handled - RS232 is used for sending only
305 2 else if (event_word_copy & EVENT_RS232_ARRIVED)
306 2 {
307 3 EA = 0;
308 3 event_word &= (~EVENT_RS232_ARRIVED);
309 3 EA = 1;
310 3 }
311 2 }
312 1 }
313
314
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 446 ----
CONSTANT SIZE = 34 ----
XDATA SIZE = 20 ----
PDATA SIZE = ---- ----
DATA SIZE = 9 6
IDATA SIZE = 2 ----
BIT SIZE = ---- 1
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -