Files
RGBController/eeprom.h
2017-05-23 10:17:36 +02:00

41 lines
1.0 KiB
C

void EEPROM_write_char(uint16_t address, unsigned char data)
{
/* Wait for completion of previous write */
while(EECR & (1<<EEPE));
/* Set up address and Data Registers */
EEAR = address;
EEDR = data;
/* Write logical one to EEMPE */
EECR |= (1<<EEMPE);
/* Start eeprom write by setting EEPE */
EECR |= (1<<EEPE);
}
unsigned char EEPROM_read_char(uint16_t uiAddress)
{
/* Wait for completion of previous write */
while(EECR & (1<<EEPE));
/* Set up address register */
EEAR = uiAddress;
/* Start eeprom read by writing EERE */
EECR |= (1<<EERE);
/* Return data from Data Register */
return EEDR;
}
void EEPROM_write_string(uint16_t address, char* buffer, uint16_t length)
{
for(uint16_t i = 0; i < length; i++)
{
EEPROM_write_char( address+i, buffer[i] );
}
}
void EEPROM_read_string(uint16_t address, char* buffer, uint16_t length)
{
for(uint16_t i = 0; i < length; i++)
{
buffer[i] = EEPROM_read_char( address+i);
}
}