View previous topic :: View next topic |
Author |
Message |
wwwglro
Joined: 03 Sep 2009 Posts: 17
|
|
Posted: Sun Sep 13, 2009 2:42 am |
|
|
Hello.
That code works but in a single click event the corresponding led lights for indefinite time.
When I try to modify to light for a few seconds (using delay_ms()), when I push another button, it doesn't do anything (until the delay is finished).
So is there a way to interrupt the delay_ms() function when I press another button?
Thank you. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Sep 13, 2009 2:59 pm |
|
|
Post your code that uses Mark's driver.
(Don't post Mark's driver. I already know where it is). |
|
|
wwwglro
Joined: 03 Sep 2009 Posts: 17
|
|
Posted: Wed Sep 16, 2009 6:59 am |
|
|
Hello.
My code actually, doesn't use Mark's code; it's like Mark's code (much simpler).
When I push a button, a led lights for 3 seconds.
When I push other button, another led starts to light (and the first stops lighting).
When I hold down the button, the led should light until the button is released.
My problem is that my code doesn't do that. When I release the button, the led stops lighting after three seconds not immediately.
I try to modify Mark's code for doing that, but when I insert a delay routine for led to light three seconds, in a single click event, when I push another button, the corresponding led doesn't start to light until the first one has stopped.
That's why I asked if is there a way to stop delay routine when the button is held down.
Thank you. |
|
|
wwwglro
Joined: 03 Sep 2009 Posts: 17
|
|
Posted: Sun Sep 20, 2009 8:57 am |
|
|
Here is the code:
Code: |
#include <16f84A.h>
#use delay(clock=4000000) //we have 3906 interupts per seconde
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(PIN_a0)==0) //the button 1
{
bec0=19530; //3906*5 seconde
bec1=1;
}
if(input(PIN_a1)==0) //the button 2
{
bec1=19530; //3906*5 seconde
bec0=1;
}
} while(1);
}
|
It doesn't do the held button but only the 5 seconds led blinking when a button is pressed
Thank you. |
|
|
|