⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.c

📁 58enc28j06protuesuip09.rar
💻 C
字号:
/******************************************************************************
**CPU:STC89C58RD+
**RAM:HY62256       32k	   0x0000H-0x7FFFH
**EEPROM:STC EEPROM 16K	   0x8000H-0xF3FFH
**FLASH:STC 32K
**OSC:22.1184M
**NetChip:ENC28J60
**Version:1.0
**Data:2008-12-28
**Author:jerkoh
**E-mail:jerkoh@163.com
**QQ Group:28221007   (ETTG)
******************************************************************************/ 
/******************************************************************************
**Record
**08/12/28  创建工程文件gIP
**09/01/02  完成单片机初始化
**09/01/04  加入串口调试,STC EEPROM读写
**09/01/05	分配收发缓冲区实体XRAM,测试串口在9600bps下接收回显1000,000 byte OK!
**09/01/06  移植ENC28J60初始化驱动程序及模拟SPI读写
**09/01/09  修改网络变压器连接,MAC层LINKED
**09/01/10  移植IP,ARP,ICMP 
**09/01/20  uip0.9移植
**09/03/09  查询MAC_LINK LINK ON 状态时STOP赋值enc28j60Write(MICMD,0x00)
**09/03/10  16进制转字符串 ping 串口显示,查询当前网线连接状态
**09/03/11  串口将TCP包发送计算一个登记延时 否侧数据包过大导致登记溢出发送
******************************************************************************/
/******************************************************************************
** SIMspi -ENC28J60
** P1.0 - /CS
** P1.1 - SCK
** P1.2 - SI
** P1.3 - SO
** P3.2 - /INT
** P1.4 - /WOL  
** P1.5 - RST
** P3.4 - RED	LED 
** p3.5 - GREEN LED 
******************************************************************************/
#include "reg52.h"
#include "uip.h" 
#include "uip_arp.h"
#include "httpd.h"
#include "uart.h"
#include "enc28j60.h"
#include "tcp_server.h"
#include "myopt.h"
#include "time.h"
#include <intrins.h>
#include <stdio.h>
#include <stdlib.h>



#define BUF ((struct uip_eth_hdr *)&uip_buf[0])



u8_t xdata mydata[MYLEN];	
u8_t xdata ComTxdBuf[COM_TXD_BUFF_SIZE];      				
u8_t xdata ComRxdBuf[COM_RXD_BUFF_SIZE];



void main(void)
{
	idata u8_t i,arptimer;
	idata u16_t j,kk,ser_ct;
	
	AUXR=0x02;	                       /*stc xram 关闭*/
	TIME0_Init();
	UART_Init();
	if(DEBUG) Printf_String("\r\n[MSG:] Copyright(c) 2008-2009 jerkoh");
	if(DEBUG) Printf_String("\r\n[MSG:] All rights reserved");
	if(DEBUG) Printf_String("\r\n[MSG:] uip0.9 running on 8051&enc28j60");			   
	if(DEBUG) Printf_String("\r\n[MSG:] Baudrate 9600 8/n/1  ");
	if(DEBUG) Printf_String("\r\n[MSG:] Now linking please wait......");
	
	dev_init();	                       /*初始化以太网芯片enc28j60*/
	
   
	while(1)
     {
	  if(enc28j60_mac_is_linked())	   /*查询连接状态*/
	  {
	    if(DEBUG) Printf_String("\r\n[MSG:] Link is successed!");
	    break;
	  }
	 }
   
	uip_arp_init();					   
	/* Initialize the uIP TCP/IP stack. */
	httpd_init();
	uip_init();
	tcp_server_init();
	uip_listen(HTONS(4001));
	uip_listen(HTONS(4002));
	uip_listen(HTONS(4003));	
	arptimer = 0;
	

 while(1) 
  {

/*@*task0*@*/ 

	 if(enc28j60_mac_is_linked()==0)
	  {
	    if(DEBUG) Printf_String("\r\n[MSG:] Link is removed!");
		for(kk=0;kk<5000;kk++);
		for(kk=0;kk<1000;kk++);			  /*检测网线断开*/
		break; 
	  }




 /*@*task1*@*/ 
	 ser_ct=Copy_Send_Data();			  /*串口回显测试*/
	 if(ser_ct>0)
	 {
	  for(kk=0;kk<ser_ct;kk++)
	     {
		   Printf_Char(mydata[kk]);
		 }
	 }

	 

 /*@*task2*@*/ 


    /* Let the tapdev network device driver read an entire IP packet
       into the uip_buf. If it must wait for more than 0.5 seconds, it
       will return with the return value 0. If so, we know that it is
       time to call upon the uip_periodic(). Otherwise, the tapdev has
       received an IP packet that is to be processed by uIP. */
    uip_len = dev_poll();
	for(j=0;j<500;j++);

    if(uip_len == 0) 
	{
        for(i = 0; i < UIP_CONNS; i++) 
		  {
	       uip_periodic(i);
	       /* If the above function invocation resulted in data that
	          should be sent out on the network, the global variable
	          uip_len is set to a value > 0. */
	       if(uip_len > 0) 
		     {
	          uip_arp_out();
	          dev_send();
	         }
          }

#if UIP_UDP
        for(i = 0; i < UIP_UDP_CONNS; i++) 
		 {
	       uip_udp_periodic(i);
	       /* If the above function invocation resulted in data that
	          should be sent out on the network, the global variable
	          uip_len is set to a value > 0. */
	       if(uip_len > 0) 
		     {
	          uip_arp_out();
	          dev_send();
	         }
         }
#endif /* UIP_UDP */
      
      /* Call the ARP timer function every 10 seconds. */
         if(++arptimer == 20) 
		  {	
	       uip_arp_timer();
	       arptimer = 0;
          }
      
     } 
	 
	else 
	 
	 {
        if(BUF->type == htons(UIP_ETHTYPE_IP)) 
		{
	      uip_arp_ipin();
	      uip_input();
	      /* If the above function invocation resulted in data that
	         should be sent out on the network, the global variable
	         uip_len is set to a value > 0. */
	     if(uip_len > 0) 
		  {
	        uip_arp_out();
	        dev_send();
	      }
        } 
		else if(BUF->type == htons(UIP_ETHTYPE_ARP)) 
		{
     	  uip_arp_arpin();
	     /* If the above function invocation resulted in data that
	        should be sent out on the network, the global variable
	        uip_len is set to a value > 0. */	
	      if(uip_len > 0) 
		  {	
	       dev_send();
	      }
        }
    }
    
  }

}

⌨️ 快捷键说明

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