📄 main.lst
字号:
C51 COMPILER V8.02 MAIN 10/17/2007 22:25:39 PAGE 1
C51 COMPILER V8.02, COMPILATION OF MODULE MAIN
OBJECT MODULE PLACED IN .\main.obj
COMPILER INVOKED BY: D:\Program File\keil\C51\BIN\C51.EXE ..\App\main.c BROWSE DEBUG OBJECTEXTEND PRINT(.\main.lst) OBJE
-CT(.\main.obj)
line level source
1 /*
2 * Copyright (c) 2003 Electric Application Laboratory of NAN KAI University
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without modification,
6 * are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 * 3. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
19 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
21 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
24 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
25 * OF SUCH DAMAGE.
26 *
27 * Author: Li Zhanglin <wzzlin@nankai.edu.cn>
28 *
29 */
30
31 #include "..\GloblDef\GloblDef.h"
32 #include "..\TCPIP\TCPIPmem.h"
33 #include "..\Netif\RTL8019.h"
34 #include "..\TCPIP\IP.h"
35 #include "..\Netif\etherif.h"
36 #include "..\Netif\ARP.h"
37 #include "..\TCPIP\Netif.h"
38 #include "..\TCPIP\TCP.h"
39 #include "..\App\main.h"
40
41 #define DATA_SIZE 0x500
42
43 #define IP4_ADDR(a,b,c,d) ((unsigned long)(a & 0xff) << 24) | ((unsigned long)(b & 0xff) << 16) | \
44 ((unsigned long)(c & 0xff) << 8) | (unsigned long)(d & 0xff)
45
46 BYTE DT_XDATA DataBlock[DATA_SIZE];
47 BYTE DT_XDATA str[]="hello";
48 socket DT_XDATA * DT_XDATA ExConn;
49 socket DT_XDATA * DT_XDATA ExAccept;
50 socket DT_XDATA * DT_XDATA ExListen;
51
52
53 void OnReceive(void DT_XDATA * buf,WORD size) REENTRANT_MUL
54 {
C51 COMPILER V8.02 MAIN 10/17/2007 22:25:39 PAGE 2
55 1 /* send back data */
56 1 TCPSend(ExConn,buf,size);
57 1 }
58 void OnAcceptRecv(void DT_XDATA *buf,WORD size) REENTRANT_MUL
59 {
60 1 /* printf received data */
61 1 #ifdef DEBUG
while(size--)
printf("%c",*((BYTE DT_XDATA *)buf)++);
#endif
65 1
66 1 /* send back data */
67 1 TCPSend(ExAccept,buf,size);
68 1 }
69 void OnAccept(socket DT_XDATA *pNewSocket) REENTRANT_MUL
70 {
71 1 ExAccept = pNewSocket;
72 1 pNewSocket->recv = OnAcceptRecv;
73 1 pNewSocket->close = OnClose;
74 1 }
75 void OnClose(socket DT_XDATA * pSocket) REENTRANT_MUL
76 {
77 1 TCPClose(pSocket); /* we close too */
78 1 }
79 void Timer() REENTRANT_MUL interrupt 1
80 {
81 1 TH0 = 0x3C; /*TIMER_24M_25MS_H;*/
82 1 TL0 = 0xAA; /*TIMER_24M_25MS_L;*/
83 1
84 1 NetIfTimer();
85 1 ARPTimer();
86 1 TCPTimer();
87 1 }
88
89 void SerialInit()
90 {
91 1 /* set TI to 1, set TR1 to 1 */
92 1 SCON = 0x52;/* SM0 SM1 =1 SM2 REN TB8 RB8 TI RI */
93 1 TMOD = 0x20;/* GATE=0 C/T-=0 M1 M0=2 GATE C/T- M1 M0 */
94 1 TH1 = 0xE6; /* TH1=E6 4800 when at 24MHz,TH1=F3,9600,24MHz */
95 1 PCON = 0x80;
96 1 TCON = 0x40;/* 01101001 TF1 TR1 TF0 TR0 IE1 IT1 IE0 IT */
97 1 }
98
99 void InterruptInit()
100 {
101 1 TMOD |= 0x01;
102 1 TH0 = 0x3C; /*TIMER_24M_25MS_H;*/
103 1 TL0 = 0xAA; /*TIMER_24M_25MS_L;*/
104 1 TR0 = 1;
105 1
106 1 /* open interrupt for rtl and timer */
107 1 EA = 1;
108 1 /* EX0 = 1; */
109 1 ET0 = 1;
110 1 }
111 main()
112 {
113 1 struct SMemHead DT_XDATA *MemHead;
114 1 struct SEtherDevice DT_XDATA DevRTL;
115 1 BYTE DT_XDATA EtherAddr[ETHER_ADDR_LEN] = {0x52,0x54,0x4c,0x30,0x2e,0x2f};
116 1 IP_ADDR IPAddr = IP4_ADDR(192,168,1,10); //本机地址
C51 COMPILER V8.02 MAIN 10/17/2007 22:25:39 PAGE 3
117 1 IP_ADDR IPAddrConnect = IP4_ADDR(192,168,1,11); //连接地址
118 1 IP_ADDR NetMask = IP4_ADDR(255,255,255,0);
119 1 IP_ADDR GateWay = IP4_ADDR(192,168,1,1);
120 1
121 1 /*
122 1 * init
123 1 */
124 1 /* init. the order is not important */
125 1 NetIfInit();
126 1 ARPInit();
127 1 TCPInit();
128 1 MemInit();
129 1 RTLInit(EtherAddr);
130 1
131 1 /* init Devcie struct and init this device */
132 1 EtherDevInit(&DevRTL,EtherAddr,RTLSendPacket,RTLReceivePacket);
133 1
134 1 /* add this device to NetIf */
135 1 NetIfAdd(IPAddr,NetMask,GateWay,EtherInput,EtherOutput,&DevRTL);
136 1
137 1 /*
138 1 * start use socket
139 1 */
140 1 SerialInit();
141 1 InterruptInit();
142 1 TRACE("start");
143 1
144 1 /* Illustrate how to listen as a server */
145 1 ExListen = TCPSocket(IPAddr);
146 1 ExAccept = NULL;
147 1 TCPListen(ExListen,TCP_DEFAULT_PORT,OnAccept);
148 1
149 1 /* Illustrate how to connect to a server */
150 1 ExConn = TCPSocket(IPAddr);
151 1 if(TCPConnect(ExConn,IPAddrConnect,1001,OnReceive,OnClose) == TRUE)
152 1 {
153 2 /* Illustrate how to Use TCPSend() */
154 2 TCPSend(ExConn,str,6);
155 2
156 2 /* Illustrate how to Use TCPSendEx() */
157 2 while(1)
158 2 {
159 3 if((MemHead = TCPAllocate(DATA_SIZE)) == NULL)
160 3 break;
161 3 MemCopy(MemHead->pStart,DataBlock,DATA_SIZE);
162 3 if(TCPSendEx(ExConn,MemHead) == FALSE)
163 3 break;
164 3 }
165 2 }
166 1
167 1 TCPAbort(ExConn);
168 1
169 1 while(1);
170 1 }
171
172
173
174
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 568 ----
C51 COMPILER V8.02 MAIN 10/17/2007 22:25:39 PAGE 4
CONSTANT SIZE = 6 ----
XDATA SIZE = 1292 16
PDATA SIZE = ---- ----
DATA SIZE = ---- 18
IDATA SIZE = ---- ----
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 + -