260/317
9 - A Carrier-current System for domestIc Remote Control
/* This function triggers the sending of one command */
void SendCommand ( Byte Command )
{
KeyCode = Codes[Command] ; /* prepare the two variables that */
HouseCode = Codes[HOUSE_CODE] ; /* contain the data to send. */
CycleNumber=1; /*start sending process */
}
The global variables used are also used by the interrupt that sends the pulses.
As said earlier, the codes transmitted do not correspond to their binary equivalent. This is why
the value to transmit is retrieved from a lookup table
Codes[], located in ROM as explained
later.
For the TIME button, the hour counter is incremented if it is less than 15.
The debouncing is done by the following function. It reads the state of the three inputs con-
nected to the buttons, and checks whether the current reading is equal to the previous one. If
this holds true for a certain number of readings, the set of buttons is regarded as stable. Then,
the value of these three bits is tested. If only one button is pressed, the value of that button is
returned. If no buttons, or more than one button are pressed, the value zero is returned.
/* This function waits until the state of the buttons is stable, and */
/* returns the code of the button pressed. If several, returns 0. */
Byte Debounce ( void )
{
Byte PreviousButton = PUSH_BUTTONS ;
int DebounceTime = DEBOUNCE_TIME ;
/* Wait for state stable */
while ( DebounceTime != 0 )
{
if ( PreviousButton != PUSH_BUTTONS )
{
DebounceTime = DEBOUNCE_TIME ; /* state changed : restart
delay */
PreviousButton = PUSH_BUTTONS ;
}
else
DebounceTime-- ;
}
switch ( PreviousButton )
{
case CLOSE_BUTTON :
case OPEN_BUTTON :
case TIME_BUTTON :
return PreviousButton ;
default: