最新消息:

Arduino库教程-EEPROM-EEPROM Clear

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

EEPROM Clear(清理EEPROM)

  • 在Arduino和genuino板上的微控制器有512字节的EEPROM存储器:当开发板关闭时(就像一个小型硬盘驱动器)开始记忆(即是保存这些数值)。
  • 这个例子说明了如何通过EEPROM write()函数设置所有字节为0,初始化它们来保存新的信息。

硬件要求

  • Arduino 或者 Genuino 开发板

电路

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

原理图

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

样例代码

/*
 * EEPROM Clear
 *
 * Sets all of the bytes of the EEPROM to 0.
 * Please see eeprom_iteration for a more in depth
 * look at how to traverse the EEPROM.
 *
 * This example code is in the public domain.
 */

#include <EEPROM.h>

void setup() {
  // initialize the LED pin as an output.
  pinMode(13, OUTPUT);
  
  /***
    Iterate through each byte of the EEPROM storage.

    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.
  ***/

  for (int i = 0 ; i < EEPROM.length() ; i++) {
    EEPROM.write(i, 0);
  }

  // turn the LED on when we're done
  digitalWrite(13, HIGH);
}

void loop() {
  /** Empty loop. **/
}

[Get Code]
更多

  • EEPROM.write()
  • if()
  • 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寿命。

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