Phonetics 5100 Home Security System User Manual


 
109
Chapter 8: C Programming
PROGRAMMING EXAMPLES
1. This example demonstrates: TIME DELAY and OUTPUT DISABLING
int delay, timer, timergo, relay, temp, rate;
main ()
{
if (temp<seconds)
{
rate=seconds-temp; /* Calculate reload rate */
}
temp=seconds; /* Save seconds for next run of program */
if (timer!=0)
{
timer=timer-rate; /* Update countdown timer */
if (timer<=0)
{
timer=0; /* Don’t count past zero */
}
}
if ((input(3)==1)&&(timergo==0)) /* If input 3 opens and we aren’t already timing it */
{
timer=delay; timergo=1; /* Start timer, set flag */
}
if ((timer==0)&&(timergo==1)) /* If timer reaches zero, and flag is set */
{
relay=1; /* Set relay flag to ON */
}
if (input(3)==0) /* If input closes */
{
timer=0; timergo=0; relay=0; /* Clear timer, flag, and turn relay OFF */
}
if ((input(5)==0)&&(relay!=0)) /* If input 5 (relay disable switch) is closed(not active) */
{ /* and relay accumulator is not zero */
output(10,1); /* Turn relay ON */
}
else
{
output(10,0); /* Turn relay OFF */
}
}
2. This example toggles output 1 on and off, based on the output's previous state.
main ()
{
output(1,(1-output(1,2)));
}
3. This example demonstrates: RESETTING VARIABLES and SINGLE TIME EVENTS
int rset, average, total, recent, prvhrs;
main()
{
if (rset==0) /* Using the ISACC command SET VAR RSET, and setting RSET = 0 */
{ /* causes these variables to be cleared */
average = 0;
total = 0;
recent = 0;
prvhrs = 0;
rset = 1; /* RSET = 1 prevents variables from being cleared every time */
} /* the program runs */