Hello
I have a program that does this: I have 2 buttons and 2 LEDs.
When I push the first button, first LED lights for 5 seconds. If I push the second button while the first led is lighting, first LED stops lighting and the second LED starts lighting for 5 seconds.
I did this with interrupts.
My problem is: when one of the buttons is kept pushed for more then 0,3 seconds, I want the LED to light until the button is released. (not 5 seconds).
Here is the program. (It does the first part I described above: first LED lights for 5 seconds and if a button is pressed, it stops lighting first led and starts lighting the second one).
Thank you.
Code:
#include <16f84A.h>
#use delay(clock=4000000)
long bec0=1;
long bec1=1;
#int_rtcc
void clock_isr() {
bec0--;
bec1--;
if(bec0<1) bec0=1;
if(bec1<1) bec1=1;
if(bec0>1)
output_high(pin_b0);
else
output_low(pin_b0);
if(bec1>1)
output_high(pin_b1);
else
output_low(pin_b1);
}
void main()
{
set_rtcc(0);
setup_counters (RTCC_INTERNAL, RTCC_DIV_1);
enable_interrupts (INT_RTCC);
enable_interrupts(GLOBAL);
do {
if(input_state(PIN_a0)==0)
{
bec0=19530; //3906*5 seconds
bec1=1;
}
if(input_state(PIN_a1)==0)
{
bec1=19530; //3906*5 seconds
bec0=1;
}
} while(1);
}
I have a program that does this: I have 2 buttons and 2 LEDs.
When I push the first button, first LED lights for 5 seconds. If I push the second button while the first led is lighting, first LED stops lighting and the second LED starts lighting for 5 seconds.
I did this with interrupts.
My problem is: when one of the buttons is kept pushed for more then 0,3 seconds, I want the LED to light until the button is released. (not 5 seconds).
Here is the program. (It does the first part I described above: first LED lights for 5 seconds and if a button is pressed, it stops lighting first led and starts lighting the second one).
Thank you.
Code:
#include <16f84A.h>
#use delay(clock=4000000)
long bec0=1;
long bec1=1;
#int_rtcc
void clock_isr() {
bec0--;
bec1--;
if(bec0<1) bec0=1;
if(bec1<1) bec1=1;
if(bec0>1)
output_high(pin_b0);
else
output_low(pin_b0);
if(bec1>1)
output_high(pin_b1);
else
output_low(pin_b1);
}
void main()
{
set_rtcc(0);
setup_counters (RTCC_INTERNAL, RTCC_DIV_1);
enable_interrupts (INT_RTCC);
enable_interrupts(GLOBAL);
do {
if(input_state(PIN_a0)==0)
{
bec0=19530; //3906*5 seconds
bec1=1;
}
if(input_state(PIN_a1)==0)
{
bec1=19530; //3906*5 seconds
bec0=1;
}
} while(1);
}