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

📄 main.c

📁 单片机控制RTL8019AS的程序,C语言编写,仿真通过.
💻 C
字号:
//---------------------------------------------------------------------------
// Net MAIN.C
//
// 8051 Web Server project
// See Makefile for build notes 
// Written for Keil C51 V5.1 compiler, notes:
//   It uses big endian order, which is the same as the
//   network byte order, unlike x86 systems.
//   Use OPTIMIZE(2)or higher so that automatic variables get shared
//   between functions, to stay within the 256 bytes idata space
//---------------------------------------------------------------------------

#include <string.h>
#include <stdlib.h>
#include <general.h>


// Global variables
UINT volatile event_word;
char xdata text[20];  
UCHAR idata rcve_buf_allocated;


// This sets my hardware address
UCHAR code my_hwaddr[6] = {0x00,0x11,0xD8,0xD7,0x99,0xF9}; 

// Hardware addr to send a broadcast
UCHAR code broadcast_hwaddr[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};

// This sets my IP address to 202.114.57.107
ULONG code  my_ipaddr = 0xCA72396BL;

// This sets my subnet mask to 255.255.255.0
ULONG code my_subnet = 0xFFFFFF00L;

// This sets gateway ip address to 202.114.57.1
ULONG code gateway_ipaddr = 0xCA723901L;

//--------------------------------------------------------------------------
// Initialize the memory management routines
// Initialize variables declared in main
//--------------------------------------------------------------------------

unsigned int Count1msInc;
unsigned char Count1ms,Count10ms,Count1s;
unsigned char TimeSecond,TimeMinute;
sbit P10=P1^0;
sbit ET2   = IE^5;
void init_main(void)
{
	// Start the memory pool for incoming and outgoing Ethernet
	// frames at 1000, with length = 1500 bytes. Memory below 500
	// is used for program variables
	init_mempool((void xdata *)1000, 1500);
	memset(text, 0, sizeof(text));
	event_word = 0;
	rcve_buf_allocated = FALSE;
}



void Timer0_Init (void)
{
   	TMOD|=0x1;    	//16Bit
	Count10ms=10;
	Count1s=0;
   	TR0 = 0;                         	// STOP Timer0
   	TH0 =0xF5;	// set Timer0 to overflow in 1ms
   	TL0 =0x96;
   	TR0 = 1;   	// START Timer0
   	IE|= 0x2; 
}

void Timer0_ISR (void) interrupt 1  //1ms
{
	TH0 = 0xF5;
   	TL0 =0x96;
	if (Count1ms) Count1ms--;
	Count1msInc++;
	if (Count10ms) Count10ms--;
	else
	{
		Count10ms=10;    			//10ms
		if (Count1s) Count1s--;
		else
		{
			Count1s=100;			//1s
			TimeSecond++;
			if (TimeSecond>=60)
			{
				TimeSecond=0;		//1min
				TimeMinute++;
				if	(TimeMinute==60)	TimeMinute=0;
			}
		}
	}
}


void Delay1ms(unsigned char T)
{
	Count1ms=T;
	while (Count1ms);
}



void LightONOFF(bit b)
{

	if (b)
	{
		P10=0;
	}
	else
	{
		P10=1;
	}
}


void main (void)
{
	UINT j, event_word_copy;
	UCHAR xdata * inbuf;
                    	
	Timer0_Init();

	init_main();
	init_tcp();
	init_http();

	EA=1;
	init_timer2();
	init_arp();
	init_8019();
   
	

	j = 0;
	ET2 = 1;		            // Enable timer 2 interrupt
	   	

	while (1)
   {
      query_8019();
      
      // Use a copy of event word to avoid interference
      // with interrupts
		EA = 0;
		event_word_copy = event_word;
		EA = 1;
      
      // See if an Ethernet frame has arrived      
      if (event_word_copy & EVENT_ETH_ARRIVED)
      {
         EA = 0;
         event_word &= (~EVENT_ETH_ARRIVED);
         EA = 1;
         
         // Allocate a buffer and read frame from CS8900A
         inbuf = rcve_frame();
         if (inbuf != NULL)
         {
            // Process the received Ethernet frame 
            eth_rcve(inbuf); 
         
            // If the memory allocated for the rcve message has
            // not already been freed then free it now
            if (rcve_buf_allocated)
            {
               free(inbuf);
               rcve_buf_allocated = FALSE;
            }
         }
      }
      
      // See if TCP retransmit timer has expired            	       
      else if (event_word_copy & EVENT_TCP_RETRANSMIT)
      {
         EA = 0;
         event_word &= (~EVENT_TCP_RETRANSMIT);
         EA = 1;
         tcp_retransmit();
 		}

      // See if TCP inactivity timer has expired
      else if (event_word_copy & EVENT_TCP_INACTIVITY)
      {
         EA = 0;
         event_word &= (~EVENT_TCP_INACTIVITY);
         EA = 1;
         tcp_inactivity();
 		}

      // See if ARP retransmit timer has expired
 		else if (event_word_copy & EVENT_ARP_RETRANSMIT)
      {
         EA = 0;
         event_word &= (~EVENT_ARP_RETRANSMIT);
         EA = 1;
         arp_retransmit();
		}

      // See if it is time to age the ARP cache
      else if (event_word_copy & EVENT_AGE_ARP_CACHE)
      {
         EA = 0;
         event_word &= (~EVENT_AGE_ARP_CACHE);
			EA = 1;
         age_arp_cache();
		}
   }
}

⌨️ 快捷键说明

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