interrupt please please please help!

Thread Starter

tuanvoi

Joined Oct 31, 2008
56
hi all,
I want to set up an external interrupt on PORTB pin0 (when PORTB pin0 is high) of my PIC18F4550 and an internal interrupt on USART of Rx.
In my external interrupt:
-I will use USART to transmit some bytes to the receiver, and expect to receive some data sent back from the receiver.
Is there any way that I can jump to the internal interrupt USART Rx while the external interrupt of PORTB pin0 is still high even it is done with it interrupt subroutine?
I've tried to clear the external interrupt flag bit (when I'm done with the subroutine while PORTB pin0 is still high), but still it continues to loop back the subroutine (not return to routine).
Could you please help me? Thank you.
 

t_n_k

Joined Mar 6, 2009
5,455
The data sheet shows that RB0/INT0 generates an interrupt on a rising or falling edge - depending on INTEDGx bit condition. So just having a high state on RB0 shouldn't force another INT0 interrupt service (after clearing the external flag) unless there has been another low-high or high-low transition. Something must be changing on that pin.

Also RB0 is a high priority only interrupt - if you have set priority conditions true. Substituting INT1 or INT2 for INT0 can allow those to be assigned as low priority if you wish- but I'm not sure that's any use to you.
 

cubi

Joined Mar 27, 2009
8
Rich (BB code):
#include <p18f4550.h>
#include <usart.h>
#include <delays.h>
#include <portb.h>
void LED1(void)
{
PORTDbits.RD1 = 1;
}
 
void main (void)
{
ADCON0bits.ADON=0;
ADCON1 = 0x07;
CMCON = 0x07;
TRISA = 0x00;
TRISD = 0x00;
//INTCON: INTERRUPT CONTROL REGISTER
TRISB = 0xFF;
INTCONbits.GIEH = 0; //clear interrupt
INTCONbits.GIEH = 1; //enable interrupt
INTCONbits.INT0IE = 0;
INTCONbits.INT0IE = 1; //an external interrupt will occur when there is a change state in PORTB pin0
INTCONbits.RBIE = 0;
INTCONbits.RBIE = 1; //enables the RB port change interrupt
RCONbits.IPEN = 1; //enable high priority levels on interrupts
 
switch(INTCONbits.INT0IF)
{
 case 0:
 LED1();
 break;
 case 1:
 PORTDbits.RD0 = 1;
 Delay10KTCYx(100);
 PORTDbits.RD0 = 0;
 Delay10KTCYx(100);
 INTCONbits.INT0IF = 0;
 break;  
 
}
Above is my code, the interrupt will be triggered when PORTB pin0 is high.
Could you please check my configurations for this interrupt?
When "INTCONbits.INT0IF = 1" the interrupt subroutine case 1 will run. After it is done, as you see I clear INTCONbits.INT0IF = 0. Could you please confirm that if the interrupt flag is clear while the PORTB pin0 is still high. Will the interrupt subroutine still run "case 1" or return to subroutine?
Thank you
Tom
 
Top