转自:https://www.arduino.cn/thread-1157-1-1.html
EEPROM (Electrically Erasable Programmable Read-Only Memory),电可擦可编程只读存储器--一种掉电后数据不丢失的存储芯片。 简而言之就是你想断电后arduino还要保存一些参数,就使用EEPROM吧。 在各型号的arduino控制器上的AVR芯片均带有EEPROM,也有外接的EEPROM芯片,常见arduino控制器的EEPROM大小: Arduino UNO、Arduino duemilanove-m328、Zduino m328均使用ATmega328芯片,EEPROM都为1K Arduino duemilanove-m168的EEPROM为512bytes Arduino 2560的EEPROM为4K
下面我们介绍arduino自带的EEPROM使用方法,arduino的库已经为我们准备好了EEPROM类库,我们要使用得先调用EEPROM.h,然后使用write和read方法,即可操作EEPROM。 另:下面的官方例子由于写成较早,所以讲EEPROM的大小都定为了512字节,实际使用中,大家可参照上面所说的EEPROM大小,自行更改。
1.写入 选择 File>Examples>EEPROM>eeprom_write
/*
|
|
* EEPROM Write
|
|
*
|
|
* Stores values read from analog input 0 into the EEPROM.
|
|
* These values will stay in the EEPROM when the board is
|
|
* turned off and may be retrieved later by another sketch.
|
|
*/
|
|
|
|
// EEPROM 的当前地址,即你将要写入的地址,这里就是从0开始写
|
|
int addr = 0;
|
|
void setup()
|
|
{
|
|
}
|
|
void
|