【问题标题】:Writing Data to Arduino EEPROM将数据写入 Arduino EEPROM
【发布时间】:2013-04-18 17:03:18
【问题描述】:

这是此处帖子的后续内容 - Writting data to the Arduino's onboard EEPROM 我刚刚尝试在 URL 中使用 sn-ps 但不起作用。请帮我解决以下错误。

write_to_eeprom.cpp:8:5: error: expected unqualified-id before '[' token
write_to_eeprom.cpp: In function 'void setup()':
write_to_eeprom.cpp:12:16: error: 'stringToWrite' was not declared in this scope
write_to_eeprom.cpp: In function 'void loop()':
write_to_eeprom.cpp:22:33: error: invalid conversion from 'uint8_t {aka unsigned char}' to 'char*' [-fpermissive]
write_to_eeprom.cpp: In function 'void EEPROM_write(void*, byte)':
write_to_eeprom.cpp:32:32: error: 'void*' is not a pointer-to-object type

这里是代码

#include <EEPROM.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(8, 13, 9, 4, 5, 6, 7);
char[] stringToWrite = "Test";
void setup() {
  lcd.begin(16, 2);
  delay(5000);
  EEPROM_write(stringToWrite, strlen(stringToWrite));
}

void loop() {
  delay(10000);
  int addr = 0;
  byte datasize = EEPROM.read(addr++);
  char stringToRead[0x20];          // allocate enough space for the string here!
  char * readLoc = stringToRead;
  for (int i=0;i<datasize; i++) {
    readLoc = EEPROM.read(addr++);
    readLoc++;
  }
}
// Function takes a void pointer to data, and how much to write (no other way to know)
// Could also take a starting address, and return the size of the reach chunk, to be more generic
void EEPROM_write(void * data, byte datasize) {
  int addr = 0;
  EEPROM.write(addr++, datasize);
  for (int i=0; i<datasize; i++) {
    EEPROM.write(addr++, data[i]);
  }
}

【问题讨论】:

    标签: arduino eeprom


    【解决方案1】:

    好吧,你需要修复你的代码:

    第 8 行 -- [] 需要放在 stringToWrite 之后 第 12 行 -- 修复第 8 行后应该会更好

    第 22 行——您需要取消对 readLoc 的引用。在它之前添加一个“*”。

    第 32 行——你的参数“data”是一个指向 void 的指针,它没有大小。因此,您将无法将其用作数组。您可以将声明更改为:

    void EEPROM_write(char * data, byte datasize)

    这修复了编译器错误。快速查看代码的语义似乎正在做你想做的事。祝你好运。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多