302/317
10 - Second Application: a Sailing Computer
high-order word of both capture variables. To do so, the capture variable is declared as fol-
lows:
typedef union uCapture
{
LWord Long ;
struct sCapture
{
Word High ;
Word Low ;
}W;
} tCapture ;
It consists of the union of an unsigned long and of a structure of two unsigned integers (word).
This allows the variable to be treated as a whole, as in the following line:
LastCapture2 = Capture2.Long ; /* Remember this time for next capture
*/
or as a pair of words:
ld Capture2.W.Low, a
The capture registers are copied into the capture variable using assembler statements. You
might ask why a simple C assignment would not do. The problem is that the timer has a spe-
cial mechanism that locks off the capture mechanism when the high-order byte has been read,
until the low-order byte is read. Since the compiler does not guarantee the order of handling of
the two bytes of a word, it is necessary to do it in assembler.
10.5.2 Refreshing of the display
The display must be refreshed periodically with a bit pattern that changes from true to comple-
ment and back every time. It is important that the duty cycle be exactly 50% to guarantee that
no DC component is fed to the liquid crystal solution. The solution is to do the display refresh
by an interrupt service routine attached to a timer that provides periodic interrupts. This is
done 100 times per second.
Thecodeisthefollowing:
Each of the three four-digit displays is represented by an array such as:
Byte WindSpeedDisplay[4]; /*Contents of the three displays. The
left-most digit */