283/317
9 - A Carrier-current System for domestIc Remote Control
case STOP_CLOSE:
StopMotor () ;
break ;
case START_OPEN:
COILS = OPEN ;
WaitDelay ( COIL_PULSE ) ;
COILS = START ;
WaitDelay ( COIL_PULSE ) ;
WaitDelay ( 5 * TENTH_SECOND ) ;
break ;
case START_CLOSE:
COILS = CLOSE ;
WaitDelay ( COIL_PULSE ) ;
COILS = START ;
WaitDelay ( COIL_PULSE ) ;
WaitDelay ( 5 * TENTH_SECOND ) ;
break ;
}
}
When the message means “stop”, the function
StopMotor
above is called. Otherwise, the ap-
propriate coil is energized, then the timer is started for 5 ms, then an additional delay is in-
cluded. This delay guarantees that the cycle could not be repeated to fast, to avoid having the
power supply voltage fall dangerously. T his also allows the motor to start, and the motor
stopped detector to work properly.
Main function.
Now we can lo ok at th e ma in pro gra m. It is ma de of a f ew lin es, be cau se mo st of the
processing is done in functions called from it. This both saves the code size and improves the
clarity of the code for later modification.
After initializing, the program enters an endless loop. Each time a remote command is re-
ceived that requests either to open or close the blind, the motor is started in the appropriate di-
rection. Then, if the button is pressed, the current state is changed for the next start in this
cycle: open, stop, close, stop, open...
Eventually, if the state is
START_OPEN
or
START_CLOSE
, and if the motor is found stopped, this
means that the motion is complete and that the end-of-stroke switch has been actuated. The
state is then changed to the corresponding
STOP_
state, so that the system is ready to start in
the opposite direction the next time the button is pressed.
The main program is the following:
void main ( void )
{
Содержание 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 ...