c_cpp EEPROM阵列

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了c_cpp EEPROM阵列相关的知识,希望对你有一定的参考价值。

/*
FROM: http://forum.arduino.cc/index.php?topic=258193.0
I suppose that the data in EEPROM could also have been defined as:
  uint16_t EEMEM eeArray[rows][cols];
or even as a single block,
  uint8_t EEMEM eeArray[rows * cols * 2];
*/

#include <avr/eeprom.h>

const int rows = 3;
const int cols = 8;

uint16_t my2dArray[rows][cols]= // arrays in SRAM

{
  {0x8888, 0x9999, 0xAAAA, 0xBBBB, 0xCCCC, 0xDDDD, 0xEEEE, 0xFFFF},
  {0x9999, 0xAAAA, 0xBBBB, 0xCCCC, 0xDDDD, 0xEEEE, 0xFFFF, 0x8888},
  {0xAAAA, 0xBBBB, 0xCCCC, 0xDDDD, 0xEEEE, 0xFFFF, 0x8888, 0x9999}
};

const int len = sizeof(my2dArray[0][0])*cols;

uint16_t EEMEM  save1[len],save2[len],save3[len];//array destinations in eeprom


void setup(void)
{
  Serial.begin(9600);

  Serial.println("Arrays read into eeprom");

  for(int j=0; j<rows; j++){

    Serial.println();

    Serial.print("my2dArray[");
    Serial.print(j);
    Serial.print ("]  ");

    for(int i=0; i<cols; i++){

      Serial.print(my2dArray[j][i],HEX);
      Serial.print('\t');

    }
  }
  Serial.println();

  eeprom_write_block(my2dArray[0], save3, len);
  eeprom_write_block(my2dArray[1], save2, len); 
  eeprom_write_block(my2dArray[2], save1, len);


  eeprom_read_block(my2dArray[0], save1, len);
  eeprom_read_block(my2dArray[1], save2, len);
  eeprom_read_block(my2dArray[2], save3, len);


  Serial.println();   
  Serial.println("Arrays read out of eeprom, new values");

  for(int j=0; j<rows; j++){

    Serial.println();

    Serial.print("my2dArray[");
    Serial.print(j);
    Serial.print ("]  ");

    for(int i=0; i<cols; i++){

      Serial.print(my2dArray[j][i],HEX);
      Serial.print('\t');

    }
  }
}

void loop(void)
{
}

以上是关于c_cpp EEPROM阵列的主要内容,如果未能解决你的问题,请参考以下文章

c_cpp 读/写ESP8266 EEPROM - 来自https://forum.arduino.cc/index.php?topic=461677.0

c_cpp 通过ESP8266 EEPROM中的网页提供WIFI SSID,密码和Blynk密钥 - 来自https://community.blynk.cc/t/feeding-wifi-ssid-

c_cpp 阵列

c_cpp 384.随机播放阵列

c_cpp 53.最大子阵列

c_cpp 53.最大子阵列