Arduino Projects   |   Raspberry Pi   |   Electronic Circuits   |   AVR   |   PIC   |   8051   |   Electronic Projects

HELP NEEDED PIC16F819

2 posts / 0 new
Last post
namams
namams's picture
Offline
Last seen: 5 months 3 weeks ago
Joined: 31/01/2019 - 14:34
HELP NEEDED PIC16F819

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 3 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); 

 

  } 

}

 

Richard
Richard's picture
Offline
Last seen: 5 months 1 week ago
Joined: 11/02/2019 - 13:15
This will involve use of
This will involve use of timer and external interrupts...i appreciate your creativity...but you need to keep this spin off task in pipeline till you are done with timers, interrupts and other basic features of the PIC
Log in or register to post comments