55/317
3 - Programming a microcontroller
this type of situation, its a difficult task for the programmer to complete the debugging of the
application so that it can be validated.
3.2 C LANGUAGE
3.2.1 Why use C?
Many high-level language exist; some have been written specifically for a family of microcon-
trollers, while others are widely-used languages from the computer world that have been
adapted to suit the needs of microcontrollers. Today, one language that prevails in microcon-
troller programming, that is C language.
The primary advantage of C is the ability to write very simple statements that actually involve
hundreds of machine instructions. As an example, the small sample of assembly source code
given in the paragraph about the assembly language has five lines. It could be replaced by the
following line:
memset ( (void*)1, 0xFF, 100 ) ;
This example is not very impressive. However, a C-language statement like:
int UnitPrice, Quantity, Cost ;
float Discount ;
void main ()
{
Cost = (float)( UnitPrice * Quantity ) * ( 1 - Discount ) ;
}
is easy to read and translates into about eighty instructions, without taking into account the
subroutines that perform multiplication and subtraction. We can see at a glance the produc-
tivity gain we can expect from a high-level language.
C language was initially designed as the programming language that came along with the
UNIX operating system. The power and relative simplicity of it made it spread to many dif-
ferent cores, until it became the standard programming language for microcontrollers.
The advantage of C is that it is a language that, though being very powerful, remains very
close to the hardware. This is a key feature for microcontroller applications, especially where
parts of the code are written in assembler. Being close to the hardware means the ability for
the compiler to produce very optimized code by choosing the best instructions for a given job,
when several instructions are available. In particular, setting a port pin high or low must not
Содержание ST7 Series
Страница 1: ...ST7 8 BIT MCU FAMILY USER GUIDE JANUARY 1999 1 ...
Страница 238: ...238 317 8 C Language and the C Compiler 08 Burn bmp Then use the EPROMer programmer software as described in Chapter 7 ...
Страница 289: ...289 317 10 Second Application a Sailing Computer 10 befor Bs Rw Vw VMG AlphaR AlphaV Before the wind ...