226/317
8 - C Language and the C Compiler
8.3 USING THE C COMPILER
It is not the purpose of this book to teach the basics of C language. The reader is expected to
have had some introduction to the C language, even if he is not an expert; but some experi-
ence is required to appreciate the specific features of C programming for the ST7.
When programming in C for a microcontroller, the following points must be taken into account:
Memory allocation
Initialization of variables
Inputs and outputs
Interrupt handling
Limitations put on the full implementation of the C language
These points will be detailed here. The C language will be used in the applications described
in the next chapters, and you will see how easy it is to write an application program using C
language compared to assembler.
8.3.1 Memory allocation
In a microcontroller, the program is stored in ROM and variables are stored in RAM, as every-
body knows. This means that you must take care to specify, for the development tools, the ad-
dresses in memory of ROM and RAM, so that the linker puts the right things in the right place.
This is not required when programming in C for example for a PC: the development chain de-
cides by itself where to allocate everything, the program works, and there is no need to worry.
The final allocation of memory is performed at the linker level. The linker parameter file con-
tains the information for the linker to place the various segments at the appropriate addresses.
This file must of course match the memory map of the type of microcontroller chosen.
In most cases, no special care must be taken at the C language source level. By default, the
compiler allocates all the code and the initial values of the variable in segments that will be
placed in ROM, while the data storage is placed in segments that will be placed in RAM.