interrupt please please please help!

Discussion in 'Embedded Systems and Microcontrollers' started by tuanvoi, Apr 4, 2009.

  1. tuanvoi

    Thread Starter Active Member

    Oct 31, 2008
    56
    0
    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.
     
  2. t_n_k

    AAC Fanatic!

    Mar 6, 2009
    5,448
    782
    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.
     
  3. cubi

    New Member

    Mar 27, 2009
    8
    0
    Code ( (Unknown Language)):
    1.  
    2. #include <p18f4550.h>
    3. #include <usart.h>
    4. #include <delays.h>
    5. #include <portb.h>
    6. void LED1(void)
    7. {
    8. PORTDbits.RD1 = 1;
    9. }
    10.  
    11. void main (void)
    12. {
    13. ADCON0bits.ADON=0;
    14. ADCON1 = 0x07;
    15. CMCON = 0x07;
    16. TRISA = 0x00;
    17. TRISD = 0x00;
    18. //INTCON: INTERRUPT CONTROL REGISTER
    19. TRISB = 0xFF;
    20. INTCONbits.GIEH = 0; //clear interrupt
    21. INTCONbits.GIEH = 1; //enable interrupt
    22. INTCONbits.INT0IE = 0;
    23. INTCONbits.INT0IE = 1; //an external interrupt will occur when there is a change state in PORTB pin0
    24. INTCONbits.RBIE = 0;
    25. INTCONbits.RBIE = 1; //enables the RB port change interrupt
    26. RCONbits.IPEN = 1; //enable high priority levels on interrupts
    27.  
    28. switch(INTCONbits.INT0IF)
    29. {
    30.  case 0:
    31.  LED1();
    32.  break;
    33.  case 1:
    34.  PORTDbits.RD0 = 1;
    35.  Delay10KTCYx(100);
    36.  PORTDbits.RD0 = 0;
    37.  Delay10KTCYx(100);
    38.  INTCONbits.INT0IF = 0;
    39.  break;  
    40.  
    41. }
    42.  
    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
     
Loading...