facebook pixel מדריך: ספריה - EEPROM - דוגמה - EEPROM Read - www.4project.co.il
Main logo www.4project.co.il
כל הרכיבים לפרוייקט שלכם
עגלת קניות

העגלה ריקה

לקוחות נכבדים, אלה שעות הפעילות של המחסן במהלך פסח 2024:
ערב חג וחג ראשון (22-23/04) - המחסן סגור
חול המועד (24-25/04) - המחסן יפעל בין 8:00 עד 15:00
ערב חג וחג שני (28-29/04) - המחסן סגור
נחזור לפעילות רגילה ביום שלישי 30/04
חג שמח!

ספריה - EEPROM - דוגמה - EEPROM Read


2022-06-14 11:53:20
לכרטיסי Arduino המבוססים על מיקרובקר AVR יש EEPROM - זכרון ששומר על הערכים שלו גם כשמכבים את החשמל (בדומה לדיסק קשיח קטן). ספריה זו מאפשרת לכם לקרוא ולכתוב ערכים אלה.

דוגמה זו מראה איך לקרוא ערכים של כל byte ב-EEPROM בעזרת פונקציית ()EEPROM.read ואיך להדפיס את הערכים שלהם בחלון תקשורת טורית של סביבת פיתוח ה-Arduino.

ציוד נדרש

כרטיס פיתוח Arduino.

מעגל

אין צורך בהכנת מעגל לדוגמה זו.

שרטוט

אין צורך בשרטוט לדוגמה זו.

קוד

קוד: בחר הכל
/*
* 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);
}



ראו גם:

()EEPROM.read
()Serial.begin
()Serial.print
פירוט ספריית EEPROM
דוגמת EEPROM Clear - ניקיון הבתים ב-EEPROM
דוגמת EEPROM Write - שמירת נתונים מכניסה אנלוגית ב-EEPROM
דוגמת EEPROM CRC - חישוב בדיקת CRC על תוכן של EEPROM כאילו שהם היו כמערך
דוגמת EEPROM Iteration - הסבר על מעבר בין כתובות שונות ב-EEPROM
דוגמת EEPROM Put - שמירת נתונים ב-EEPROM עם התחשבות בסמנטיקה של המשתנים
דוגמת EEPROM Get - קריאת ערכים מ-EEPROM והדפסתם כ-float ל-Serial
דוגמת EEPROM Update - שמירת נתון מכניסה אנלוגית ב-EEPROM, כאשר הכתיבה מתבצעת רק כשיש שינוי כדי להאריך את אורך החיים של ה-EEPROM

פירוט שפת תכנות לסביבת Arduino


עמוד זה הוא תרגום של EEPROM Read לפי רישיון Creative Commons Attribution-ShareAlike 3.0.