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 ;
}
Содержание 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 ...