📄 main.lst
字号:
C51 COMPILER V7.01 MAIN 04/30/2003 15:22:10 PAGE 1
C51 COMPILER V7.01, COMPILATION OF MODULE MAIN
OBJECT MODULE PLACED IN Main.OBJ
COMPILER INVOKED BY: D:\SOFT\KEIL\C51\BIN\C51.EXE Main.c BROWSE DEBUG OBJECTEXTEND
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 //---------------------------------------------------------------------------
15
16 #include <string.h>
17 #include <stdlib.h>
18 #include "C8051f.h"
19 #include "net.h"
20 #include "eth.h"
21 #include "serial.h"
22 #include "timer.h"
23 #include "analog.h"
24 #include "arp.h"
25 #include "tcp.h"
26 #include "http.h"
27 #include "ip.h"
28
29
30 // Global variables
31 UINT volatile event_word;
32 char xdata text[20];
33 UCHAR idata debug;
34 UCHAR idata rcve_buf_allocated;
35
36
37 // This sets my hardware address to 00:01:02:03:04:05
38 UCHAR code my_hwaddr[6] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05};
39
40 // Hardware addr to send a broadcast
41 UCHAR code broadcast_hwaddr[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
42
43 // This sets my IP address to 192.168.0.10
44 ULONG code my_ipaddr = 0xC0A8000AL;
45
46 // This sets my subnet mask to 255.255.255.0
47 ULONG code my_subnet = 0xFFFFFF00L;
48
49 // Set to 0 if no gateway is present on network
50 ULONG code gateway_ipaddr = 0;
51
52 //--------------------------------------------------------------------------
53 // Initialize the memory management routines
54 // Initialize variables declared in main
55 //--------------------------------------------------------------------------
C51 COMPILER V7.01 MAIN 04/30/2003 15:22:10 PAGE 2
56
57 unsigned int Count1msInc;
58 unsigned char Count1ms,Count10ms,Count1s;
59 unsigned char TimeSecond,TimeMinute;
60
61 void init_main(void)
62 {
63 1 // Start the memory pool for incoming and outgoing Ethernet
64 1 // frames at 1000, with length = 1500 bytes. Memory below 500
65 1 // is used for program variables
66 1 init_mempool((void xdata *)1000, 1500);
67 1 memset(text, 0, sizeof(text));
68 1 event_word = 0;
69 1 rcve_buf_allocated = FALSE;
70 1 debug = FALSE;
71 1 }
72
73 void PORT_Init (void)
74 {
75 1 XBR0 = 0x07; // Enable SMBus, SPI0, and UART0
76 1 XBR1 = 0x00;
77 1 XBR2 = 0x44; // Enable crossbar and weak pull-ups
78 1 EMI0TC = 0x21;
79 1 P74OUT = 0xFF;
80 1 P0MDOUT = 0x15;
81 1 }
82
83 void SPI0_Init (void)
84 {
85 1 SPI0CFG = 0x07; // data sampled on 1st SCK rising edge
86 1 // 8-bit data words
87 1 SPI0CFG|=0xC0; //CKPOL =1;
88 1
89 1 SPI0CN = 0x03; // Master mode; SPI enabled; flags
90 1 // cleared
91 1 SPI0CKR = SYSCLK/2/8000000-1; // SPI clock <= 8MHz (limited by
92 1 // EEPROM spec.)
93 1 }
94
95 void Timer0_Init (void)
96 {
97 1 CKCON|=0x8;
98 1 TMOD|=0x1; //16Bit
99 1 Count10ms=10;
100 1 Count1s=0;
101 1 TR0 = 0; // STOP Timer0
102 1 TH0 = (-SYSCLK/1000) >> 8; // set Timer0 to overflow in 1ms
103 1 TL0 = -SYSCLK/1000;
104 1 TR0 = 1; // START Timer0
105 1 IE|= 0x2;
106 1 }
107 void SYSCLK_Init (void)
108 {
109 1 int i; // delay counter
110 1 OSCXCN = 0x67; // start external oscillator with
111 1 // 18.432MHz crystal
112 1 for (i=0; i < 256; i++) ; // Wait for osc. to start up
113 1 while (!(OSCXCN & 0x80)) ; // Wait for crystal osc. to settle
114 1 OSCICN = 0x88; // select external oscillator as SYSCLK
115 1 // source and enable missing clock
116 1 // detector
117 1 // OSCICN = 0x07; //interal 16MHZ
C51 COMPILER V7.01 MAIN 04/30/2003 15:22:10 PAGE 3
118 1 }
119 void Timer0_ISR (void) interrupt 1 //1ms
120 {
121 1 TH0 = (-SYSCLK/1000) >> 8;
122 1 TL0 = -SYSCLK/1000;
123 1 if (Count1ms) Count1ms--;
124 1 Count1msInc++;
125 1 if (Count10ms) Count10ms--;
126 1 else
127 1 {
128 2 Count10ms=10; //10ms
129 2 if (Count1s) Count1s--;
130 2 else
131 2 {
132 3 Count1s=100; //1s
133 3 TimeSecond++;
134 3 if (TimeSecond>=60)
135 3 {
136 4 TimeSecond=0; //1min
137 4 TimeMinute++;
138 4 if (TimeMinute==60) TimeMinute=0;
139 4 }
140 3 }
141 2 }
142 1 }
143
144
145 void Delay1ms(unsigned char T)
146 {
147 1 Count1ms=T;
148 1 while (Count1ms);
149 1 }
150
151 /*通过SPI发送一字节*/
152 #define CHIP595_SELECT P5 &= ~(0x10); // P54
153 #define CHIP_NOSELECT P5 |= 0xf8; // P53-57
154
155 void SendSPIByte(unsigned char ch)
156 {
157 1 SPIF = 0;
158 1 SPI0DAT = ch;
159 1 while (SPIF == 0); // wait for data transfer to be completed
160 1 }
161
162 void LightONOFF(bit b)
163 {
164 1 CHIP_NOSELECT;
165 1 CHIP595_SELECT;
166 1 SendSPIByte(0x0);
167 1 if (b)
168 1 {
169 2 SendSPIByte(0x01);
170 2 }
171 1 else
172 1 {
173 2 SendSPIByte(0x00);
174 2 }
175 1 CHIP_NOSELECT;
176 1 }
177
178
179 void main (void)
C51 COMPILER V7.01 MAIN 04/30/2003 15:22:10 PAGE 4
180 {
181 1 UINT j, event_word_copy;
182 1 UCHAR xdata * inbuf;
183 1
184 1 WDTCN = 0xDE; // Disable watchdog timer
185 1 WDTCN = 0xAD;
186 1
187 1 EMI0CF =0x24; // share low 4K XRAM
188 1 SYSCLK_Init (); // initialize oscillator
189 1 Timer0_Init();
190 1 PORT_Init (); // initialize crossbar and GPIO
191 1 SPI0_Init (); // initialize SPI0
192 1
193 1 init_main();
194 1 init_tcp();
195 1 init_http();
196 1
197 1 EA=1;
198 1 init_serial();
199 1 SendCommString("Init OK\r\n");
200 1
201 1 init_adc();
202 1 init_timer2();
203 1 init_arp();
204 1 init_8019();
205 1
206 1
207 1
208 1 j = 0;
209 1 ET2 = 1; // Enable timer 2 interrupt
210 1
211 1 // The code below is a priority based RTOS. The event
212 1 // handlers are in priority order - highest priority first.
213 1 while (1)
214 1 {
215 2 // Query CS8900A to see if Ethernet frame has arrived
216 2 // If so, set EVENT_ETH_ARRIVED bit in event_word
217 2 query_8019();
218 2
219 2 // Use a copy of event word to avoid interference
220 2 // with interrupts
221 2 EA = 0;
222 2 event_word_copy = event_word;
223 2 EA = 1;
224 2
225 2 // See if an Ethernet frame has arrived
226 2 if (event_word_copy & EVENT_ETH_ARRIVED)
227 2 {
228 3 EA = 0;
229 3 event_word &= (~EVENT_ETH_ARRIVED);
230 3 EA = 1;
231 3
232 3 // Allocate a buffer and read frame from CS8900A
233 3 inbuf = rcve_frame();
234 3 if (inbuf != NULL)
235 3 {
236 4 // Process the received Ethernet frame
237 4 eth_rcve(inbuf);
238 4
239 4 // If the memory allocated for the rcve message has
240 4 // not already been freed then free it now
241 4 if (rcve_buf_allocated)
C51 COMPILER V7.01 MAIN 04/30/2003 15:22:10 PAGE 5
242 4 {
243 5 free(inbuf);
244 5 rcve_buf_allocated = FALSE;
245 5 }
246 4 }
247 3 }
248 2
249 2 // See if TCP retransmit timer has expired
250 2 else if (event_word_copy & EVENT_TCP_RETRANSMIT)
251 2 {
252 3 EA = 0;
253 3 event_word &= (~EVENT_TCP_RETRANSMIT);
254 3 EA = 1;
255 3 tcp_retransmit();
256 3 }
257 2
258 2 // See if TCP inactivity timer has expired
259 2 else if (event_word_copy & EVENT_TCP_INACTIVITY)
260 2 {
261 3 EA = 0;
262 3 event_word &= (~EVENT_TCP_INACTIVITY);
263 3 EA = 1;
264 3 tcp_inactivity();
265 3 }
266 2
267 2 // See if ARP retransmit timer has expired
268 2 else if (event_word_copy & EVENT_ARP_RETRANSMIT)
269 2 {
270 3 EA = 0;
271 3 event_word &= (~EVENT_ARP_RETRANSMIT);
272 3 EA = 1;
273 3 arp_retransmit();
274 3 }
275 2
276 2 // See if it is time to age the ARP cache
277 2 else if (event_word_copy & EVENT_AGE_ARP_CACHE)
278 2 {
279 3 EA = 0;
280 3 event_word &= (~EVENT_AGE_ARP_CACHE);
281 3 EA = 1;
282 3 age_arp_cache();
283 3 }
284 2
285 2 // See if it is time to read the analog inputs
286 2 else if (event_word_copy & EVENT_READ_ANALOG)
287 2 {
288 3 EA = 0;
289 3 event_word &= (~EVENT_READ_ANALOG);
290 3 EA = 1;
291 3 // Read one of the 3 analog inputs each time
292 3 read_analog_inputs();
293 3 }
294 2
295 2 // See if an RS232 message has arrived. It is
296 2 // not handled - RS232 is used for sending only
297 2 else if (event_word_copy & EVENT_RS232_ARRIVED)
298 2 {
299 3 EA = 0;
300 3 event_word &= (~EVENT_RS232_ARRIVED);
301 3 EA = 1;
302 3 }
303 2 }
C51 COMPILER V7.01 MAIN 04/30/2003 15:22:10 PAGE 6
304 1 }
305
306
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 463 ----
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 + -