📄 main.lst
字号:
C51 COMPILER V7.09 MAIN 07/27/2007 16:06:50 PAGE 1
C51 COMPILER V7.09, COMPILATION OF MODULE MAIN
OBJECT MODULE PLACED IN main.OBJ
COMPILER INVOKED BY: F:\Keil\C51\BIN\C51.EXE main.c LARGE BROWSE DEBUG OBJECTEXTEND
line level source
1 //-----------------------------------------------------------------------------
2 // main.c
3 //-----------------------------------------------------------------------------
4 // Copyright 2006 Silicon Laboratories, Inc.
5 // http://www.silabs.com
6 //
7 // Program Description:
8 //
9 // This file contains the main routine for the CP220x Send and Receive example.
10 //
11 // FID:
12 // Target: Multiple
13 // Tool chain: Keil C51 7.20 / Keil EVAL C51
14 // Silicon Laboratories IDE version 2.72
15 // Command Line: See Readme.txt
16 // Project Name: CP220x_Ethernet_Routines
17 //
18 //
19 //
20 // Release 1.1
21 // - Configures C8051F120 SYSCLK to 98 MHz
22 //
23 // Release 1.0
24 // -Initial Release (FB)
25 // -30 MAY 2006
26
27 //-----------------------------------------------------------------------------
28 // Includes
29 //-----------------------------------------------------------------------------
30 #include "global.h"
31 #include "stdio.h"
32 #include "./tcp/net.h"
33 #include "./tcp/arp.h"
34 #include "./tcp/tcp.h"
35 #include "./tcp/http.h"
36 #include "./tcp/ip.h"
37 #include "./tcp/eth.h"
38
39 uint volatile event_word;
40 char xdata text[20];
41 UCHAR xdata debug;
42 UCHAR xdata rcve_buf_allocated;
43
44
45 // This sets my hardware address to 00:01:02:03:04:05
46 UCHAR xdata my_hwaddr[6] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05};
47
48 // Hardware addr to send a broadcast
49 UCHAR xdata broadcast_hwaddr[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
50
51 // This sets my IP address to 192.168.0.10
52 ulong xdata my_ipaddr = 0xC0A80058L;
53
54 // This sets my subnet mask to 255.255.255.0
55 ulong xdata my_subnet = 0xFFFFFF00L;
C51 COMPILER V7.09 MAIN 07/27/2007 16:06:50 PAGE 2
56
57 // Set to 0 if no gateway is present on network
58 ulong xdata gateway_ipaddr = 0;
59
60 void init_main(void)
61 {
62 1 // Start the memory pool for incoming and outgoing Ethernet
63 1 // frames at 1000, with length = 1500 bytes. Memory below 500
64 1 // is used for program variables
65 1
66 1 memset(text, 0, sizeof(text));
67 1 event_word = 0;
68 1 rcve_buf_allocated = FALSE;
69 1 debug = FALSE;
70 1 }
71
72 void UART0_Init (void);
73 //-----------------------------------------------------------------------------
74 // Function Prototypes
75 //-----------------------------------------------------------------------------
76 void main(void);
77
78 //-----------------------------------------------------------------------------
79 // Global Variables
80 //-----------------------------------------------------------------------------
81
82 IPADDRESS xdata MYIP;
83 MACADDRESS xdata MYMAC;
84 MACADDRESS xdata BROADCASTMAC;
85 MACADDRESS xdata DESTMAC;
86
87 unsigned char xdata RX_BUFF[1000];
88 unsigned char xdata TX_BUFF[1000];
89 unsigned char xdata TFTP_BUF[100];
90 unsigned char xdata UDP_BUF[200];
91
92 //-----------------------------------------------------------------------------
93 // Main Routine
94 //-----------------------------------------------------------------------------
95 sbit LED = P1^6;
96 sbit SW1 = P3^7;
97
98 void main(void)
99 {
100 1 unsigned char error_code;
101 1
102 1 unsigned int num_bytes;
103 1
104 1 //----------------------------------
105 1 // MCU Initialization
106 1 //----------------------------------
107 1
108 1 // Initialize the MCU for Ethernet
109 1 Reset_Init();
110 1 // XBR1 = 0x00;
111 1 // XBR2 = 0x40; // 使能数据交叉开关和弱上拉
112 1
113 1 // P1MDOUT |= 0x40; // 允许P1.6(LED)为推挽输出 LED = 1;
114 1 //uart init
115 1 CPFLASH_ByteWrite(0x00,0x99);
116 1 CPFLASH_ByteWrite(0x01,0x56);
117 1
C51 COMPILER V7.09 MAIN 07/27/2007 16:06:50 PAGE 3
118 1 // aa = CPFLASH_ByteRead(0x01);
119 1 // bb = CPFLASH_ByteRead(0x00);
120 1
121 1
122 1 // Turn off yellow LED.
123 1 YELLOW_LED = 1;
124 1 AB4_LED1 = 0;
125 1 AB4_LED2 = 0;
126 1
127 1 //----------------------------------
128 1 // Initialize Global Variables
129 1 //----------------------------------
130 1
131 1 // Initialize broadcast MAC address
132 1 BROADCASTMAC.Int[0] = 0xFFFF;
133 1 BROADCASTMAC.Int[1] = 0xFFFF;
134 1 BROADCASTMAC.Int[2] = 0xFFFF;
135 1
136 1 // Initialize destination MAC address
137 1 DESTMAC.Int[0] = 0x0012;
138 1 DESTMAC.Int[1] = 0x3F51;
139 1 DESTMAC.Int[2] = 0x3589;
140 1
141 1 // Initialize MYIP address
142 1 MYIP.Char[0] = 0;
143 1 MYIP.Char[1] = 0;
144 1 MYIP.Char[2] = 0;
145 1 MYIP.Char[3] = 1;
146 1
147 1 // Initialize Transmit Buffer
148 1 // for(i = 0; i < sizeof(TX_BUFF); i++)
149 1 // {
150 1 // TX_BUFF[i] = 0;
151 1 // }
152 1
153 1 //----------------------------------
154 1 // Infinite Execution Loop
155 1 // This loop allows the CP220x
156 1 // to be re-initialized each time
157 1 // it is unplugged from a network.
158 1 //----------------------------------
159 1
160 1 #if(UART_ENABLED)
printf("\n\n *** start ***\n");
#endif
163 1 do{
164 2
165 2 //-------------------------------
166 2 // Initialize the CP220x
167 2 //-------------------------------
168 2
169 2 //-----------------------------------------------------------------------
170 2 // Part A: Hardware Reset and Reset Initialization
171 2 //
172 2 // Perform the hardware reset and recommended reset initialization
173 2 // procedure listed in the CP220x datasheet.
174 2 //
175 2 // After completion, check the return code for any of the following
176 2 // possible errors:
177 2 // OSC_ERROR - oscillator error
178 2 // CAL_ERROR - self-initialization error
179 2 // MEM_ERROR - external memory bus error
C51 COMPILER V7.09 MAIN 07/27/2007 16:06:50 PAGE 4
180 2 //-----------------------------------------------------------------------
181 2
182 2 EA = 0; // Disable Interrupts
183 2
184 2 error_code = CP220x_HW_Reset(); // Reset and 初始化 the CP220x
185 2
186 2 // Check for the three possible error codes
187 2 if(error_code & (OSC_ERROR | CAL_ERROR | MEM_ERROR))
188 2 {
189 3 // Print an Error Message
190 3 #if(UART_ENABLED)
printf("\n\n *** Please Reset Device ***\n");
#endif
193 3
194 3 // Place device in an infinite loop if an error occurs
195 3 // while(1);
196 3 }
197 2
198 2 #if(UART_ENABLED)
printf("\n\n *** CP220x_HW_Reset ok ***\n");
#endif
201 2 YELLOW_LED = 1;
202 2 //-----------------------------------------------------------------------
203 2 // Part B: Physical Layer Initialization
204 2 //
205 2 // Initialize the physical layer (PHY) for Autonegotiation
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -