Cov txheej txheem:

Koj Arduino's Inbuilt EEPROM: 6 Cov Kauj Ruam
Koj Arduino's Inbuilt EEPROM: 6 Cov Kauj Ruam

Video: Koj Arduino's Inbuilt EEPROM: 6 Cov Kauj Ruam

Video: Koj Arduino's Inbuilt EEPROM: 6 Cov Kauj Ruam
Video: Еще один барабанный секвенсор Arduino с минимальным аппаратным обеспечением drumseq81212 2024, Hlis ntuj nqeg
Anonim
Koj Arduino's Inbuilt EEPROM
Koj Arduino's Inbuilt EEPROM

Hauv kab lus no peb yuav tshuaj xyuas sab hauv EEPROM hauv peb Arduino cov laug cam. Dab tsi yog EEPROM qee tus ntawm koj yuav hais? EEPROM yog Electrically Erasable Programmable Read-Only Memory.

Nws yog daim ntawv uas tsis hloov pauv lub cim xeeb uas tuaj yeem nco tau yam nrog lub zog raug kaw, lossis tom qab rov pib dua Arduino. Qhov zoo nkauj ntawm qhov cim xeeb no yog tias peb tuaj yeem khaws cov ntaub ntawv tsim tawm hauv daim duab kos ntawm qhov chaw ruaj khov dua.

Vim li cas koj thiaj siv EEPROM sab hauv? Rau cov xwm txheej uas cov ntaub ntawv tshwj xeeb rau qhov xwm txheej xav tau lub tsev nyob tas mus li. Piv txwv li, khaws cia tus lej tshwj xeeb thiab hnub tsim khoom ntawm kev lag luam Arduino-raws txoj haujlwm-kev ua haujlwm ntawm cov duab kos tuaj yeem tso tawm tus lej xov tooj ntawm LCD, lossis cov ntaub ntawv tuaj yeem nyeem los ntawm kev xa tawm 'kev pabcuam kos duab'. Lossis koj yuav xav suav qee qhov xwm txheej thiab tsis tso cai rau tus neeg siv rov kho lawv-xws li lub ntsuas cua lossis ntsuas lub voj voog ua haujlwm.

Kauj Ruam 1: Cov ntaub ntawv twg tuaj yeem khaws cia?

Cov ntaub ntawv twg tuaj yeem khaws cia?
Cov ntaub ntawv twg tuaj yeem khaws cia?

Txhua yam uas tuaj yeem sawv cev ua bytes ntawm cov ntaub ntawv. Ib byte ntawm cov ntaub ntawv yog ua los ntawm yim khoom ntawm cov ntaub ntawv. Me ntsis tuaj yeem yog (tus nqi 1) lossis tawm (tus nqi 0), thiab zoo meej rau sawv cev rau tus lej hauv daim ntawv binary. Hauv lwm lo lus, tus lej binary tuaj yeem siv zeros thiab tus lej los sawv cev rau tus nqi. Yog li binary tseem hu ua "base-2", vim nws tsuas tuaj yeem siv ob tus lej.

Yuav ua li cas tus lej binary nrog tsuas yog siv ob tus lej sawv cev rau tus lej loj? Nws siv ntau yam thiab xoom. Cia peb tshuaj xyuas tus lej binary, hais 10101010. Raws li qhov no yog tus lej-2 tus lej, txhua tus lej sawv cev 2 rau lub zog x, los ntawm x = 0 mus rau tom ntej.

Kauj ruam 2:

Duab
Duab

Saib seb txhua tus lej ntawm tus lej binary tuaj yeem sawv cev rau tus lej-10 tus lej. Yog li tus lej binary saum toj no sawv cev rau 85 hauv paus-10-tus nqi 85 yog qhov sib npaug ntawm cov hauv paus-10 qhov tseem ceeb. Lwm qhov piv txwv - 11111111 hauv binary sib npaug 255 hauv lub hauv paus 10.

Kauj ruam 3:

Tam sim no txhua tus lej hauv tus lej binary siv ib qho 'me ntsis' ntawm kev nco, thiab yim khoom ua ib byte. Vim yog kev txwv sab hauv ntawm microcontrollers hauv peb Arduino cov laug cam, peb tsuas tuaj yeem khaws 8-tus lej (ib byte) hauv EEPROM.

Qhov no txwv tus lej zauv ntawm tus lej kom poob ntawm xoom thiab 255. Nws yog tom qab koj txiav txim siab li cas koj cov ntaub ntawv tuaj yeem sawv cev nrog tus lej ntawd. Tsis txhob cia qhov ntawd tso koj tawm - cov lej nyob hauv txoj kev raug tuaj yeem sawv cev yuav luag txhua yam! Muaj ib qho kev txwv kom ceev faj - pes tsawg lub sijhawm peb tuaj yeem nyeem lossis sau ntawv mus rau EEPROM. Raws li cov chaw tsim khoom Atmel, EEPROM zoo rau 100, 000 nyeem/sau mus (saib cov ntaub ntawv).

Kauj ruam 4:

Tam sim no peb paub peb cov khoom thiab bytes, pes tsawg bytes tuaj yeem khaws hauv peb Arduino lub microcontroller? Cov lus teb sib txawv nyob ntawm tus qauv ntawm microcontroller. Piv txwv li:

  • Cov laug cam nrog Atmel ATmega328, xws li Arduino Uno, Uno SMD, Nano, Lilypad, thiab lwm yam - 1024 bytes (1 kilobyte)
  • Cov laug cam nrog Atmel ATmega1280 lossis 2560, xws li Arduino Mega series - 4096 bytes (4 kilobytes)
  • Cov laug cam nrog Atmel ATmega168, xws li thawj Arduino Lilypad, qub Nano, Diecimila thiab lwm yam - 512 bytes.

Yog tias koj tsis paub meej saib ntawm Arduino kho vajtse ntsuas lossis nug koj tus thawj coj khoom lag luam. Yog tias koj xav tau EEPROM ntau dua li qhov muaj nrog koj lub microcontroller, txiav txim siab siv I2C EEPROM sab nraud.

Txog tam sim no peb tam sim no nkag siab txog cov ntaub ntawv twg thiab ntau npaum li cas tuaj yeem khaws cia hauv peb Arduino's EEPROM. Tam sim no nws yog lub sijhawm los ua qhov no. Raws li tau tham ua ntej, muaj qhov txwv qhov chaw rau peb cov ntaub ntawv. Hauv cov piv txwv hauv qab no, peb yuav siv lub rooj sib tham Arduino nrog ATmega328 nrog 1024 bytes ntawm EEPROM cia.

Kauj ruam 5:

Txhawm rau siv EEPROM, yuav tsum muaj lub tsev qiv ntawv, yog li siv cov tsev qiv ntawv hauv qab no hauv koj cov duab kos:

#suav nrog "EEPROM.h"

Tus so yog yooj yim heev. Txhawm rau khaws ib qho ntawm cov ntaub ntawv, peb siv cov haujlwm hauv qab no:

EEPROM.write (a, b);

Qhov ntsuas a yog txoj haujlwm hauv EEPROM khaws cov lej (0 ~ 255) ntawm cov ntaub ntawv b. Hauv qhov piv txwv no, peb muaj 1024 bytes ntawm lub cim xeeb cia, yog li tus nqi ntawm a yog nruab nrab ntawm 0 thiab 1023. Txhawm rau khaws ib daim ntawm cov ntaub ntawv zoo ib yam li yooj yim, siv:

z = EEPROM.read (a);

Qhov twg z yog tus lej txhawm rau khaws cov ntaub ntawv los ntawm EEPROM txoj haujlwm a. Tam sim no kom pom ib qho piv txwv.

Kauj Ruam 6:

Duab
Duab

Cov duab kos no yuav tsim cov lej sib xws ntawm 0 thiab 255, khaws cia rau hauv EEPROM, tom qab ntawd rov qab los thiab muab tso rau ntawm cov ntawv saib. Qhov sib txawv EEsize yog qhov txwv qis tshaj ntawm koj li EEPROM loj, yog li (piv txwv) qhov no yuav yog 1024 rau Arduino Uno, lossis 4096 rau Mega.

// Arduino sab hauv EEPROM ua qauv qhia

#suav nrog

zz koj;. int EEsize = 1024; // loj hauv bytes ntawm koj lub rooj tsav xwm EEPROM

void teeb tsa ()

{Serial.begin (9600); randomSeed (analogRead (0)); } void loop () {Serial.println ("Sau cov lej tsis raug …"); rau (int i = 0; i <EEsize; i ++) {zz = random (255); EEPROM.write (i, zz); } Serial.println (); rau (int a = 0; a <EEsize; a ++) {zz = EEPROM.read (a); Serial.print ("EEPROM txoj haujlwm:"); Serial.print (a); Serial.print ("muaj"); Serial.println (zz); ncua (25); }}

Cov zis los ntawm cov saib saib yuav tshwm, raws li qhia hauv daim duab.

Yog li ntawd koj muaj nws, lwm txoj hauv kev zoo los khaws cov ntaub ntawv nrog peb cov tshuab Arduino. Txawm hais tias tsis yog qhov qhia tau zoo tshaj plaws, nws yeej yog qhov muaj txiaj ntsig.

Cov ntawv tshaj tawm no tau coj tuaj rau koj los ntawm pmdway.com - txhua yam rau cov kws tsim khoom thiab cov khoom siv hluav taws xob, nrog kev xa khoom dawb thoob ntiaj teb.

Pom zoo: