Pengetahuan Dasar Simpan Data Char Integer dan Array di EEPROM

Contoh Code -1

void writeInteger(int addr, int dataeeprom)
{
writeeeprom(addr+1, dataeeprom & 0xff);
writeeeprom(addr, (dataeeprom>>8) & 0xff);
}

int ReadInteger(int addr)
{ char value=0,value2=0;
value = readeeprom(addr);
value2 = readeeprom(++addr);
value = (value <<8) & 0xff00;
value = value | value2;
return value;
}

void writeeeprom(unsigned int alamat, unsigned char datana)
{
while(EECR & (1<<1));
EEAR = alamat;
EEDR = datana;
EECR |= (1<<2);
EECR |= (1<<1);
delay_ms(10);
}
unsigned char readeeprom(unsigned int alamat)
{
unsigned char dataeeprom;
while(EECR & (1<<1));
EEAR = alamat;
EECR |= (1<<0);
dataeeprom=EEDR;
return dataeeprom;
delay_ms(10);
}

void simpanArrayKeEEPROM( int array[],int alamat)
{ char i=0;

for(i=0;i<13;i++)
{
writeInteger(alamat, array[i]) ;
alamat=alamat+2;
}
}

 

Contoh Kode -2 dgn menggunakan library EEPROM

#include <EEPROM.h>

void writeEepromInteger(int addr, unsigned int dataeeprom)
{
EEPROM.write(addr+1, dataeeprom & 0xff);
EEPROM.write(addr, (dataeeprom>>8) & 0xff);
delay(50);
}

int readEepromInteger(int addr)
{
int value = EEPROM.read(addr);
int value2 = EEPROM.read(++addr);
value = (value <<8) & 0xff00;
value = value | value2;
return value;
}

//contoh penggunaan fungsi writeEepromInteger()  diatas

writeEepromInteger(1,1500);   // write intger 1500 ke alamat 1 dan 2 dimemori eeprom
writeEepromInteger(4,6789);   // write intger 6789 ke alamat 4 dan 5 dimemori eeprom

//contoh penggunaan fungsi readeepromInteger()  diatas

int dataku =readEepromInteger(1);   //baca Eeprom alamat 1 dan 2 simpan sebagai integer di variable dataku

int datamu =readEepromInteger(4);

Advertisements

About pccontrol

Berisi Tutorial Menggunakan PC untuk mengontrol Peralatan dengan cara mudah & praktis untuk pemula.

Posted on 26/10/2016, in Arduino, AVR, Daftar isi. Bookmark the permalink. Leave a comment.

Komentar ,Saran atau Pertanyaan

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: