EasyManua.ls Logo

ST ST7 - Page 261

ST ST7
317 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
261/317
9 - A Carrier-current System for domestIc Remote Control
return 0 ; /* No button pressed or more than one button
pressed. */
}
}
Please note the use of the macro PUSH_BUTTONS in the text. This macro is defined as follows:
#define PUSH_BUTTONS ( ( ~PBDR ) & 0xE0 ) /* upper three bits */
#define CLOSE_BUTTON 0x80
#define OPEN_BUTTON 0x40
#define TIME_BUTTON 0x20
This expression complements the bits read from port B, for they read as zero when the button
is activated; and only the three bits corresponding to the buttons are returned. Using such a
definition at the beginning of the source text allows you to easily rewire the electronic circuit so
that the buttons can be connected to another input, in a different order, or set the level to high
when active: only these four lines have to be changed, which is easier than having to scan the
source text to find where and how the push buttons are read.
The main program is the following:
void main ( void )
{
InitPorts () ;
InitTimerA() ;
InitTimerB() ;
MISCR = 0x00 ; /* Normal mode (clock/2). */
EnableInterrupts ;
while (1)
{
switch ( Debounce () )
{
case CLOSE_BUTTON :
Delay=0; /*Cancel wait. */
SendCommand ( CLOSE_COMMAND ) ;
break ;
case OPEN_BUTTON :
Delay=0; /*Cancel wait. */
SendCommand ( OPEN_COMMAND ) ;
break ;
case TIME_BUTTON :
Hour = 3600 ; /* To make the first hour accurate. */
if ( Delay < 15 )
Delay++ ;
break ;
}

Table of Contents

Related product manuals