Advertisement
yair99

Untitled

Nov 14th, 2012
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.34 KB | None | 0 0
  1. //this codes are for writing and reaeding from EEPROM the ip, mac and gateway data
  2.  
  3. /* EEPROM_settings_write_ARD
  4. //EEPROM MAC and IP setter
  5. //http://arduino.cc/playground/Code/EEPROMWriteAnything
  6. //http://arduino.cc/forum/index.php/topic,64673.0.html
  7.  
  8. #include <EEPROM.h>
  9. #include <avr/eeprom.h>
  10.  
  11. struct NET_t
  12. {
  13.   byte   IP[4];
  14.   byte   MAC[6];
  15.   byte   GATE[4];
  16.   short  myPort;             // should be an uint16_t myPort  !!! range = 0..65535
  17.   short  serverPort;        // idem
  18. }
  19. LAN =
  20. {
  21.   {
  22.     10,0,0,13  } // change ip
  23.   ,
  24.   {
  25.      0xDE, 0xAD, 0xBE, 0xEF, 0x00, 0x03  } // will take ip as last 4 bits
  26.   ,
  27.   {
  28.     10,0,0,1  }
  29.   ,
  30.   6666
  31.     ,
  32.   9999
  33. };
  34.  
  35.  
  36. void setup(){
  37.  
  38.   for (int i=0; i<4; i++)
  39.   {
  40.     LAN.MAC[i+2] = LAN.IP[i];
  41.   }
  42.  
  43.   eeprom_write_block((const void*)&LAN, (void*)0, sizeof(LAN)); //write
  44.   //eeprom_read_block((void*)&LAN, (void*)0, sizeof(LAN)); //read
  45. }
  46.  
  47. void loop(){
  48.  
  49. }
  50.  
  51. */
  52. ///////////////////////////////////////////////////////////////////////////
  53. ///////////////////////////////////////////////////////////////////////////
  54. ///////////////////////////////////////////////////////////////////////////
  55.  
  56.  
  57. //EEPROM_settings_read_ARD.ino
  58. /*
  59. //EEPROM MAC and IP setter
  60. //http://arduino.cc/playground/Code/EEPROMWriteAnything
  61.  
  62. #include <EEPROM.h>
  63. #include <avr/eeprom.h>
  64.  
  65.  
  66. struct NET_t
  67. {
  68.   byte   MAC[6];
  69.   byte   IP[4];  
  70.   byte   GATE[4];
  71.   short  myPort;             // should be an uint16_t myPort  !!! range = 0..65535
  72.   short  serverPort;        // idem
  73. }  
  74. LAN;
  75.  
  76. //http://arduino.cc/forum/index.php/topic,64673.0.html
  77.  
  78. void setup(){
  79.   //eeprom_write_block((const void*)&LAN, (void*)0, sizeof(LAN)); //write
  80.   eeprom_read_block((void*)&LAN, (void*)0, sizeof(LAN)); //read
  81.  
  82.   Serial.begin(9600);
  83.  
  84.   Serial.print("MAC: ");
  85.   for (int i; i < 6; i ++) {
  86.     Serial.print(LAN.MAC[i]);
  87.     Serial.print(".");
  88.   }
  89.   Serial.println();
  90.   Serial.print("IP: ");
  91.   for (int i ; i < 4; i ++) {
  92.     Serial.print(LAN.IP[i]);
  93.     Serial.print(".");
  94.   }
  95.   Serial.println();
  96.  
  97.   Serial.print("GATE: ");
  98.   for (int i; i < 4; i ++) {
  99.     Serial.print(LAN.GATE[i]);
  100.     Serial.print(".");
  101.   }
  102.   Serial.println();
  103.  
  104.   Serial.print("myPort: ");
  105.   Serial.println(LAN.myPort);
  106.  
  107.   Serial.print("serverPort: ");
  108.   Serial.println(LAN.serverPort);
  109. }
  110.  
  111. void loop(){
  112.  
  113. }
  114.  
  115. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement