command interpreter and epprom

This commit is contained in:
IMback
2017-05-19 09:48:19 +02:00
parent cb779f21d4
commit ecd7ad677b
9 changed files with 282 additions and 58 deletions

42
eeprom.h Normal file
View File

@ -0,0 +1,42 @@
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);
}
}