English
Language : 

ATMEGA8U2_14 Datasheet, PDF (24/310 Pages) ATMEL Corporation – 125 Powerful Instructions – Most Single Clock Cycle Execution
ATmega8U2/16U2/32U2
The next code examples show assembly and C functions for reading the EEPROM. The exam-
ples assume that interrupts are controlled so that no interrupts will occur during execution of
these functions.
Assembly Code Example(1)
EEPROM_read:
; Wait for completion of previous write
sbic EECR,EEPE
rjmp EEPROM_read
; Set up address (r18:r17) in address register
out EEARH, r18
out EEARL, r17
; Start eeprom read by writing EERE
sbi EECR,EERE
; Read data from Data Register
in r16,EEDR
ret
C Code Example(1)
unsigned char EEPROM_read(unsigned int 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;
}
Note: 1. See “Code Examples” on page 6.
7.5.4 GPIOR2 – General Purpose I/O Register 2
Bit
0x2B (0x4B)
Read/Write
Initial Value
7
6
5
4
3
2
1
0
MSB
LSB
GPIOR2
R/W
R/W
R/W
R/W
R/W
R/W
R/W
R/W
0
0
0
0
0
0
0
0
7.5.5 GPIOR1 – General Purpose I/O Register 1
Bit
0x2A (0x4A)
Read/Write
Initial Value
7
6
5
4
3
2
1
0
MSB
LSB
GPIOR1
R/W
R/W
R/W
R/W
R/W
R/W
R/W
R/W
0
0
0
0
0
0
0
0
24
7799D–AVR–11/10