|
|
本帖最后由 dkm382638608 于 2015-4-11 23:51 编辑
按照,大神翻译帖子:http://www.geek-workshop.com/thread-2257-1-1.html
arduino mega 2号数字线接LED灯
然后无法响应网页按钮(灯不亮),enc28J60串口也没任何信息
后来经过布列松的指点找到是MAC地址有问题,同时更加感谢弘毅大大一语道破问题所在!也感谢zoologist的热心回答。
把 MAC 地址修改为:0x74,0x69,0x69,0x2D,0x30,0xE8 即可
如图:
arduino:
网页:
enc28J60接线如下:
SO --- 50
SI --- 51
SCK-- 52
CS --- 53
GND--GND
VCC--3.3V
RST--RST
Arduino 代码:
- #include <EtherCard.h>
- static byte mymac[] = {0xDD,0xDD,0xDD,0x00,0x00,0x01}; //这里是问题所在
- static byte myip[] = {192,168,2,1};
- byte Ethernet::buffer[700];
- const int ledPin = 2;
- boolean ledStatus;
- char* on = "ON";
- char* off = "OFF";
- char* statusLabel;
- char* buttonLabel;
- void setup () {
-
- Serial.begin(57600);
- Serial.println("WebLed Demo");
-
- if (!ether.begin(sizeof Ethernet::buffer, mymac, 53))
- Serial.println( "Failed to access Ethernet controller");
- else
- Serial.println("Ethernet controller initialized");
-
- if (!ether.staticSetup(myip))
- Serial.println("Failed to set IP address");
- Serial.println();
-
- pinMode(ledPin, OUTPUT);
- digitalWrite(ledPin, LOW);
- ledStatus = false;
- }
-
- void loop() {
-
- word len = ether.packetReceive();
- word pos = ether.packetLoop(len);
-
- if(pos) {
-
- if(strstr((char *)Ethernet::buffer + pos, "GET /?status=ON") != 0) {
- Serial.println("Received ON command");
- ledStatus = true;
- }
- if(strstr((char *)Ethernet::buffer + pos, "GET /?status=OFF") != 0) {
- Serial.println("Received OFF command");
- ledStatus = false;
- }
-
- if(ledStatus) {
- digitalWrite(ledPin, HIGH);
- statusLabel = on;
- buttonLabel = off;
- } else {
- digitalWrite(ledPin, LOW);
- statusLabel = off;
- buttonLabel = on;
- }
-
- BufferFiller bfill = ether.tcpOffset();
- bfill.emit_p(PSTR("HTTP/1.0 200 OK\r\n"
- "Content-Type: text/html\r\nPragma: no-cache\r\n\r\n"
- "<html><head><title>WebLed</title></head>"
- "<body>LED Status: $S "
- "<a><input type="button" value="$S" onClick="location.href='/?status=$S';"></a>"
- "</body></html>"
- ), statusLabel, buttonLabel, buttonLabel);
- ether.httpServerReply(bfill.position());
- }
- }
复制代码
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?注册
x
|