BBKEthernet.ino

Arduino网卡代码,支持SPI连接的网络接入设备……

BBKEthernet.ino

//=====================================================
#include <SPI.h>
#include <Ethernet.h>
#include <EthernetUdp.h>
#include <Dns.h>
//=====================================================
//byte mac[] = {0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02 };
byte mac[] = { 0x00, 0x00, 0xAA, 0xBB, 0xCC, 0xDD };
unsigned int localPort = 80; // local port to listen for UDP packets
//-----------------------------------------------------
DNSClient   Dns;
EthernetUDP Udp;
//=====================================================
void Ethernet_Setup()
{
  Serial.print("Ethernet_Setup......");
  //-------------------------------------------------------------
  if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");
    Serial.println("Ethernet_Setup() Stop!!!");
    for(;;)
      ;
  }
  //-------------------------------------------------------------
  Udp.begin(localPort);
  Dns.begin(Ethernet.dnsServerIP());
  //-------------------------------------------------------------
  Serial.print(Ethernet.localIP());
  Serial.println(" OK!");  
  //-------------------------------------------------------------
}
void Ethernet_IPShow() {
  //------------------------------------------
  //Serial.print("My IP address: ");
  Serial.print(Ethernet.localIP());
  //------------------------------------------
  //  for (byte thisByte = 0; thisByte < 4; thisByte++) {
  //    Serial.print(Ethernet.localIP()[thisByte], DEC);
  //    if(thisByte<3)Serial.print("."); 
  //  }
  //  Serial.println();
  //------------------------------------------
}
更新日期: 2014-11-05 10:53:16
文章标签:
文章链接: BBKEthernet.ino
站方声明: 除特别标注, 本站所有文章均为原创, 互联分享, 尊重版权, 转载请注明.