facebook pixel מדריך: ספריה - EEPROM - דוגמה - EEPROM Put - 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 Put


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

מטרת דוגמה זו היא להציג את השימוש ב-()EEPROM.put שבתוכו משתמש ב-()EEPROM.update שמבצע כתיבה ל-EEPROM רק כשהנתון שונה ממה שכבר שמור בכתובת אליה כותבים את הנתונים. כמות הבתים (bytes) שנכתבת תלויה בסוג הנתון או גודל המבנה של הנתונים שצריך לשמור.

ציוד נדרש

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

מעגל

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

שרטוט

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

קוד

קוד: בחר הכל
/***
    eeprom_put example.

    This shows how to use the EEPROM.put() method.
    Also, this sketch will pre-set the EEPROM data for the
    example sketch eeprom_get.

    Note, unlike the single byte version EEPROM.write(),
    the put method will use update semantics. As in a byte
    will only be written to the EEPROM if the data is actually
    different.

    Written by Christopher Andrews 2015
    Released under MIT licence.
***/

#include <EEPROM.h>

struct MyObject {
  float field1;
  byte field2;
  char name[10];
};

void setup() {

  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

  float f = 123.456f;  //Variable to store in EEPROM.
  int eeAddress = 0;   //Location we want the data to be put.


  //One simple call, with the address first and the object second.
  EEPROM.put(eeAddress, f);

  Serial.println("Written float data type!");

  /** Put is designed for use with custom structures also. **/

  //Data to store.
  MyObject customVar = {
    3.14f,
    65,
    "Working!"
  };

  eeAddress += sizeof(float); //Move address to the next byte after float 'f'.

  EEPROM.put(eeAddress, customVar);
  Serial.print("Written custom data type! \n\nView the example sketch eeprom_get to see how you can retrieve the values!");
}

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



ראו גם:

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

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


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