main.c

来自「网络单片机 让嵌入式系统上网,基于keil C. 文件名:microweb-ke」· C语言 代码 · 共 106 行

C
106
字号
// ***************************************************************************// An 8051 Based Web Server// main.c: main source code file// By Mason Kidd 3/7/02// ***************************************************************************#include <reg515.h>#include <string.h>#include "csio.h"#include "packets.h"#include "lcd_disp.h"#include "keypad.h"#include "arp.h"#include "ip.h"#include "icmp.h"#include "udp.h"#include "tcp.h"#define ICMP_ECHO_LEN 32unsigned char myMAC[6] = {0x00,0x08,0x07,0x06,0x05,0x04};unsigned char myIP[4] = {192,168,1,1};unsigned char targetIP[4] = {192,168,1,2};unsigned char targetMAC[6] = {0x00,0xa0,0x24,0x66,0xda,0x3f};unsigned char srcMAC[6] = {0,0,0,0,0,0};unsigned char srcIP[4] = {0,0,0,0};unsigned char tmp_mac[6];unsigned char tmp_ip[4];unsigned char myBCAST[4] = {255,255,255,255};unsigned char rx_ip_type;unsigned char rx_buf[BUF_LEN];unsigned int rx_buf_len;unsigned int rx_packet_type;void main(void){		unsigned char cTest;	unsigned char cKey;	struct eth_hdr *rx_eth_hdr = (struct eth_hdr *)rx_buf;	bit bEvent = 0;	unsigned char i = 0;	unsigned char szSendData[ICMP_ECHO_LEN];		lcdinit();	kbdinit();	tcp_init();	cTest = cs_test();	cs_init(&myMAC);	for (i = 0; i < (ICMP_ECHO_LEN / 4);)	{		szSendData[i++] = 0xDE;		szSendData[i++] = 0xAD;		szSendData[i++] = 0xBE;		szSendData[i++] = 0xEF;	}       	while (1)	{		cKey = keypress; 		switch (cKey)  		{   			case ('1'):   	 			tx_icmp_packet(ICMP_ECHO, szSendData, ICMP_ECHO_LEN);   	   			keypress = 0;   	    		     cKey = 0;   	   			break;			default:  				cKey = 0;   	 			break;   	    		   		}		bEvent = rx_event_poll(); 		if (bEvent == 1)  		{			rx_buf_len = rx_packet(&rx_buf);			if (rx_buf_len != 0)			{				rx_packet_type = rx_eth_hdr->type;				switch (rx_packet_type)				{					case ETHER_IP:						rx_ip_type = rx_ip_packet(&rx_buf);						switch (rx_ip_type)						{							case IP_ICMP:								rx_icmp_packet(&rx_buf);								break;							case IP_UDP:								rx_udp_packet(&rx_buf);								break;							case IP_TCP:								rx_tcp_packet(&rx_buf);								break;						}   	 					break;					case ETHER_ARP:						rx_arp_packet();						break;				}			}		}	}}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?