Arduino读写EEPROM的语句是只能读写一个字节的,如果要读写一个整型数值(2字节),就要自己做一个函数了。 如下是无符号短整型的例子,其他数据类型可以以此类推。
// Write an int value to EEPROM
void EEPROM_write_short(unsigned int Address, unsigned int Data)
{
unsigned int DataL=Data&0x00FF;
unsigned int DataH=Data>>8;
EEPROM.write(Address, DataH);
EEPROM.write(Address+1, DataL);
}
// Read an int value from EEPROM
unsigned int EEPROM_read_short(unsigned int Address)
{
unsigned int DataH=EEPROM.read(Address);
unsigned int DataL=EEPROM.read(Address+1);
return((DataH<<8) + DataL);
}