【鬼哥】网络开关-ENC28J60

第一次发帖请多多指教。
硬件: arduino pro mini ATMEGA328P 5V/16M
Microduino-ENC28J60
继电器 DC5V
------------------------华丽丽的分割线----------------------------------------
呃,然后不知道干嘛了?
我要干嘛呢, 忘记了。
那就去睡一觉吧!
嗯,想法不错。
坛友们怎么说……
呃,%%%%@#¥%%……%¥#@¥%¥#@¥%
------------------------纯属扯谈,不要介意~----------------------------------
接下来,呃……% 是啥?
那就先上图看下,具体是啥硬件吧!
估计又是扯淡………………%¥¥……&&…………
高清无码%……%(不知道算不算高清:lol)




我靠感觉图片好大 不知道有没有事!~~~~我什么都不知道,没看见没看见没看见没看见没看见没看见
-------------------------------------------没看见没看见---------------------------------------

好吧老实交待了,那个是某宝的图片,:lol,只因我图片太丑了。
那就上一下我自己的图片。
吓坏大家 不要骂我哈!~~~~~

好了就是这么一坨,不要骂我~:lol

-------------------------------------狗屎分割线-------------------------------------

#include <EtherCard.h>

#define LED1PIN  2
#define LED2PIN  3
#define LED3PIN  4
/*
PROGMEM prog_char led_off]= {
   0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A, 0x00, 0x00, 0x00, 0x0D, 0x49, 0x48, 0x44, 0x52, 0x00, 0x00, 0x00, 0x0E,
   0x00, 0x00, 0x00, 0x0E, 0x08, 0x04, 0x00, 0x00, 0x00, 0xB5, 0x41, 0xE5, 0x5A, 0x00, 0x00, 0x00, 0x01, 0x73, 0x52, 0x47,
   0x42, 0x00, 0xAE, 0xCE, 0x1C, 0xE9, 0x00, 0x00, 0x00, 0x02, 0x62, 0x4B, 0x47, 0x44, 0x00, 0xFF, 0x87, 0x8F, 0xCC, 0xBF,
   0x00, 0x00, 0x00, 0x09, 0x70, 0x48, 0x59, 0x73, 0x00, 0x00, 0x0B, 0x12, 0x00, 0x00, 0x0B, 0x12, 0x01, 0xD2, 0xDD, 0x7E,
   0xFC, 0x00, 0x00, 0x00, 0x07, 0x74, 0x49, 0x4D, 0x45, 0x07, 0x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F9, 0x60, 0x69, 0x7F, 0xE7, 0xE6, 0xB6,
   0x1C, 0x8B, 0xA2, 0x1F, 0xD1, 0xCE, 0xBB, 0x75, 0x53, 0x4D, 0x3A, 0x03, 0x30, 0x7F, 0x68, 0x9E, 0xBC, 0x29, 0xB4, 0x3E,
   0x3D, 0x5B, 0x37, 0xE6, 0xEC, 0x9D, 0x10, 0x82, 0xC5, 0x3F, 0xEF, 0x3B, 0x8C, 0x5F, 0xC2, 0x84, 0x6A, 0x7B, 0xFB, 0x42,
   0x44, 0xCC, 0x00, 0x00, 0x00, 0x00, 0x49, 0x45, 0x4E, 0x44, 0xAE, 0x42, 0x60, 0x82
   };
   
PROGMEM prog_char led_on]= {
   0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A, 0x00, 0x00, 0x00, 0x0D, 0x49, 0x48, 0x44, 0x52, 0x00, 0x00, 0x00, 0x0E,
   0x00, 0x00, 0x00, 0x0E, 0x04, 0x03, 0x00, 0x00, 0x00, 0xED, 0x66, 0x30, 0xE2, 0x00, 0x00, 0x00, 0x01, 0x73, 0x52, 0x47,
   0x42, 0x00, 0xAE, 0xCE, 0x1C, 0xE9, 0x00, 0x00, 0x00, 0x27, 0x50, 0x4C, 0x54, 0x45, 0x00, 0x00, 0x00, 0xFF, 0xCC, 0x00,
   0xCC, 0x66, 0x00, 0xFF, 0xFF, 0x33, 0xFF, 0x99, 0x00, 0xFF, 0xCC, 0x33, 0xCC, 0x99, 0x66, 0xFF, 0xFF, 0x99, 0xCC, 0x99,
   0x33, 0xCC, 0x99, 0x00, 0xFF, 0xCC, 0x66, 0x99, 0x66, 0x00, 0xFF, 0xCC, 0x99, 0x4A, 0x4E, 0xC9, 0x79, 0x00, 0x00, 0x00,
   0x01, 0x74, 0x52, 0x4E, 0x53, 0x00, 0x40, 0xE6, 0xD8, 0x66, 0x00, 0x00, 0x00, 0x01, 0x62, 0x4B, 0x47, 0x44, 0x00, 0x88,
   0x05, 0x1D, 0x48, 0x00, 0x00, 0x00, 0x09, 0x70, 0x48, 0x59, 0x73, 0x00, 0x00, 0x0B, 0x12, 0x00, 0x00, 0x0B, 0x12, 0x01,
   0xD2, 0xDD, 0x7E, 0xFC, 0x00, 0x00, 0x00, 0x07, 0x74, 0x49, 0x4D, 0x45, 0x07, 0xDC, 0x01, 0x1D, 0x14, 0x23, 0x1C, 0x87,
   0xBC, 0xF0, 0x84, 0x00, 0x00, 0x00, 0x48, 0x49, 0x44, 0x41, 0x54, 0x08, 0xD7, 0x63, 0x60, 0x80, 0x03, 0x26, 0x25, 0x05,
   0x30, 0x95, 0x55, 0x3E, 0x0D, 0xC4, 0xD0, 0x31, 0x16, 0x14, 0x6C, 0x02, 0xD2, 0xC9, 0x86, 0x82, 0x82, 0xD2, 0x40, 0xE1,
   0xC5, 0x40, 0x3A, 0x44, 0x81, 0x81, 0xA9, 0x18, 0x46, 0x0B, 0x0A, 0x8A, 0xBA, 0x00, 0xE9, 0x60, 0x08, 0xCD, 0x90, 0x0C,
   0xA4, 0x9D, 0x80, 0xEA, 0x35, 0x80, 0xD2, 0x20, 0x9A, 0xA9, 0x53, 0xD0, 0x49, 0x01, 0xC9, 0x5C, 0x08, 0x00, 0x00, 0x9A,
   0x56, 0x0B, 0x58, 0x9D, 0x6A, 0x76, 0x99, 0x00, 0x00, 0x00, 0x00, 0x49, 0x45, 0x4E, 0x44, 0xAE, 0x42, 0x60, 0x82
   };
*/
static byte mymac] = {0x74,0x69,0x69,0x2D,0x30,0x31};
static byte myip] = {10,0,0,2};

byte Ethernet::buffer[700];

boolean led1Status;
boolean led2Status;
boolean led3Status;

void setup () {
 
  Serial.begin(57600);
  Serial.println("WebLeds Demo");
 
  if (!ether.begin(sizeof Ethernet::buffer, mymac, 10))
   Serial.println( "Failed to access Ethernet controller");
 else
   Serial.println("Ethernet controller initialized");
 
  if (!ether.staticSetup(myip))
   Serial.println("Failed to set IP address");



  ether.printIp("IP Address:\t", ether.myip);
 // ether.printIp("Netmask:\t", ether.mymask);
  ether.printIp("Gateway:\t", ether.gwip);
  
  
  Serial.println();
  
  pinMode(LED1PIN, OUTPUT);
  pinMode(LED2PIN, OUTPUT);
  pinMode(LED3PIN, OUTPUT);
  
  digitalWrite(LED1PIN, HIGH);
  digitalWrite(LED2PIN, HIGH);
  digitalWrite(LED3PIN, HIGH);

}
  
void loop() {
 // ether.packetLoop(ether.packetReceive());
  word len = ether.packetReceive();
  word pos = ether.packetLoop(len);
  
  if(pos) {
   
/*    if(strstr((char *)Ethernet::buffer + pos, "GET /led_off.png") != 0) 
   send_png_image(led_off, sizeof(led_off));
   else if(strstr((char *)Ethernet::buffer + pos, "GET /led_on.png") != 0)
   send_png_image(led_on, sizeof(led_on));
 
   else {
   
*/      if(strstr((char *)Ethernet::buffer + pos, "GET /?password=这里写密码") != 0) {
   digitalWrite(LED1PIN, LOW); 
   delay(200);
   digitalWrite(LED1PIN, HIGH); 
   
   //Serial.println("Failed ");
   
   //  led1Status = !led1Status;
   //  digitalWrite(LED1PIN, led1Status);  
   }
   
   if(strstr((char *)Ethernet::buffer + pos, "GET /?password=这里写密码") != 0) {
   // Serial.println( (char *)Ethernet::buffer);
   digitalWrite(LED2PIN, LOW); 
   delay(200);
   digitalWrite(LED2PIN, HIGH);
   
   //  led2Status = !led2Status;
   //  digitalWrite(LED2PIN, led2Status);          
   }
   
   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>WebLeds</title></head><body>"
   ));
   bfill.emit_p(PSTR("<form>"));
   // if(led1Status) bfill.emit_p(PSTR("<a href=\"/?LED1\"><input type=\"button\" value=\"START\"></a>"));
   // else bfill.emit_p(PSTR("<a href=\"/?LED1\"><img src=\"led_on.png\"><input type=\"button\" value=\"START\"></a>"));
   bfill.emit_p(PSTR(" Hard disk :"));
   bfill.emit_p(PSTR("<a> <input type=\"text\" name=\"password\" value=\"password\"/></a>"));
   bfill.emit_p(PSTR("<a href=\"/?LED1\"><input type=\"submit\" value=\"START\"></a>"));
   bfill.emit_p(PSTR("</form>"));
   bfill.emit_p(PSTR("<form>"));
   bfill.emit_p(PSTR("<br> Server2012 :"));
   bfill.emit_p(PSTR("<a> <input type=\"text\" name=\"password\" value=\"password\"/></a>"));
   bfill.emit_p(PSTR("<a href=\"/?LED2\"><input type=\"submit\" value=\"START\"></a>"));


   bfill.emit_p(PSTR("</form></body></html>"));
   ether.httpServerReply(bfill.position());
  }
  }

/*
void send_png_image(PGM_P png_image, unsigned int image_size) {
  
  BufferFiller bfill = ether.tcpOffset();
  bfill.emit_p(PSTR("HTTP/1.0 200 OK\r\n"
   "Content-Type: image/png\r\n\r\n"));
  bfill.emit_raw_p(png_image, image_size);
  ether.httpServerReply(bfill.position());  
}*/

我靠我直接贴代码了,果断没煮熟(哦,注释:lol)为了互动,有问题就问吧!(反正我也不懂,是借鉴了一位老师的代码修改的!)
-----------------------不知道写什么了 ,来一个分割线吓唬一下大家:lol----------------

库地址: https://github.com/jcw/ethercard (那位老师的!高手也~)
这是老师写的接线方法:
顺便说下接线,特别是模块的,很多同学容易弄错,必要接的7根,Vcc接3.3V(电路接好通电后,一定要用万用表量一下,至少要3V以上);CS根据程序接;SI接D11;SO接D12;SCK接D13;RESET接RESET;GND接GND。
arduino 2560接线:Vcc接3.3V(电路接好通电后,一定要用万用表量一下,至少要3V以上);cs根据程序接;SI接D51;SO接D50;SCK接D52;RESET接RESET;GND接GND。有些2560可能3.3V电压不够,如果调试Vcc可接5V电压(建议不要长时间运行,芯片会比较热)。

---------------------------------然而我这是在干嘛,其实我也不知道--------------------------
那就先到这里吧! ···~再会………………%………………

:lol:victory:

忘记发 web 打开效果图片了

:lol前排,赞一个!

挺好的东西啊,前排支持,如果用无线就更好啦

我觉得还是 插网线稳定 看着就爽(被插了:lol)

之前用ARDUINO+W5100完成过