Cov txheej txheem:

Nyeem thiab Sau Cov Ntaub Ntawv rau Sab Nraud EEPROM Siv Arduino: 5 Kauj Ruam
Nyeem thiab Sau Cov Ntaub Ntawv rau Sab Nraud EEPROM Siv Arduino: 5 Kauj Ruam

Video: Nyeem thiab Sau Cov Ntaub Ntawv rau Sab Nraud EEPROM Siv Arduino: 5 Kauj Ruam

Video: Nyeem thiab Sau Cov Ntaub Ntawv rau Sab Nraud EEPROM Siv Arduino: 5 Kauj Ruam
Video: Saib Mis paub Poj niam (hluas nkauj) tus yam ntxwv lub siab 2024, Hlis ntuj nqeg
Anonim
Nyeem thiab Sau Cov Ntaub Ntawv rau Sab Nraud EEPROM Siv Arduino
Nyeem thiab Sau Cov Ntaub Ntawv rau Sab Nraud EEPROM Siv Arduino

EEPROM sawv rau Electrically Erasable Programmable Read-Only Memory.

EEPROM yog qhov tseem ceeb thiab muaj txiaj ntsig zoo vim nws yog daim ntawv tsis hloov pauv ntawm kev nco. Qhov no txhais tau tias txawm tias thaum lub rooj tsavxwm raug tshem tawm, EEPROM nti tseem khaws cov haujlwm uas tau sau rau nws. Yog li thaum koj tshem tawm lub rooj tsavxwm thiab tom qab ntawd rov ua haujlwm dua, txoj haujlwm uas tau sau rau EEPROM tuaj yeem ua haujlwm. Yog li ntawd, EEPROM khw muag khoom thiab ua haujlwm ib qho program txawm li cas los xij. Qhov no txhais tau tias koj tuaj yeem tua lub cuab yeej, tshem nws tawm rau 3 hnub, thiab rov qab los thiab qhib nws thiab nws tseem tuaj yeem ua haujlwm qhov program uas tau teeb tsa hauv nws. Nov yog li cas cov neeg siv khoom siv hluav taws xob feem ntau ua haujlwm.

Txoj haujlwm no yog txhawb nqa los ntawm LCSC. Kuv tau siv cov khoom siv hluav taws xob los ntawm LCSC.com. LCSC muaj kev cog lus ruaj khov los muab kev xaiv dav ntawm cov khoom siv hluav taws xob zoo tshaj plaws ntawm tus nqi zoo tshaj nrog kev xa khoom thoob ntiaj teb mus rau ntau dua 200 lub tebchaws. Sau npe hnub no thiab tau txais $ 8 tawm ntawm koj thawj daim ntawv xaj.

EEPROM kuj tseem muaj txiaj ntsig zoo hauv cov tib neeg bytes hauv ib txwm EEPROM tuaj yeem nyeem nws tus kheej, tshem tawm, thiab rov sau dua. Hauv feem ntau lwm yam kev nco tsis hloov pauv, qhov no tsis tuaj yeem ua tiav. Cov khoom siv EEPROM zoo li Microchip 24-series EEPROM tso cai rau koj ntxiv lub cim xeeb ntxiv rau txhua lub cuab yeej uas tuaj yeem hais lus I²C.

Khoom siv

  1. EEPROM - 24LC512
  2. ATmega328P-PU
  3. 16 MHz Crystal
  4. Cov qhob cij
  5. Resistor 4.7k Ohm x 2
  6. Capacitor 22 pF x 2

Kauj ruam 1: EEPROM Basics

EEPROM Cov hauv paus
EEPROM Cov hauv paus

Microchip 24LC2512 nti tuaj yeem yuav hauv pob 8 tus pin DIP. Cov pins ntawm 24LC512 zoo nkauj ncaj nraim thiab suav nrog lub zog (8), GND (4), sau kev tiv thaiv (7), SCL/SDA (6, 5), thiab peb qhov chaw nyob pins (1, 2, 3).

Keeb Kwm Me Me ntawm ROM

Early "Stored -Program" hom khoos phis tawj - xws li lub laij lej lub rooj thiab cov txhais lus keyboard - pib siv ROM hauv daim ntawv ntawm Diode Matrix ROM. Qhov no yog lub cim xeeb ua los ntawm cov khoom siv hluav taws xob tsis sib xws tso rau ntawm PCB tshwj xeeb uas tau teeb tsa. Qhov no tau muab txoj hauv kev rau Mask ROM nrog kev tshwm sim ntawm kev sib koom ua ke. Daim npog ntsej muag ROM tau zoo ib yam li Diode Matrix ROM nkaus xwb nws tau siv los ntawm qhov loj me me. Qhov no txhais tau tias, txawm li cas los xij, koj tsis tuaj yeem txav ob peb diodes ib ncig nrog cov hlau txuas thiab rov ua dua nws. Daim npog ntsej muag ROM yuav tsum tau tsim los ntawm cov khw thiab tom qab ntawd tsis tuaj yeem hloov kho.

Hmoov tsis zoo, Mask ROM tau kim thiab siv sijhawm ntev los tsim vim tias txhua qhov haujlwm tshiab xav tau cov cuab yeej tshiab los tsim los ntawm cov kws tsim khoom. Xyoo 1956, txawm li cas los xij, qhov teeb meem no tau daws nrog kev tsim ntawm PROM (Programmable ROM) uas tso cai rau cov tsim tawm los teeb tsa cov chips rau lawv tus kheej. Qhov ntawd txhais tau tias cov tuam txhab tsim khoom tuaj yeem tsim ntau lab tus tib lub cuab yeej uas tsis tau sau npe uas ua rau nws pheej yig dua thiab siv tau ntau dua. PROM, txawm li cas los xij, tsuas yog tuaj yeem sau rau ib zaug siv cov cuab yeej hluav taws xob siab. Tom qab PROM lub cuab yeej tau ua haujlwm, tsis muaj txoj hauv kev rov qab ntaus ntawv mus rau nws lub xeev tsis tau npaj tseg.

Qhov no tau hloov pauv xyoo 1971 nrog kev tsim EPROM (Erasable Programmable ROM) uas - ntxiv rau lwm tsab ntawv mus rau cov ntawv luv - coj nrog nws lub peev xwm los lwv cov cuab yeej thiab xa nws mus rau "dawb paug" lub xeev siv lub zog UV teeb pom kev zoo. Yog lawm, koj yuav tsum ua lub teeb ci ci ntawm IC kom rov ua dua nws, qhov txias npaum li cas? Zoo, nws hloov tawm nws zoo nkauj tshwj tsis yog koj yog tus tsim tawm ua haujlwm ntawm firmware uas qhov xwm txheej koj xav tau tiag tiag kom tuaj yeem rov tsim dua lub cuab yeej siv cov cim hluav taws xob. Qhov no thaum kawg tau dhau los ua qhov tseeb hauv xyoo 1983 nrog kev txhim kho EEPROM (Electrically Erasable Programmable ROM) thiab nrog qhov ntawd, peb tuaj txog niaj hnub tam sim no tsis muaj npe luv.

Kauj ruam 2: Quirks ntawm EEPROM

Muaj ob qhov tsis zoo rau EEPROM raws li txoj hauv kev khaws cov ntaub ntawv. Hauv feem ntau daim ntawv thov, qhov zoo tshaj qhov tsis zoo, tab sis koj yuav tsum paub txog lawv ua ntej koom nrog EEPROM rau hauv koj qhov kev tsim tom ntej.

Ua ntej tshaj plaws, thev naus laus zis uas ua rau EEPROM ua haujlwm kuj txwv tus lej uas nws tuaj yeem rov sau dua. Qhov no tau ua nrog cov tshuab hluav taws xob ua rau hauv cov transistors uas ua rau ROM thiab tsim kom txog thaum qhov sib txawv ntawm "1" thiab "0" yog qhov tsis tuaj yeem lees paub. Tab sis tsis txhob txhawj xeeb, feem ntau EEPROMs muaj qhov rov sau tus lej ntau tshaj 1 lab lossis ntau dua. Tsuav koj tsis tas li sau ntawv mus rau EEPROM nws tsis zoo li koj yuav tsoo qhov siab tshaj plaws no. Qhov thib ob, EEPROM yuav tsis raug tshem tawm yog tias koj tshem lub zog los ntawm nws, tab sis nws yuav tsis tuav koj cov ntaub ntawv tas mus li. Cov hluav taws xob tuaj yeem txav tawm ntawm cov transistors thiab los ntawm cov insulator, tshem tawm EEPROM lub sijhawm. Uas tau hais tias, qhov no feem ntau tshwm sim nyob rau xyoo (txawm hais tias nws tuaj yeem ua kom nrawm dua los ntawm tshav kub). Cov neeg tsim khoom feem ntau hais tias koj cov ntaub ntawv muaj kev nyab xeeb ntawm EEPROM rau 10 xyoo lossis ntau dua ntawm chav sov. Thiab muaj ib yam ntxiv uas koj yuav tsum nco ntsoov thaum xaiv EEPROM ntaus ntawv rau koj txoj haujlwm. EEPROM lub peev xwm raug ntsuas hauv cov khoom thiab tsis yog bytes. 512K EEPROM yuav tuav 512Kbits ntawm cov ntaub ntawv, ua lwm yam, tsuas yog 64KB.

Kauj Ruam 3: Arduino Kho Vajtse Hookup

Arduino Kho Vajtse Hookup
Arduino Kho Vajtse Hookup
Arduino Kho Vajtse Hookup
Arduino Kho Vajtse Hookup

Okay, tam sim no peb paub tias EEPROM yog dab tsi, cia peb nqes ib qho thiab saib nws tuaj yeem ua dab tsi! Txhawm rau kom tau txais peb cov cuab yeej tham, peb yuav tsum txuas lub zog nrog rau I²C cov kab ntawv txuas. Cov cuab yeej no, tshwj xeeb, khiav ntawm 5VDC yog li peb yuav txuas nws mus rau 5V tso tawm ntawm peb Arduino UNO. Tsis tas li, kab I²C yuav xav tau rub tawm cov neeg tawm tsam rau kev sib txuas lus kom tshwm sim raug. Tus nqi ntawm cov tshuaj tiv thaiv no nyob ntawm qhov muaj peev xwm ntawm cov kab thiab zaus koj xav sib txuas lus nws, tab sis txoj cai zoo ntawm tus ntiv tes xoo rau cov ntawv thov tsis tseem ceeb tsuas yog khaws nws hauv kΩ ntau yam. Hauv qhov piv txwv no, peb yuav siv 4.7kΩ rub tawm cov neeg tawm tsam.

Muaj peb tus pin ntawm lub cuab yeej no los xaiv I addressC chaw nyob, txoj hauv kev no koj tuaj yeem muaj ntau dua ib qho EEPROM ntawm lub npav thiab hais rau lawv txhua qhov sib txawv. Koj tuaj yeem tsuas yog ua rau lawv tag nrho, tab sis peb yuav txuas rau lawv kom peb tuaj yeem poob hauv cov cuab yeej muaj peev xwm siab dua tom qab hauv kev qhia.

Peb yuav siv lub khob cij los txuas txhua yam ua ke. Daim duab hauv qab no qhia qhov txuas kom raug rau feem ntau I²C EEPROM cov cuab yeej, suav nrog Microchip 24-series EEPROM uas peb muag.

Kauj Ruam 4: Nyeem Ntawv thiab Sau Ntawv

Feem ntau ntawm lub sijhawm thaum koj siv EEPROM ua ke nrog lub microcontroller koj yuav tsis xav pom tag nrho cov ntsiab lus ntawm lub cim xeeb ib zaug. Koj tsuas yog nyeem thiab sau bytes ntawm no thiab nyob ntawd raws li xav tau. Hauv qhov piv txwv no, txawm li cas los xij, peb yuav sau tag nrho cov ntaub ntawv rau EEPROM thiab tom qab ntawv nyeem tag nrho nws rov qab kom peb tuaj yeem pom nws ntawm peb lub computer. Qhov no yuav tsum ua rau peb xis nyob nrog lub tswv yim ntawm kev siv EEPROM thiab tseem ua rau peb muaj kev xav tias cov ntaub ntawv ntau npaum li cas tuaj yeem haum rau ntawm lub cuab yeej me me.

Sau Ib Yam

Peb cov qauv piv txwv yuav yooj yim siv ib qho byte uas los hla qhov chaw nres nkoj thiab sau nws mus rau EEPROM, ua raws txoj hauv kev ntawm pes tsawg bytes peb tau sau rau nco.

Sau ib byte nco mus rau EEPROM feem ntau tshwm sim hauv peb qib:

  1. Xa Qhov Tseem Ceeb Tshaj Plaws Byte ntawm qhov chaw nco uas koj xav sau rau.
  2. Xa Qhov Tsawg Tshaj Plaws Byte ntawm qhov chaw nyob nco uas koj xav sau rau.
  3. Xa cov ntaub ntawv byte uas koj xav khaws hauv qhov chaw no.

Tej zaum muaj ob peb lo lus tseem ceeb nyob ntawd uas tsis piav qhia:

Chaw Nyob

Yog tias koj xav txog tag nrho cov bytes hauv 512 Kbit EEPROM sawv ntawm kab los ntawm 0 txog 64000 - vim tias muaj 8 ntsis rau ib byte thiab yog li koj tuaj yeem haum 64000 bytes ntawm 512 Kbit EEPROM - tom qab ntawv nco chaw nyob yog qhov chaw kab uas koj yuav pom ib qho tshwj xeeb byte. Peb yuav tsum xa qhov chaw nyob ntawd mus rau EEPROM yog li nws paub qhov twg yuav muab cov byte uas peb xa mus.

Qhov Tseem Ceeb Tshaj Plaws thiab Tsawg Qhov Tseem Ceeb Bytes

Vim tias muaj 32000 qhov chaw tuaj yeem hauv 256 Kbit EEPROM - thiab vim 255 yog tus lej loj tshaj plaws koj tuaj yeem nkag mus rau hauv ib byte - peb yuav tsum xa qhov chaw nyob no hauv ob bytes. Ua ntej, peb xa Qhov Tseem Ceeb Tshaj Plaws Byte (MSB) - thawj 8 qhov khoom hauv qhov no. Tom qab ntawd peb xa Qhov Tsawg Tshaj Plaws Byte (LSB) - thib ob 8 khoom. Vim li cas? Vim tias qhov no yog li cas lub cuab yeej xav kom tau txais lawv, qhov ntawd yog txhua yam.

Sau Ntawv

Sau ib byte ntawm ib lub sijhawm yog qhov zoo, tab sis feem ntau EEPROM cov cuab yeej muaj qee yam hu ua "nplooj ntawv sau tsis raug" uas tso cai rau koj sau ntau bytes ntawm ib lub sijhawm ib yam nkaus li koj xav tau ib byte. Peb yuav siv qhov zoo ntawm qhov no hauv peb qhov piv txwv piv txwv. EEPROM siv lub txee sab hauv uas cia li nce qhov chaw nco nrog txhua cov ntaub ntawv hauv qab no byte nws tau txais. Thaum qhov chaw nyob nco tau xa peb tuaj yeem ua raws nws nrog txog 64 bytes ntawm cov ntaub ntawv. EEPROM kwv yees (raug) qhov chaw nyob ntawm 312 ua raws 10 bytes yuav sau byte 0 ntawm chaw nyob 312, byte 1 ntawm chaw nyob 313, byte 2 ntawm chaw nyob 314, thiab ntxiv rau.

Nyeem Dab Tsi

Nyeem ntawv los ntawm EEPROM ib txwm ua raws tib yam peb txheej txheem txheej txheem raws li sau ntawv rau EEPROM:

  1. Xa Qhov Tseem Ceeb Tshaj Plaws Byte ntawm qhov chaw nco uas koj xav sau rau.
  2. Xa Qhov Tsawg Tshaj Plaws Byte ntawm qhov chaw nyob nco uas koj xav sau rau.
  3. Nug cov ntaub ntawv byte ntawm qhov chaw ntawd.

Kauj Ruam 5: Schematics thiab Code

Schematics thiab Code
Schematics thiab Code

Txoj Cai:

#suav nrog

#define eeprom 0x50 // txhais lub hauv paus chaw nyob ntawm EEPROM

void teeb tsa () {

Hlau.begin (); // tsim cov khoom Hlau

Serial.begin (9600);

unsigned int chaw nyob = 0; // thawj qhov chaw nyob ntawm EEPROM

Serial.println ("Peb sau tus lej zip 22222, tus lej zip"); rau (chaw nyob = 0; chaw nyob <5; chaw nyob ++) writeEEPROM (eeprom, chaw nyob, '2'); // Sau 22222 rau EEPROM

rau (chaw nyob = 0; chaw nyob <5; chaw nyob ++) {Serial.print (readEEPROM (eeprom, chaw nyob), HEX); }}

void voj () {

/*tsis muaj dab tsi hauv lub voj () ua haujlwm vim peb tsis xav kom arduino rov sau tib yam rau EEPROM ntau thiab ntau dua. Peb tsuas yog xav tau sau ib zaug, yog li lub voj () ua haujlwm raug zam nrog EEPROMs.*/}

// txhais lub luag haujlwm writeEEPROM

void writeEEPROM (int deviceaddress, unsigned int eeaddress, byte data) {Wire.beginTransmission (deviceaddress); Wire.write ((int) (eeaddress >> 8)); // sau MSB Wire.write ((int) (eeaddress & 0xFF)); // sau LSB Wire.write (cov ntaub ntawv); Wire.endTransmission (); }

// txhais lub luag haujlwm readEEPROM

byte readEEPROM (int deviceaddress, unsigned int eeaddress) {byte rdata = 0xFF; Wire.beginTransmission (deviceddress); Wire.write ((int) (eeaddress >> 8)); // sau MSB Wire.write ((int) (eeaddress & 0xFF)); // sau LSB Wire.endTransmission (); Wire.requestFrom (deviceddress, 1); yog (Wire.available ()) rdata = Wire.read (); rov qab rdata; }

Pom zoo: