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();
//------------------------------------------
}