View previous topic :: View next topic |
Author |
Message |
scuba
Joined: 13 Sep 2011 Posts: 13
|
Tactile Button PIC18F46K22 |
Posted: Mon Oct 10, 2011 4:18 pm |
|
|
Hi there,
I have a PIC18F46K22 and i want to activate the interrupts by pressing a tactile button. The problem that is the interrupt doesn't work and i don't know how to solve it.
Code: |
#FUSES NOPLLEN,NOWDT, NOLVP, HS
int current=0;
#INT_RB
void rb_isr() {
//current=input_b();
current=input(PIN_B4);
fputs("Bottom", hostPC);
if(!current){
output_high(PIN_A0);
fputs("Button", hostPC);
output_high(PIN_A1);
}
delay_ms(1000);
}
void main(){
enable_interrupts(INT_RB);
enable_interrupts(GLOBAL);
}
|
Thank you! |
|
|
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
Posted: Mon Oct 10, 2011 4:28 pm |
|
|
Just for starters
DO NOT DO any serial transmission within the int handler.
Set a variable or use the state of the pin YOU changed
to signal the MAIN() as to what you want to send to the host.
If your pic interrupts on both state changes hi/lo -- lo/hi.
THEN TEST which STATE YOU ARE IN AND SAY ONLY FLAG
the release and act accordingly. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
Posted: Mon Oct 10, 2011 5:16 pm |
|
|
ALSO
that 1 second delay in the ISR is the KISS of DEATH
to anything else you might put in MAIN()
the rule of ALL good INT handlers is:
GET in and out FAST
no delays
no serial comm |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19505
|
|
Posted: Tue Oct 11, 2011 1:51 am |
|
|
Also, the other glaring thing, is that the chip will have gone to sleep. Potentially should wake up, but no guarantees.
You need to have something at the end of main, to stop the code dropping off the end.
Best Wishes |
|
|
scuba
Joined: 13 Sep 2011 Posts: 13
|
|
Posted: Tue Oct 11, 2011 7:46 pm |
|
|
following your suggestions i programmed this code but the button doesn't work too. Is that the problem may be hardware or still bug?
Thank you all.
Code: | #FUSES NOPLLEN,NOWDT, NOLVP, HS
#INT_RB
void rb_isr() {
fputs("Hi", hostPC);
output_high(PIN_A0);
output_high(PIN_A1);
}
void main(){
enable_interrupts(INT_RB);
enable_interrupts(GLOBAL);
} |
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
ezflyr
Joined: 25 Oct 2010 Posts: 1019 Location: Tewksbury, MA
|
|
Posted: Tue Oct 11, 2011 9:04 pm |
|
|
Hi,
Actually, you haven't implemented a single suggestion from the respondents to your query!
As asmboy said, no serial ops inside the ISR. This means get rid of the puts statement.
As pcm programmer said, your version of the compiler might have a bug, and you might need to manually configure the chip. Where is that code?
As Ttelmah said, you need to insert some code at the bottom of main to keep the code from reaching the default 'sleep' instruction put in by the compiler. A 'while(1){}' works nicely!
Other than that, you got everything ;-)!
I'd take a step back a bit and try a much simpler task like blinking an LED. Can you do that? Once that is done, you can use the LED for diagnostics in place of the serial ops in your ISR.
John |
|
|
scuba
Joined: 13 Sep 2011 Posts: 13
|
|
Posted: Wed Oct 12, 2011 1:01 pm |
|
|
Problem Solved!
Thank you PCM Programmer, you're right. |
|
|
|