Page 242 - Programming Microcontrollers in C
P. 242
Header File 227
port. Does the assembly language generated by the compiler appear
to be efficient? If not, what can be done to improve the code?
2. Write and compile a program that uses Output Compare 3 to gener
ate a periodic interrupt. This interrupt should occur each millisecond.
3. With the time tick generated by the results of Example 2 above,
create a clock that will keep track of the time of day accurate to the
nearest one-hundredth of a second.
The Compiler Optimizer and Volatile
The compiler optimizer that is a part of the Cosmic C compiler does
an excellent job of reducing code size. One of the steps involved is to
remove code required to change values that are not changed by the pro
gram. Recall that the volatile qualifier identifies varibles that should not
be optimized. The following code sequence will show this problem:
volatile char able;
char baker
test(void)
{
char dog;
dog = able;
dog = able;
able = 0;
able = 0;
dog = baker;
dog = baker;
baker = 0;
baker = 0;
}
Note that this function makes multiple assignments of dog, able,
and baker. The assignments involving able show how the compiler
responds to a volatile variable, and baker to a nonvolatile variable.
The following listing is the compilation of the above program:
1 ; Compilateur C pour MC68HC11 (COSMIC-France)
32 .include”macro.h11"