I'm a newbie to this site, so please excuse me if I'm posting in the wrong forum section, or if my question is too elementary. I've just recently started using MPLab to program a PIC16F819 I'm trying to write a code in which a single LED is switch on if 2 certain switches are pressed within 2 seconds of each other. I've started a basic code in which I have 4 inputs (switches) and four outputs (LED's) at the moment each switch corresponds to a single LED so if I was to press switch1 then LED1 lights up.
How would I code the PIC so that LED1 would light up if I was to press switch1 and then switch2 (within 2 seconds of each other)?
Thanks in advance.
Current code:
#include <16F819.h>
#fuses INTRC_IO,NOWDT,NOPROTECT,MCLR,NOBROWNOUT
#use delay(clock=4000000)
#define SW2 PIN_B7
#define SW2 PIN_B6
#define SW3 PIN_B5
#define SW4 PIN_B4
#define LED1 PIN_B3
#define LED2 PIN_B2
#define LED3 PIN_B1
#define LED4 PIN_B0
void main()
{
port_b_pullups(TRUE);
while(1)
{
if(!input(SW1)) output_high(LED1);
if(!input(SW2)) output_high(LED2);
if(!input(SW3)) output_high(LED3);
if(!input(SW4)) output_high(LED4);
}
}
How would I code the PIC so that LED1 would light up if I was to press switch1 and then switch2 (within 2 seconds of each other)?
Thanks in advance.
Current code:
#include <16F819.h>
#fuses INTRC_IO,NOWDT,NOPROTECT,MCLR,NOBROWNOUT
#use delay(clock=4000000)
#define SW2 PIN_B7
#define SW2 PIN_B6
#define SW3 PIN_B5
#define SW4 PIN_B4
#define LED1 PIN_B3
#define LED2 PIN_B2
#define LED3 PIN_B1
#define LED4 PIN_B0
void main()
{
port_b_pullups(TRUE);
while(1)
{
if(!input(SW1)) output_high(LED1);
if(!input(SW2)) output_high(LED2);
if(!input(SW3)) output_high(LED3);
if(!input(SW4)) output_high(LED4);
}
}