Datasheet
22
ATtiny828 [DATASHEET]
8371A–AVR–08/12
Note: See “Code Examples” on page 7.
The next code examples show assembly and C functions for reading the EEPROM. The examples assume that
interrupts are controlled so that no interrupts will occur during execution of these functions.
Note: See “Code Examples” on page 7.
C Code Example
void EEPROM_write(unsigned int ucAddress, unsigned char ucData)
{
/* Wait for completion of previous write */
while(EECR & (1<<EEPE))
;
/* Set Programming mode */
EECR = (0<<EEPM1)|(0<<EEPM0)
/* Set up address and data registers */
EEAR = ucAddress;
EEDR = ucData;
/* Write logical one to EEMPE */
EECR |= (1<<EEMPE);
/* Start eeprom write by setting EEPE */
EECR |= (1<<EEPE);
}
Assembly Code Example
EEPROM_read:
sbic EECR, EEPE
rjmp EEPROM_read ; Wait for completion of previous write
out EEARH,r18
out EEARL,r17 ; Set up address (r18:r17) in address registers
sbi EECR, EERE ; Start eeprom read by writing EERE
in r16, EEDR ; Read data from data register
ret