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

📄 main.c

📁 51单片机加rt8019硬件平台,上web方案及详细代码
💻 C
字号:
//----------------------------main.c------------------
#define DEBUG          1 

#include "includes.h"
uchar volatile cmd;

//-----------------------------------
void init()
{
   	LED=0;	//指示灯亮				
	init_t0();
	Timer_Init();	
	init_uart(B115200);//B19200);//
	init_arp();
	init_tcp();	
	init_8019();
	clean_buf(inbuf,MAXBUF);
   	LED=1;	//指示灯灭				
	EA=1;
}

void OnEthernet(void)
{
	uint data len;

	len=frame_receive(inbuf);
	KillTimer(QUERY_8019);
//	TRACE("inbuf=",inbuf,20,0);
	eth_process(inbuf);
	clean_buf(inbuf,MAXBUF);
	SetTimer(QUERY_8019,5);
}


void OnTimer(uchar  id)
{
	switch (id)
	{
	 case ARP_RESEND:
		arp_resend();
      				
		break;

	 case QUERY_8019:	 	  
		if(query_8019())
      {
         
			OnEthernet();
       }							
		break;

	 case ARP_AGE:	 
		age_arp_cache();				
		break;

	 case TCP_RESEND:
		tcp_resend();		
		break;

	case TCP_ABORT:
		tcp_inactivity();				
		break; 
   case LED_RAY:
		LED=~LED;				
		break;  		

	}
}

void main()
{	
	uchar data i;
		  
	init();	
	SetTimer(QUERY_8019,5);
	SetTimer(ARP_AGE,60000);
	SetTimer(TCP_RESEND,500);
	SetTimer(LED_RAY,1000);	
 #ifdef OSCAR_DEBUG
	TRACE("TCP/IP VER1.0",NULL,0,0);
	TRACE("MYIP = ",CP &myipaddr,4,0);
#endif

 	while(1)
 	{
		
		for(i=0; i<MAX_TIMER; i++)
		{
			if (Timer_GetEvent(i) & EVF_TIMERMATCH)
				OnTimer(i);
		}		
		switch (cmd)
		{
			case 0x55 : 
//				udp_send(outbuf,test,0xc0a801a7, 0x21ee, 1050);
				cmd=0;
				break;
			case 0x56 :
				TRACE("ARP_Cache = ",(uchar *)arp_cache,sizeof(arp_cache),0);
				cmd=0; 
				break;			
			default:
				break;
		}
	}
}

⌨️ 快捷键说明

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