View previous topic :: View next topic |
Author |
Message |
rfjhh
Joined: 31 Mar 2011 Posts: 51 Location: Mexico
|
INT_RB interrupt |
Posted: Fri Apr 15, 2011 11:25 am |
|
|
What can I do to make the program leave the interrupt routine, because
once it enters the routine it keeps repeating itself.
Code: |
#include<16f876a.h>
#device ADC=10
#use delay (clock=20MHz)
#use rs232(baud=9600,xmit=PIN_C6,rcv=PIN_C7)
#use fixed_io(c_outputs = PIN_C2, PIN_C6)
#fuses HS, NOWDT, NOBROWNOUT, NOLVP
int conta = 0;
#int_rb
void rb_isr()
{
printf("Entro a la interrupcion");
conta = 0;
}
void main()
{
set_tris_b(0xf0);
clear_interrupt(int_rb);
enable_interrupts(INT_RB);
enable_interrupts(GLOBAL);
for(;;)
{
while(conta == 0)
{
printf("\r\nEsperando entrar a la subrutina......");
conta++;
}
}
} |
|
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9243 Location: Greensville,Ontario
|
|
Posted: Fri Apr 15, 2011 1:24 pm |
|
|
some ideas...
1) add 'errors' to the #use RS232(...) function
2) get rid of fast_io() and set_tris() functions. These are best left for experts to use, novices can waste a LOT of time by misusing these functions. Let the compiler do it all for you, automatically, no thinking required!
3) be sure pullups are on all of the PORTB pins.
4) Read how INT_RB works in the compiler onscreen help file and the datasheet.ANY transition will trigger the ISR (fe,te,any pin)
5) be sure to disable any onchip perherial that is muxed onto the PORTB pins... |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Apr 15, 2011 1:28 pm |
|
|
The reason the interrupt is stuck and repeating forever, is because you
need to clear the "mismatch condition" in the INT_RB circuit inside the
PIC. This is fully described in the PIC data sheet. You can clear the
mismatch condition by reading PortB, or just read the one pin.
Do this with the input() function, inside the interrupt routine. |
|
|
rfjhh
Joined: 31 Mar 2011 Posts: 51 Location: Mexico
|
Thanks |
Posted: Sun Apr 17, 2011 7:48 pm |
|
|
I've already readed the portb and the mismatch condition has been cleared. Thanks |
|
|
|