📄 net.lst
字号:
C51 COMPILER V7.06 NET 02/28/2008 17:09:34 PAGE 1
C51 COMPILER V7.06, COMPILATION OF MODULE NET
OBJECT MODULE PLACED IN net.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE net.c BROWSE DEBUG OBJECTEXTEND
stmt level source
1 //********************************************
2 // 网络通信子程序
3 // 2007.4.13
4 // Passion
5 //********************************************
6 #include "reg51.h"
7 #include <string.h>
8 #include <stdlib.h>
9 #include <absacc.h>
10 #include <uart.h>
11
12 sbit P3_4 = P3^4;
13 //*************************************************************************
14 #define H_H_Length pac_head[16]
15 #define L_H_Length pac_head[17]
16 #define H_CRC Send_Buff[24]
17 #define L_CRC Send_Buff[25]
18 #define H_Loc_Port pac_head[34]
19 #define L_Loc_Port pac_head[35]
20 #define H_Aim_Port pac_head[36]
21 #define L_Aim_Port pac_head[37]
22 #define H_UDP_Length pac_head[38]
23 #define L_UDP_Length pac_head[39]
24 #define HUDPCRC Send_Buff[40]
25 #define LUDPCRC Send_Buff[41]
26 #define reg00 XBYTE[0x8000] //reg00- 10为isa网卡接口的寄存器地址300-310;
27 #define reg01 XBYTE[0x8001]
28 #define reg02 XBYTE[0x8002]
29 #define reg03 XBYTE[0x8003]
30 #define reg04 XBYTE[0x8004]
31 #define reg05 XBYTE[0x8005]
32 #define reg06 XBYTE[0x8006]
33 #define reg07 XBYTE[0x8007]
34 #define reg08 XBYTE[0x8008]
35 #define reg09 XBYTE[0x8009]
36 #define reg0a XBYTE[0x800a]
37 #define reg0b XBYTE[0x800b]
38 #define reg0c XBYTE[0x800c]
39 #define reg0d XBYTE[0x800d]
40 #define reg0e XBYTE[0x800e]
41 #define reg0f XBYTE[0x800f]
42 #define reg10 XBYTE[0x8010]
43 #define reg1f XBYTE[0x801f]
44 #define Reset_Low P3_4 = 0;//P5 &= ~(0x4); // P52
45 #define Reset_High P3_4 = 1;//P5 |= 0x4; // P52
46 //**********************************************************************
47
48 //extern void InitUART();
49
50 void UDP_Send(void); //UDP协议发送处理
51 void UDP_Recv(void);
52 void page_select(unsigned char pagenumber); //RTL8019页选择函数
53 void read_mac_add(void); //RTL8019网卡MAC读取函数
54 void Reset_8019(void); //RTL8019复位函数
55 void RTL8019_init(void); //RTL8019初始化函数
C51 COMPILER V7.06 NET 02/28/2008 17:09:34 PAGE 2
56 bit RTL8019_receive(void); //RTL8019接收函数
57 void PORT_Init (void); //C8051F020端口初始化
58 void write_mac_add(void); //写网卡物理地址
59 void SYSCLK_Init (void); //外部时钟初始化
60 void RTL8019_send(void); //RTL8019发送函数
61 void ARP_Request(); //ARP请求处理
62 //void ARP_Answer(void);
63 void RARP(void); //ARP应答处理
-
64 bit ARP_Process(void); //ARP请求包处理
65 bit IP_Process(void); //IP包处理
66 bit UDP_Process(void); //UDP包处理
67 bit WRQ_Process(void); //WRQ包处理
68 bit DATA_Process(void); //DATA包处理
69 bit OVER_Process(void); //OVER包处理
70 void ACK_Send(unsigned int count); //ACK包发送
71 void Pag_TimeOut(void); //数据包接收超时
72 void Config_Timmer(void); //定时器配置函数
-
73 unsigned int CRC_Process(unsigned char LEN,unsigned char mov,unsigned char type); //校验位生成函数
74 //***********************************************************************
75 unsigned int kk;
76 unsigned int Protocol;
77 unsigned int Pag_Head; //包头寄存器
78 unsigned int Loc_Port; //源端口
79 unsigned int Aim_Port; //目的端口
80 unsigned int Package=0; //块寄存器
81 unsigned int Count_Pag=1; //块计数器
82 unsigned int H_Package=0; //总数据块数
83 unsigned int ms=0; //毫秒计时
84 unsigned char s=0; //秒计时
85 unsigned char min=0; //分计时
86 unsigned char xdata Send_Buff[558]={0x00}; //发送缓存
87 unsigned char xdata Receive_Buff[68]={0x00}; //接收缓存
88 unsigned char bnry;
89 unsigned char curr;
90 unsigned char xdata A_m_a[6]={0x00}; //目的物理地址
91 unsigned char xdata A_IP_add[4]={0x00}; //目的IP地址
92 unsigned char xdata hard_add[6]={0x00,0x01,0x02,0x03,0x04,0x05}; //网卡物理地址
93 //unsigned char IP_add[4]={0x0a,0x05,0x84,0xd9}; //网卡IP地址
94 unsigned char xdata IP_add[4]={13,2,168,192}; //网卡IP地址
95 unsigned char xdata UDP_F_Head[12]={0x00}; //UDP伪头
96 unsigned char xdata DATA_Buff[512]={0x00}; //接收数据缓存
97 unsigned char xdata pac_head[42]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x02,0x03,0x04,0x05,
98 0x08,0x00,0x45,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x11,
99 0x00,0x00,0x0a,0x05,0x84,0xd9,0x00,0x00,0x00,0x00,0x00,0x00,
100 0x00,0x00,0x00,0x00,0x00,0x00}; //UDP数据包
101
102
103 //***********************************************************************
104 void main(void)
105 {
106 1 unsigned char i;
107 1 InitUART();
108 1
109 1 // WDTCN = 0xDE; // Disable watchdog timer
110 1 // WDTCN = 0xAD;
111 1 // EMI0CF =0x24;
112 1
113 1 Prints("asdfasldfhalsdjfalsdfhas\r\n");
114 1
115 1 SYSCLK_Init ();
C51 COMPILER V7.06 NET 02/28/2008 17:09:34 PAGE 3
116 1
117 1 PORT_Init();
118 1
119 1 RTL8019_init();
120 1
121 1 for(i=0;i<6;i++)
122 1 hard_add[i]=i;
123 1
124 1 while(1)
125 1 {
126 2 //P2=0x00;
127 2 //if(ms>5)
128 2 //Pag_TimeOut();
129 2 //if(s>1)
130 2 //Request_TimeOut();
131 2 //if(min>=1)
132 2 //OFF_TimeOut();
133 2 RTL8019_receive(); //接收一个数据包
134 2
135 2 for(i=0;i<68;i++)
136 2 PrintHex(Receive_Buff[i]);
137 2
138 2 Prints("\r\n\r\n\r\n");
139 2
140 2 Protocol=Receive_Buff[16];
141 2
142 2 //Prints("Protocol: ");
143 2 //PrintHex(Protocol);
144 2 //Prints("\r\n");
145 2
146 2 Protocol=Protocol<<8;
147 2 Protocol+=Receive_Buff[17]; //取出协议类型
148 2 if(Protocol!=0x0806&&Protocol!=0x0800)
149 2 {
150 3 //PrintLongIntHex(Protocol);
151 3 //Prints(" continue\r\n");
152 3 continue; //既不是ARP包也不是IP包则丢弃
153 3 }
154 2 else if(Protocol==0x0806) //若为ARP包
155 2 {
156 3 Prints("ARP_Process();Protocol==0x0806\r\n");
157 3 ARP_Process(); //ARP包处理函数
158 3 }
159 2 else
160 2 {
161 3 Prints("IP_Process();\r\n");
162 3 IP_Process(); //IP报处理函数
163 3 }
164 2 }
165 1 }
166 //*********************************************************************
167 bit ARP_Process(void)
168 {
169 1 unsigned char i;
170 1
171 1 for(i=42;i<46;i++)
172 1 {
173 2 if(Receive_Buff[i]!=IP_add[i-42]) //是否与本地IP地址相符
174 2 return 0;
175 2 }
176 1 for(i=0;i<6;i++)
177 1 A_m_a[i]=Receive_Buff[i+10]; //取出客户机物理地址
C51 COMPILER V7.06 NET 02/28/2008 17:09:34 PAGE 4
178 1 for(i=0;i<4;i++)
179 1 A_IP_add[i]=Receive_Buff[i+32]; //取出客户机IP地址
180 1 if(Receive_Buff[25]==0x01) //是否为ARP请求
181 1 RARP(); //应答
182 1 return 1;
183 1 }
184 //*********************************************************************
185 bit IP_Process(void)
186 {
187 1 unsigned char i;
188 1 for(i=0;i<6;i++)
189 1 {
190 2 if(Receive_Buff[4+i]!=hard_add[i])
191 2 return 0;
192 2 }
193 1 if(Receive_Buff[27]!=0x11) //上层协议是否为UDP
194 1 return 0;
195 1 else
196 1 {
197 2 for(i=0;i<6;i++)
198 2 A_m_a[i]=Receive_Buff[i+10]; //取出客户机物理地址
199 2 for(i=0;i<4;i++)
200 2 A_IP_add[i]=Receive_Buff[i+30]; //取出客户机IP地址
201 2 UDP_Process(); //UDP报处理函数
202 2 return 1;
203 2 }
204 1 }
205 //*********************************************************************
206 bit UDP_Process(void)
207 {
208 1 unsigned int Pag_Head;
209 1 Aim_Port=Receive_Buff[38];
210 1 Aim_Port<<=8;
211 1 Aim_Port+=Receive_Buff[39]; //取出源端口装入目的端口寄存器
212 1 Loc_Port=Receive_Buff[40];
213 1 Loc_Port<<=8;
214 1 Loc_Port+=Receive_Buff[41]; //取出目的端口装入源端口
215 1 Pag_Head=Receive_Buff[46];
216 1 Pag_Head<<=8;
217 1 Pag_Head+=Receive_Buff[47];
218 1 if(Pag_Head>=0x0004||Pag_Head<0x0000) //检验数据包头
219 1 return 0;
220 1 else if(Pag_Head==0x0000) //如果为写请求WRQ
221 1 {
222 2 s=0;
223 2 ms=0;
224 2 WRQ_Process(); //WRQ报处理函数
225 2 return 1;
226 2 }
227 1 else if(Pag_Head==0x0001) //如果为数据块包
228 1 {
229 2 ms=0;
230 2 DATA_Process(); //DATA报处理函数
231 2 return 1;
232 2 }
233 1 else if(Pag_Head==0x0003) //如果为完成标示OVER
234 1 {
235 2 min=0;
236 2 s=0;
237 2 ms=0;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -