EasyManua.ls Logo

ST ST7 - Setting Configuration Registers; Using Macros to Define External Devices

ST ST7
317 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
245/317
8 - C Language and the C Compiler
The register is anded 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 programmerwill 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-
trical schematic has to be changed for some reason. If the pin assignment of a device
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.

Table of Contents

Related product manuals