(论文)01130090204- 基于ENC28J60的网络模块设计 - 图文 联系客服

发布时间 : 星期五 文章(论文)01130090204- 基于ENC28J60的网络模块设计 - 图文更新完毕开始阅读a0c99b2727d3240c8447effa

天津职业技术师范大学2013届本科生毕业设计

// check if a packet has been received and buffered

if( !(encRead(EIR) & EIR_PKTIF) )

return 0;

// Make absolutely certain that any previous packet was discarded// MACDiscardRx();

encWrite(ERDPTL, (NextPacketPtr)); encWrite(ERDPTH, (NextPacketPtr)>>8); // read the next packet pointer

NextPacketPtr = encReadOp(ENC28J60_READ_BUF_MEM, 0); NextPacketPtr |= encReadOp(ENC28J60_READ_BUF_MEM, 0)<<8; // read the packet length

len = encReadOp(ENC28J60_READ_BUF_MEM, 0); len |= encReadOp(ENC28J60_READ_BUF_MEM, 0)<<8; // read the receive status

rxstat = encReadOp(ENC28J60_READ_BUF_MEM, 0); rxstat |= encReadOp(ENC28J60_READ_BUF_MEM, 0)<<8;

// (we reduce the MAC-reported length by 4 to remove the CRC) if(len > 336)

len = 336;

/if( WasDiscarded == FALSE)

// Set the read pointer to the start of the received packet

// limit retrieve length

// copy the packet from the receive buffer encReadBuffer(len, rxdnet->bytedata.bytebuf+4);

// Move the RX read pointer to the start of the next received packet // This frees the memory we just read out

}

36

encWrite(ERXRDPTL, (NextPacketPtr)); encWrite(ERXRDPTH, (NextPacketPtr)>>8);

encWriteOp(ENC28J60_BIT_FIELD_SET, ECON2, ECON2_PKTDEC);

// decrement the packet counter indicate we are done with this packet return len;

天津职业技术师范大学2013届本科生毕业设计

附录2:主程序

#include \#include \#include \#include \

extern union NetNode myNode; extern union netcard rxdnetbuf; extern union netcard txdnetbuf; int main(void) {

unsigned int num_bytes; OSCCAL = 0x9A;

myNode.node.mask = IP4_ADDR(0,255,255,255); myNode.node.gate = IP4_ADDR(1,1,168,192); myNode.node.mac[0] = 0x00; myNode.node.mac[1] = 0x60; myNode.node.mac[2] = 0x97; myNode.node.mac[3] = 0x48; myNode.node.mac[4] = 0xF4;

myNode.node.mac[5] = 0xAB; /*ENC Initialisieren*/

encInit(); //Mac Adresse setzen(stack.h, dort wird auch die Ip nicSetMacAddress(); /* Leds konfigurieren

LEDA : Link status

LEDB : Receive & Send activity

Led Settings : enc28j60 datasheet, page 11*/

myNode.node.ip = IP4_ADDR(218,1,168,192);

festgelegt)

encPhyWrite(0x14,0b0000010001110000); arptab_init();

{ // Unload packet from the receive buffer and store in

37

while(1)

天津职业技术师范大学2013届本科生毕业设计

num_bytes = encPacketReceive(&rxdnetbuf);

if(num_bytes > 0) {

if(rxdnetbuf.etherframe.protocal==ARP_PACKET) { }

// 收到一个IP包

{ }

else if(rxdnetbuf.arpframe.operation==0x0200) { }

arp_process(); //ARP answer

arp_answer(); //ARP request,处理arp数据包

//表示收到一个arp请求包

if(rxdnetbuf.arpframe.operation==0x0100)

else if((rxdnetbuf.etherframe.protocal == IP_PACKET)

&& ((rxdnetbuf.ipframe.verandihl&0xf0) == 0x40) // IP V4 && (rxdnetbuf.ipframe.destip[0] == myNode.nodebytes.ipbytes[0]) && (rxdnetbuf.ipframe.destip[1] == myNode.nodebytes.ipbytes[1]) && (rxdnetbuf.ipframe.destip[2] == myNode.nodebytes.ipbytes[2]) && (rxdnetbuf.ipframe.destip[3] == myNode.nodebytes.ipbytes[3])) // my IP

{

arp_ip_mac();

if(rxdnetbuf.ipframe.protocal == 1) { }

else if(rxdnetbuf.ipframe.protocal == 17) // udp {

38

// ICMP // echo

if(rxdnetbuf.icmpframe.type == 8) { }

ping_answer();

天津职业技术师范大学2013届本科生毕业设计

} else {

{ }

// tcp_rcve(&rxdnetbuf); // net_udp_rcv();}

// tcp

else if(rxdnetbuf.ipframe.protocal == 6)

//Lib_Uart_SendString(\

}

//updatearptab();

// IEEE 802 pkt rejected

} } }

39

天津职业技术师范大学2013届本科生毕业设计

致 谢

对于XX老师和XX老师给予我的关怀和指导,我不甚感激。从最初的定题,到资料收集,到写作、修改,再到论文定稿,XX老师给了我耐心的指导和无私的帮助。两位老师在学术等方面的造诣令我敬佩不已,在XX老师和XX老师那里学到的知识让我终生受益。同时,感谢任课老师和同学们在这期间给予我的指导和帮助,是他们教会了我专业知识,教会了我如何学习。正是由于他们,我才能在各方面取得显著的进步,在此向他们表示我由衷的谢意。

感谢天津职业技术师范大学,感谢自动化与电气工程学院,给我提供了一个学习知识的平台和一个向前进步的机会。我将铭记我是一名天职师大人,在今后的学习和工作中谨记“动手动脑,全面发展”的校训,并以此鞭策自己,努力把优良传统发扬光大。

最后,衷心感谢为评阅本论文付出辛勤劳动的专家和教授们。

40