herunterladen

Freescale Semiconductor
Application Note
AN1952
Rev. 0, 9/2005
© Freescale Semiconductor, Inc., 2005. All rights reserved.
Using Program Memory As
Data Memory
William Jiang
1. Introduction
Microcontrollers with Harvard architecture have separate program
and data memory spaces. Program memory is generally used for
storing program code, although it can be used for storing data;
while, as its name indicates, Data memory is used for storing data.
Because the CodeWarrior tool for the 56800 Family does not
directly support access to Program memory from C code, using
assembly code is the only way to access Program memory. To
speed a product’s time to market, this document includes a
Program Memory Functions Library, which can be used for
accessing data of various types stored in Program Memory. It is
simple, easy to understand, and easy to use. For quick reference,
source code is included in Section C in the Appendix.
2. 56800 Program Memory and Data
Memory
Program memory and Data memory in the 56800 Family are
known as P memory and X memory, respectively. Both memory
spaces are 16 bits wide; i.e., one word wide. Program memory is
normally used for storing program code, i.e. instructions. Data
memory is used for storing program data. There is only one kind
of instruction for Program memory access: MOVE(M)
P:(Rj)+,HHHH. In contrast, many kinds of instructions are used to
access Data memory, such as MOVE instructions,
bit-manipulation instructions and so on. A detailed comparison
between both memory usages is shown in
Table 2-1.
According to this table, 56800 hybrid controllers provide far less
Data memory than Program memory. A user can benefit from
larger Program memory to store data when the data memory space
is insufficient. For example, a user can store various constant
coefficients in the Program Flash. The disadvantage of using
Program memory is obvious: the access time is longer.
Contents
1. Introduction ..................................1
2. 56800 Program Memory and Data
Memory .....................................1
3. Program Memory Functions
Library ...................................... 2
3.1 Performance of the APIs.................3
3.2 Requirements of the APIs...............3
3.3 pmemreads ......................................3
3.4 pmemwrites.....................................4
3.5 pmemreadf ......................................4
3.6 pmemwritef.....................................4
3.7 pmemreadl.......................................4
3.8 pmemwritel .....................................5
3.9 pmemreadns....................................5
3.10pmemwritens...................................5
3.11pmemreadnf ....................................6
3.12pmemwritenf...................................6
4. How to Use the Program Memory
Functions Library ......................6
4.1 Tips and Tricks................................7
4.2 Linker Command File for 56F827
External RAM..................................7
4.3 main.c..............................................9
APPENDIX...................................... 14