anzedick 发表于 2013-1-9 20:59:01

新人关于EEPROM demo 的疑问

前几天偶然试了下IDE里自带的EEPROM READ例子,发现个有趣的事情:arduino运行例子后,每次打开IDE的串口监视窗,都会发现EEPROM的地址从0跑起。看了半天代码也没搞明白这是怎么做到的,请各位指点指点。谢谢
#include <EEPROM.h>

// start reading from the first byte (address 0) of the EEPROM
int address = 0;
byte value;

void setup()
{
// initialize serial and wait for port to open:
Serial.begin(9600);
while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
}
}

void loop()
{
// read a byte from the current address of the EEPROM
value = EEPROM.read(address);

Serial.print(address);
Serial.print("\t");
Serial.print(value, DEC);
Serial.println();

// advance to the next address of the EEPROM
address = address + 1;

// there are only 512 bytes of EEPROM, from 0 to 511, so if we're
// on address 512, wrap around to address 0
if (address == 512)
    address = 0;
   
delay(500);
}

johnsonzzd 发表于 2013-1-9 21:05:32

串口一连,arduino就会自动重启

ttyp 发表于 2013-1-9 21:05:51

确实是么?也可能是IDE内存里记录后,监视器从里面读的

Ansifa 发表于 2013-1-10 14:34:04

UNO上面不是有个reset的跳线嘛,把它断开就不会reset了..就不会从0起了

yyy_zc 发表于 2013-2-26 15:58:42

这个和EEPROM没什么关系i,所有的程序都会这样,如前面两位所言。把reset 与地间接个 大点的电容 470 uf ,或者参考官网接个220欧姆的电阻试试
页: [1]
查看完整版本: 新人关于EEPROM demo 的疑问