?? main.lst
字號(hào):
C51 COMPILER V6.12 MAIN 05/19/2009 14:55:41 PAGE 1
C51 COMPILER V6.12, COMPILATION OF MODULE MAIN
OBJECT MODULE PLACED IN .\main.obj
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE ..\App\main.c BROWSE DEBUG OBJECTEXTEND PRINT(.\main.lst) OBJECT(.\main.obj
-)
stmt 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 BYTE DT_XDATA DataBlock[DATA_SIZE];
43 BYTE DT_XDATA str[]="hello";
44 socket DT_XDATA * DT_XDATA ExConn;
45 socket DT_XDATA * DT_XDATA ExAccept;
46 socket DT_XDATA * DT_XDATA ExListen;
47
48
49 void OnReceive(void DT_XDATA * buf,WORD size) REENTRANT_MUL
50 {
51 1 /* send back data */
52 1 TCPSend(ExConn,buf,size);
53 1 }
54 void OnAcceptRecv(void DT_XDATA *buf,WORD size) REENTRANT_MUL
C51 COMPILER V6.12 MAIN 05/19/2009 14:55:41 PAGE 2
55 {
56 1 /* printf received data */
57 1 #ifdef DEBUG
while(size--)
printf("%c",*((BYTE DT_XDATA *)buf)++);
#endif
61 1
62 1 /* send back data */
63 1 TCPSend(ExAccept,buf,size);
64 1 }
65 void OnAccept(socket DT_XDATA *pNewSocket) REENTRANT_MUL
66 {
67 1 ExAccept = pNewSocket;
68 1 pNewSocket->recv = OnAcceptRecv;
69 1 pNewSocket->close = OnClose;
70 1 }
71 void OnClose(socket DT_XDATA * pSocket) REENTRANT_MUL
72 {
73 1 TCPClose(pSocket); /* we close too */
74 1 }
75 void Timer() REENTRANT_MUL interrupt 1
76 {
77 1 TH0 = 0x3C; /*TIMER_24M_25MS_H;*/
78 1 TL0 = 0xAA; /*TIMER_24M_25MS_L;*/
79 1
80 1 NetIfTimer();
81 1 ARPTimer();
82 1 TCPTimer();
83 1 }
84
85 void SerialInit()
86 {
87 1 /* set TI to 1, set TR1 to 1 */
88 1 SCON = 0x52;/* SM0 SM1 =1 SM2 REN TB8 RB8 TI RI */
89 1 TMOD = 0x20;/* GATE=0 C/T-=0 M1 M0=2 GATE C/T- M1 M0 */
90 1 TH1 = 0xE6; /* TH1=E6 4800 when at 24MHz,TH1=F3,9600,24MHz */
91 1 PCON = 0x80;
92 1 TCON = 0x40;/* 01101001 TF1 TR1 TF0 TR0 IE1 IT1 IE0 IT */
93 1 }
94
95 void InterruptInit()
96 {
97 1 TMOD |= 0x01;
98 1 TH0 = 0x3C; /*TIMER_24M_25MS_H;*/
99 1 TL0 = 0xAA; /*TIMER_24M_25MS_L;*/
100 1 TR0 = 1;
101 1
102 1 /* open interrupt for rtl and timer */
103 1 EA = 1;
104 1 /* EX0 = 1; */
105 1 ET0 = 1;
106 1 }
107 main()
108 {
109 1 struct SMemHead DT_XDATA *MemHead;
110 1 struct SEtherDevice DT_XDATA DevRTL;
111 1 BYTE DT_XDATA EtherAddr[ETHER_ADDR_LEN] = {0x52,0x54,0x4c,0x30,0x2e,0x2f};
112 1 IP_ADDR IPAddr = 0xc0a8020d; /* 192.168.2.13 *//* ca71e590:202.113.229.144 *//* ca711075:202.113.16.117
-*/
113 1 IP_ADDR NetMask = 0xffffff00; /* 255.255.255.0 */
114 1 IP_ADDR GateWay = 0xc0a80201; /* 192.138.2.1 */
115 1
C51 COMPILER V6.12 MAIN 05/19/2009 14:55:41 PAGE 3
116 1 /*
117 1 * init
118 1 */
119 1 /* init. the order is not important */
120 1 NetIfInit();
121 1 ARPInit();
122 1 TCPInit();
123 1 MemInit();
124 1 RTLInit(EtherAddr);
125 1
126 1 /* init Devcie struct and init this device */
127 1 EtherDevInit(&DevRTL,EtherAddr,RTLSendPacket,RTLReceivePacket);
128 1
129 1 /* add this device to NetIf */
130 1 NetIfAdd(IPAddr,NetMask,GateWay,EtherInput,EtherOutput,&DevRTL);
131 1
132 1 /*
133 1 * start use socket
134 1 */
135 1 SerialInit();
136 1 InterruptInit();
137 1 TRACE("start");
138 1
139 1 /* Illustrate how to listen as a server */
140 1 ExListen = TCPSocket(IPAddr);
141 1 ExAccept = NULL;
142 1 TCPListen(ExListen,TCP_DEFAULT_PORT,OnAccept);
143 1
144 1 /* Illustrate how to connect to a server */
145 1 ExConn = TCPSocket(IPAddr);
146 1 if(TCPConnect(ExConn,0xc0a8020e,1001,OnReceive,OnClose) == TRUE)
147 1 {
148 2 /* Illustrate how to Use TCPSend() */
149 2 TCPSend(ExConn,str,6);
150 2
151 2 /* Illustrate how to Use TCPSendEx() */
152 2 while(1)
153 2 {
154 3 if((MemHead = TCPAllocate(DATA_SIZE)) == NULL)
155 3 break;
156 3 MemCopy(MemHead->pStart,DataBlock,DATA_SIZE);
157 3 if(TCPSendEx(ExConn,MemHead) == FALSE)
158 3 break;
159 3 }
160 2 }
161 1
162 1 TCPAbort(ExConn);
163 1
164 1 while(1);
165 1 }
166
167
168
169
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -