English
Language : 

ATMEGA128A_1 Datasheet, PDF (282/386 Pages) ATMEL Corporation – Write/Erase cycles: 10,000 Flash/100,000 EEPROM
ATmega128A
Note: 1. “1” means unprogrammed, “0´means programmed
25.7 Addressing the Flash During Self-Programming
The Z-pointer together with RAMPZ are used to address the SPM commands. For details on
how to use the RAMPZ, see “RAMPZ - RAM Page Z Select Register” on page 14.
Bit
ZH (R31)
ZL (R30)
15
14
13
12
11
10
9
8
Z15
Z14
Z13
Z12
Z11
Z10
Z9
Z8
Z7
Z6
Z5
Z4
Z3
Z2
Z1
Z0
7
6
5
4
3
2
1
0
Since the Flash is organized in pages (see Table 26-10 on page 296), the program counter can
be treated as having two different sections. One section, consisting of the least significant bits, is
addressing the words within a page, while the most significant bits are addressing the pages.
This is shown in Figure 25-3. Note that the page erase and page write operations are addressed
independently. Therefore it is of major importance that the Boot Loader software addresses the
same page in both the page erase and page write operation. Once a programming operation is
initiated, the address is latched and the Z-pointer/RAMPZ can be used for other operations.
The only SPM operation that does not use the Z-pointer/RAMPZ is setting the Boot Loader Lock
bits. The content of the Z-pointer/RAMPZ is ignored and will have no effect on the operation.
The (E)LPM instruction does also use the Z-pointer/RAMPZ to store the address. Since this
instruction addresses the Flash byte by byte, also the LSB (bit Z0) of the Z-pointer is used.
Figure 25-3. Addressing the Flash During SPM(1)
RAMPZ
BIT 15 ZPCMSB
ZPAGEMSB
10
0 Z - REGISTER
PCMSB
PROGRAM
COUNTER
PCPAGE
PAGE ADDRESS
WITHIN THE FLASH
PROGRAM MEMORY
PAGE
PAGEMSB
PCWORD
WORD ADDRESS
WITHIN A PAGE
PAGE
INSTRUCTION WORD
PCWORD[PAGEMSB:0]:
00
01
02
PAGEEND
Notes: 1. The different variables used in Figure 25-3 are listed in Table 25-8 on page 288.
2. PCPAGE and PCWORD are listed in Table 26-11 on page 296.
8151G–AVR–07/10
282