atmega161-4pi ATMEL Corporation, atmega161-4pi Datasheet - Page 120

no-image

atmega161-4pi

Manufacturer Part Number
atmega161-4pi
Description
8-bit Microcontroller With 16k Bytes Of In-system Programmable Flash
Manufacturer
ATMEL Corporation
Datasheet
Programming the Flash
120
ATmega161(L)
The Flash is organized as 128 pages of 128 bytes each. When programming the Flash,
the program data is latched into a page buffer. This allows one page of program data to
be programmed simultaneously. The following procedure describes how to program the
entire Flash memory:
A. Load Command “Write Flash”
1. Set XA1, XA0 to “10”. This enables command loading.
2. Set BS1 to “0”.
3. Set DATA to “0001 0000”. This is the command for Write Flash.
4. Give XTAL1 a positive pulse. This loads the command.
B. Load Address Low Byte
1. Set XA1, XA0 to “00”. This enables address loading.
2. Set BS1 to “0”. This selects low address.
3. Set DATA = Address Low byte ($00 - $FF).
4. Give XTAL1 a positive pulse. This loads the address Low byte.
C. Load Data Low Byte
1. Set BS1 to “0”. This selects low data byte.
2. Set XA1, XA0 to “01”. This enables data loading.
3. Set DATA = Data Low byte ($00 - $FF).
4. Give XTAL1 a positive pulse. This loads the data byte.
D. Latch Data Low Byte
E. Load Data High Byte
1. Set BS1 to “1”. This selects high data byte.
2. Set XA1, XA0 to “01”. This enables data loading.
3. Set DATA = Data High byte ($00 - $FF).
4. Give XTAL1 a positive pulse. This loads the data byte.
F. Latch Data High Byte
G. Repeat “B” through “F” 64 times to fill the page buffer.
To address a page in the Flash, seven bits are needed (128 pages). The five most sig-
nificant bits are read from address High byte as described in section “H” below. The two
least significant page address bits, however, are the two most significant bits (bit7 and
bit6) of the latest loaded address Low byte as described in section “B”.
H. Load Address High byte
1. Set XA1, XA0 to “00”. This enables address loading.
2. Set BS1 to “1”. This selects high address.
3. Set DATA = Address High byte ($00 - $1F).
4. Give XTAL1 a positive pulse. This loads the address High byte.
I. Program Page
Give PAGEL a positive pulse. This latches the data Low byte.
(See Figure 76 for signal waveforms.)
Give PAGEL a positive pulse. This latches the data High byte.
1228D–AVR–02/07

Related parts for atmega161-4pi