本代码为10Mbit RTL8019网卡C文件完整代码,配置方式为跳线方式,适合51系列单片机,经多次使用,性能稳定,学习51单片机上网的网友可直接下载使用, #include \
#define TIME0_TH0 0xce #define TIME0_TL0 0x41
// Packet transmit & receive buffer configuration
#define ETH_TX_PAGE_START 0x40 // 0x4000 Tx buffer is 6 * 256 = 1536 bytes #define ETH_RX_PAGE_START 0x4c // 0x4600 Rx buffer is 26 * 256 = 6656 bytes #define ETH_RX_PAGE_STOP 0x60 // 0x6000
#define ETH_MIN_PACKET_LEN 0x3C
static void etherdev_reg_write(unsigned char reg, unsigned char wr_data); static unsigned char etherdev_reg_read(unsigned char reg); static void etherdev_delay_ms(unsigned int count); static unsigned int etherdev_poll(void); void Delay1(uchar x);
//static void etherdev_timer0_isr(void) interrupt 1 using 1;
// Manipulate PS1 & PS0 in CR to select RTL8019AS register page. void page(uchar pagenumber) { uchar data temp; temp=CR; //读入命令寄存器的值。 temp=temp&0x3B; //将高2位,即PS1,PS0清0 pagenumber=pagenumber<<6; //将低2位移至高端 CR=temp|pagenumber; //设置第几页 }
static unsigned char tick_count = 0;
void Send(uchar a) {
SBUF=a;
}
/*static void etherdev_reg_write(unsigned char reg, unsigned char wr_data) {
// Select register address.
ETH_ADDR_PORT &= ~ETH_ADDR_PORT_MASK; ETH_ADDR_PORT |= reg;
// Output register data to port. ETH_DATA_PORT = wr_data;
// Clock register data into RTL8019AS. // IOR & IOW are both active low. IOW = 0; IOW = 1;
// Set register data port as input again.
ETH_DATA_PORT = ETH_DATA_PORT_MASK;
return; } */
/*static unsigned char etherdev_reg_read(unsigned char reg) {
unsigned char rd_data;
// Select register address.
ETH_ADDR_PORT &= ~ETH_ADDR_PORT_MASK; ETH_ADDR_PORT |= reg;
// Enable register data output from RTL8019AS. IOR = 0;
// Read register data from port. rd_data = ETH_DATA_PORT;
// Disable register data output from RTL8019AS. IOR = 1;
return rd_data; } */
static void etherdev_timer0_isr(void) interrupt 1 using 1 {
// Reload timer/ counter 0 for 24Hz periodic interrupt. TH0 = TIME0_TH0; TL0 = TIME0_TL0;
// Increment 24ths of a second counter. tick_count++;
return; }
bit etherdev_init(void) {
//RESET=0;
// Configure RTL8019AS ethernet controller.
uchar a; RESET=0; Delay1(0xff);
/*page(0); a=PG0_ISR;
// Check if RTL8019AS fully reset. if(!(a & 0x80)) {
return 0; } */
// Select RTL8019AS register page 0. //page(0);
// Stop RTL8019AS, select page 0 and abort DMA operation. CR=0x21;
page(3); PG3_9346CR=0xc0; PG3_CONFIG2=0x20; PG3_9346CR=0x00;
// Initialise data configuration register.
// FIFO threshold 8 bytes, no loopback, don't use auto send packet. page(0); PG0_DCR=0xc8;
// Reset remote byte count registers. PG0_RBCR0=0x00; PG0_RBCR1=0x00;
// Receive configuration register to monitor mode. PG0_RCR=0xcc;
// Initialise transmit configuration register to loopback internally. PG0_TCR=0xe0;
// Clear interrupt status register bits by writing 1 to each. PG0_ISR=0xFF;
// Mask all interrupts in mask register. PG0_IMR=0x00;
// Set transmit page start. PG0_TPSR=0x40;
// Set receive buffer page start. PG0_PSTART=0x4c;
// Initialise last receive buffer read pointer. PG0_BNRY=0x4c;
// Set receive buffer page stop. PG0_PSTOP=0x80; //PG0_RCR=0xcc; //RCR 接收配置寄存器 // PG0_TCR=0xe0; //TCR 发送配置寄存器 //PG0_DCR=0xc8; //DCR 数据配置寄存器 8位数据dma // Select RTL8019AS register page 1. page(1);
// Initialise current packet receive buffer page pointer
PG1_CURR=0x4d;
// Set physical address
PG1_PAR0=UIP_ETHADDR0; PG1_PAR1=UIP_ETHADDR1; PG1_PAR2=UIP_ETHADDR2; PG1_PAR3=UIP_ETHADDR3; PG1_PAR4=UIP_ETHADDR4; PG1_PAR5=UIP_ETHADDR5; PG1_MAR0=0xff; //reg08- reg0f 是 MAR0-MAR7 功能为设置多点播送的参数, PG1_MAR1=0xff; //我们用到的播放方式为广播和组播方式, PG1_MAR2=0xff; //所以我们把MAR0-MAR7全部设为0xFF PG1_MAR3=0xff; PG1_MAR4=0xff; PG1_MAR5=0xff; PG1_MAR6=0xff; PG1_MAR7=0xff;
CR=0x22; /*a=PG0_BNRY; Send(a); Delay1(0xff); page(1); a=PG1_CURR; Send(a); Delay1(0xff); Send(CR); Delay1(0xff); */ // Restart RTL8019AS.
/* page(0);
PG0_TCR=0xe0;
PG0_RCR=0xcc; PG0_DCR=0xc8; */ //CR=0x22; //PG0_ISR=0xFF;
// Initialize Timer 0 to generate a periodic 24Hz interrupt.
百度搜索“77cn”或“免费范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,免费范文网,提供经典小说教育文库51单片机上网RLT8019 AS C文件源代码在线全文阅读。
相关推荐: