307/317
10 - Second Application: a Sailing Computer
if ( Turn )
{
GetPushButtons() ;
ReadDirection () ;
}
Turn = ! Turn ;
RefreshAllDisplays () ;
}
10.5.6 Computation of the results
The main program takes the raw values and applies to them the formulae given at the begin-
ning of this chapter. For each display, according to the current selection that is shown by either
a green or a red light, either the raw value or the corrected value is converted to a string and
sent to the display.
Since the raw values are produced by an interrupt service routine, it is important to read them
atomically. A function provides for this, by disabling the interrupts for the time the value is
read:
Word Atomic ( Word*p)
{
Word Result ;
DisableInterrupts ;
Result=*p;
EnableInterrupts ;
return Result ;
}
A similar function is also available for long values. Since they are involved in floating calcula-
tions, the function directly returns them converted to float.
float LongToFloatAtomic ( LWord*p)
{
float Result ;
DisableInterrupts ;
Result = (float)(* p) ;
EnableInterrupts ;
return Result ;
}