259/317
9 - A Carrier-current System for domestIc Remote Control
So the repetition period will remain within the correct value. The variation of the timer period is
constrained within narrow bounds, so that large frequency deviations are not possible. This
prevents surges or stray pulses on the line from erroneously changing the position of the 120
kHz pulses relative to the actual zero crossing of the power line.
Timer B is set to PW M mode so that it overflows 64 times per second. It triggers an interrupt
request.
9.2.3 Description of the software
The software is divided into a main program and three interrupt service routines.
The main program checks for the control buttons and defines the command sequences to be
sent. It runs continuously.
The first interrupt service routine is run after each pulse has been sent. Once every three
tim es (that is once for each half cycle), it determ ines whether a pulse should be sent, ac-
cording to the X-10 standard and to the message to send, and sets the OLVL1 bit accordingly.
The second interrupt service routine is run once at each line zero crossing. It synchronizes the
timer.
The third interrupt service routine is run each time Timer B overflows. This occurs 64 times per
second. The service routine does two things:
It refreshes the display that is multiplexed and that must be switched fast enough to appear as
steady.
It counts down the time, providing the necessary time base for the delay displayed.
The software has been entirely written in C, except for a few lines in assembler; the need for
them is explained below. This shows that it is easy to write (and even more to later read) an
application in C even when the task looks simple and apparently does not require much pro-
gramming.
We shall study these pieces of software in detail here.
9.2.3.1 The main program
The main program includes the initialization code and an endless loop that processes the
pushbuttons.
The initialization code sets the ports, the timers and all the required registers.
The endless loop reads the buttons, waits for them to be stable for a sufficient duration (de-
bouncing), and takes the appropriate action depending on the button that is pressed:
For buttons OPEN and CLOSE, the function
SendCommand
is called. It sets global variables to
signal to the interrupt service routine that a message is to be transmitted:
Содержание 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 ...