最新消息:

Arduino库教程-EEPROM-EEPROM Read

Arduino 少儿编程 2017浏览 0评论
Arduino库教程

EEPROM Read(读取EEPROM)

  • 在Arduino和genuino板上的微控制器有512字节的EEPROM存储器:当开发板关闭时(就像一个小型硬盘驱动器)开始记忆(即是保存这些数值)。
  • 这个例子说明了如何通过EEPROM.read()函数读取所有字节,和怎样打印这些值到Arduino软件IDE的串口窗口上。

硬件要求

  • Arduino 或 Genuino 开发板

电路

这个例子的电路没有额外的连接
Arduino库教程-EEPROM-EEPROM Read
图由 Fritzing 软件绘制

原理图

Arduino库教程-EEPROM-EEPROM Read
图由 Fritzing 软件绘制

样例代码

/*
 * EEPROM Read
 *
 * Reads the value of each byte of the EEPROM and prints it
 * to the computer.
 * This example code is in the public domain.
 */

#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 native USB port 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, when at the end restart at the beginning.

    Larger AVR processors have larger EEPROM sizes, E.g:
    - Arduno Duemilanove: 512b EEPROM storage.
    - Arduino Uno:        1kb EEPROM storage.
    - Arduino Mega:       4kb EEPROM storage.

    Rather than hard-coding the length, you should use the pre-provided length function.
    This will make your code portable to all AVR processors.
  ***/
  address = address + 1;
  if (address == EEPROM.length()) {
    address = 0;
  }

  /***
    As the EEPROM sizes are powers of two, wrapping (preventing overflow) of an
    EEPROM address is also doable by a bitwise and of the length - 1.

    ++address &= EEPROM.length() - 1;
  ***/

  delay(500);
}

[Get Code]
更多

  • EEPROM.read()
  • serial.begin()
  • serial.print()
  • EEPROM library reference
  • EEPROM Clear: 清理EEPROM里面的数据。
  • EEPROM Read: 读取EEPROM,并且发送它的值到电脑。
  • EEPROM Write: 保存模拟输入引脚的值到EEPROM。
  • EEPROM Crc: 将EEPROM内容里的CRC当作数组分析。
  • EEPROM Get: 从EEPROM获得一个值,并作为float格式串行打印。
  • EEPROM Iteration: 明白怎样到达EEPROM存储本地。
  • EEPROM Put: 用变量来把一些数值放到EEPROM里。
  • EEPROM Update: 保存从A0读取的数值到EEPROM里,仅在不同的时候写入,以延长EEPROM寿命。

您必须 登录 才能发表评论!