Page 173 - Programming Microcontrollers in C
P. 173
158 Chapter 4 Small 8-Bit Systems
This definition is not compliant with the ANSI Standard, which re
quires that an int be at least 16 bits wide and a long be at least 32
bits. Since the stack cannot be used to pass arguments, they must be
passed in either registers or as global variables. If they are passed in
registers, only two bytes can be passed. The arguments can be either
two ints or one long. Function return values have the same limi
tations. Of course, the program can use global variables to pass
information to or from a function. A global variable defined external
to any function can be accessed by any function in the program.
Most C compilers for the M68HC05 family provide automatic
placement of variables in the available RAM of the part. Specific
memory addresses are identified to the compiler by the #pragma
memory directives. The following code segment shows an example
of how the memory is defined within an M68HC05 program:
#pragma memory ROMPAGE0 [48] @ 32;
#pragma memory ROMPROG [5888] @ 2048;
#pragma memory RAMPAGE0 [176] @ 80;
#pragma memory RAMPROG [256] @ 256;
This sequence of code will be used to identify the memory map of
the M68HC05B6. This part has 48 bytes of ROM in page zero start
ing at address 32. There are 5888 bytes of program ROM starting at
address 2048. The 176 bytes of page zero RAM starts at address 80.
There are 256 bytes of EEPROM in this part that begin at the address
256. Here we treat EEPROM as program RAM because it is pro
grammable and is outside of the base page.
Inclusion of the above code lines will identify the necessary
memory locations for the compiler, and further concerns about
memory locations should be unnecessary. The compiler will auto
matically place the code in the ROMPROG area and the RAM
requirements will fall at the starting address identified by RAMPAGE0.
Programmers who wish to make use of the ROMPAGE0 memory can
do so by a command like
const int table[]={—,—,—,...,—} @ 32;
This instruction will place the specified array of data in the ROMPROG0
area and will start it at the address 32.