attiny167-esxz ATMEL Corporation, attiny167-esxz Datasheet - Page 18

no-image

attiny167-esxz

Manufacturer Part Number
attiny167-esxz
Description
8-bit Avr 8-bit Microcontroller Microcontroller With 16k Bytes In-system Programmable Flash And Lin Controller
Manufacturer
ATMEL Corporation
Datasheet
18
ATtiny167
The following code examples show one assembly and one C function for erase, write, or atomic
write of the EEPROM. The examples assume that interrupts are controlled (e.g., by disabling
interrupts globally) so that no interrupts will occur during execution of these functions.
Assembly Code Example
C Code Example
EEPROM_write:
void EEPROM_write(unsigned char ucAddress, unsigned char ucData)
{
}
; Wait for completion of previous write
sbic
rjmp
; Set Programming mode
ldi
out
; Set up address (r18:r17) in address register
out
out
; Write data (r16) to data register
out
; Write logical one to EEMPE
sbi
; Start eeprom write by setting EEPE
sbi
ret
/* 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);
;
EECR,EEPE
EEPROM_write
r16, (0<<EEPM1)|(0<<EEPM0)
EECR, r16
EEARH, r18
EEARL, r17
EEDR, r16
EECR,EEMPE
EECR,EEPE
7728A–AUTO–07/08

Related parts for attiny167-esxz