303/317
10 - Second Application: a Sailing Computer
The contents of this array are copied to the SPI, one byte at a time, by the following function.
The last three bytes of the array contain the values to be displayed. The function uses the
SevenSegmentCode lookup table to find the pattern to be sent to the display shiftregisters. The
following conventions apply to the values to be displayed:
The figures 0 to 9 are displayed as is. If a digit is to be displayed with a decimal point to the left,
the value 16 is added to it. To blank the digit, the value must be 10.
The first byte is not converted, as it already contains the pattern to display (1, -1, or an arrow).
void RefreshOneDisplay ( char*s)
{
signed char i ;
for(i=3;i>0;i--) /*Right 3 digits */
{
while ( ( SPISR&(1<<SPIF ) ) ==0); /*Wait for end of
transmission */
SPIDR = SevenSegmentCode [ s[i] ] ^ Polarity ; /* Send current
byte with proper polarity */
}
while ( ( SPISR&(1<<SPIF))==0); /*Wait for end of
transmission */
SPIDR = s[0] ^ Polarity ; /* Send leftmost digit with proper
polarity */
}
The pattern is sent to the display device after performing an exclusive
or with the variable Polarity
that is alternately 0 or 0xff,
to provide the display with an
AC drive voltage, as said
above.
This function is called three times for each display refresh, with the
a pointer to another array each
time. This is done in the
following function:
void RefreshAllDisplays ( void )
{
RefreshOneDisplay ( BoatSpeedDisplay ) ; /* First bit string for
farthest display (3) */
RefreshOneDisplay ( WindAngleDisplay ) ;
RefreshOneDisplay ( WindSpeedDisplay ) ;
/* Toggle polarity */
if ( Polarity == 0 )
Polarity = 0xff ;
else
Polarity=0;
}