DOC0933.PDF
(
20 KB
)
Pobierz
AVR102: Block Copy Routines
Features
•
Program Memory (Flash) to SRAM Copy
Routine
•
SRAM to SRAM Copy Routine
•
Extremely Code Efficient Routines
Flash
→
SRAM: 6 Words,
SRAM
→
SRAM: 5 Words
•
Runable Test/Example Program
Introduction
This application note contains routines
for transfer of data blocks.
• Flash to SRAM Copy. Copies data
blocks of sizes up to 256 bytes from
any Flash address to any SRAM
address.
• SRAM to SRAM copy. Copies data
blocks of sizes up to 256 bytes from
any SRAM source address to any
SRAM destination address.
The routines are described in detail in
the following sections.
byte is returned. The returned byte is
always found in R0. To obtain the 15
MSBs of Z with the correct word value,
the user must be careful to load Z with 2
times the address of the first double byte
in the table. The program listing shows
how to handle this precaution.
During data transfer, the auto-increment
facility of the pointers is utilized. Writing
to SRAM is done using the “ST Y+,Rs”-
instruction. The “LPM”-instruction does
not support auto-increment or decre-
ment. The “ADIW” instruction is used to
increment the 16-bit pointer.
The register variable “flashsize” is used
as a loop counter in the routine.
8-Bit
Microcontroller
Application
Note
AVR102
FLASH2RAM
R0
←
FLASH@Z (LPM)
Flash to SRAM Copy -
Subroutine “flash2ram”
Before calling this routine, the following
input parameters must be set up by the
user:
• “flashsize” - Register variable holding
the size of the data block
• Z-pointer - 2 x source address of first
Flash block byte
• Y-pointer - Destination address of first
SRAM block byte
The routine uses the “LPM”-instruction
which is the one to use for data transfer
from Flash to Register File. The instruc-
tion selects the Flash word (16-bit)
pointed to by the 15 most significant
bytes of the Z-pointer. If LSB of the Z-
pointer is 0, the lower byte of the Flash
word is returned, otherwise the higher
SRAM@Y
←
R0,
Y
←
Y+1
Z
←
Z+1
FLASHSIZE
←
FLASHSIZE - 1
FLASHSIZE = 0?
Y
RETURN
N
Figure 1.
“flash2ram” Flow Chart
0933A-A–8/97
1
Table 1.
“flash2ram” Register Usage
Register
R0
R16
R28
R29
R30
R31
“flashsize” - size of data block to copy
“YL” - low address of SRAM data start
“YH” - high address of SRAM data start
“ZL” - low address of Flash data start
“ZH” - high address of Flash data start
Input
Internal
Temporary data storage
Output
Table 2.
“flash2ram” Performance Figures
Parameter
Code Size (Words)
Execution Time
Register Usage
Value
5 + return
10 x (block size) + return
• Low registers
• High registers
• Pointers
None
None
:1
:1
:Y, Z
Interrupts Usage
Peripherals Usage
SRAM to SRAM Copy -
Subroutine “ram2ram”
Before calling this routine, the following input parameters
must be set up by the user:
• “ramsize” - Register variable holding the size of the data
block
• Z-pointer - source address of first byte in block
• Y-pointer - destination address of first byte in block
By utilizing the pointer auto-increment facility, this routine is
extremely compact. Moving one byte of data and incre-
menting both pointers requires 2 instructions only. Two
more instructions are needed to decrement an check the
register variable “ramsize” which is used as a loop counter
in the routine. The data are temporarily stored in the regis-
ter variable “ramtemp” during transfer.
RAM2RAM
RAMTEMP
←
SRAM@Z,
Z
←
Z+1
SRAM@Y
←
RAMTEMP,
Y
←
Y+1
RAMSIZE
←
RAMSIZE - 1
RAMSIZE = 0?
Y
RETURN
N
Figure 2.
“ram2ram” Flow Chart
2
AVR102
AVR102
Table 3.
“ram2ram” Register Usage
Register
R1
R16
R28
R29
R30
R31
“ramsize” - size of data block to copy
“YL” - destination address low byte
“YH” - destination address high byte
“ZL” - source address low byte
“ZH” - source address high byte
Input
Internal
“ramtemp” - Temporary data storage
Output
Table 4.
“flash2ram” Performance Figures
Parameter
Code Size (Words)
Execution Time
Register Usage
Value
4 + return
6 x (block size) + return
• Low registers
• High registers
• Pointers
None
None
:1
:1
:Y, Z
Interrupts Usage
Peripheral Usage
Test/Example Program
The application note program file contains a runable test
program which uses the copy application routines to copy
20 bytes of data from Flash to SRAM, then make a second
copy of the data at another SRAM location. The test pro-
gram is made for use with an AT90S8515. By changing
including another “*def.inc” file, the program can be used
with any other AVR MCU with SRAM.
3
Plik z chomika:
fred1144
Inne pliki z tego folderu:
avr204.asm
(12 KB)
an032code.zip
(3 KB)
avr100.asm
(5 KB)
avr102.asm
(3 KB)
avr302.asm
(12 KB)
Inne foldery tego chomika:
Errata
ProgSpec
Russian
Zgłoś jeśli
naruszono regulamin