245/317
8 - C Language and the C Compiler
The register is
and
ed with the one's complement of 1 shifted by the appropriate number of
places, which preserves all bits except the one that we want to reset; and the result is written
back into the register.
8.8.2 Setting configuration registers
The syntax above can be extended to load a configuration register in a very legible manner:
TACR1 = ( 1 << ICIE )
|
( 0 << OCIE )
|
( 0 << TOIE )
|
/* Interrupt on overflow. */
( 0 << OLVL2 ) |
/* Cycle starts with output low for 2.3
ms ... */
( 0 << IEDG1 ) |
( 0 << OLVL1 ) ;
/* and ends with output high (when active)
for 1 ms. */
This syntax shows clearly that of all the bits of the register, we set ICIE to one, and all other
bits to zero. This allows for later changes that can be done easily with little chance of confu-
sion.
8.8.3 Using macros to define external devices
When designing an application, the programmer and the electronics engineer have to consult
each other to define which pins are connected to which device, so that the programmer will as-
sign certain bits of certain registers to these devices.
In many cases, when devices need less than eight bits, like switches, decoders, etc. the circuit
designer connects several of them to the same eight-bit port, to fully use the capabilities of the
device. This will require the programmer to use binary expressions to extract those bits he
needs at a certain time, without taking into account the other bits that are only relevant at other
times.
If a certain device is used at several places in the program, the same expression must be used
in each place. Such expressions requires some care from the programmer in order to be done
correctly.
Unfortunately, in the process of developing a project, it happens more than once that the elec-
trica l schem atic has to b e change d for some re ason. If the pin a ssig nme nt o f a de vice
changes, the programmer has to update all the places where this device is used, introducing
the risk of a change being forgotten, which will make the changed program fail.
To avoid this, the programmer can use a macro that defines the expression to be used each
time the device is accessed. This macro can be defined in the main project header file, which
allows changes like that mentioned above to be performed at one time in one place.
Содержание 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 ...