Datasheet

ATmega48/88/168 Automotive [DATASHEET]
7530K–AVR–07/14
224
23.4 Addressing the Flash During Self-Programming
The Z-pointer is used to address the SPM commands.
Since the flash is organized in pages (see Table 25-12 on page 247), 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 24-3 on page 235. Note that the page erase and page write
operations are addressed independently. Therefore it is of major importance that the software addresses the same page in
both the page erase and page write operation.
The LPM instruction uses the Z-pointer 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 23-1. Addressing the Flash During SPM
(1)
Note: 1. The different variables used in Figure 24-3 on page 235 are listed in Table 25-12 on page 247.
Bit 151413121110 9 8
ZH (R31) Z15 Z14 Z13 Z12 Z11 Z10 Z9 Z8
ZL (R30)Z7Z6Z5Z4Z3Z2Z1Z0
76543210
BIT
PAGEMSBPCMSB
ZPAGEMSBZPCMSB 0115
Z-REGISTER
PROGRAM
COUNTER
WORD ADDRESS
WITHIN PAGE
PAGE ADDRESS
WITHIN THE FLASH
0
PCWORDPCPAGE
02
01
00
PAGEEND
PCWORD [PAGEMSB:0]
Page
Program Memory
Instructions Word
Page