rising edge trigger how to set up

Discussion in 'Embedded Systems and Microcontrollers' started by tuanvoi, Mar 28, 2009.

  1. tuanvoi

    Thread Starter Active Member

    Oct 31, 2008
    56
    0
    Hello,
    Below is my code, PIC18F4550
    Code ( (Unknown Language)):
    1.  
    2. #include <p18f4550.h>
    3. #include <usart.h>
    4. #include <delays.h>
    5.  
    6. void LED1(void)
    7. {
    8. PORTDbits.RD0 = 0;
    9. }
    10.  
    11. void main (void)
    12. {
    13. ADCON0bits.ADON=0;
    14. ADCON1 = 0x07;
    15. CMCON = 0x07;
    16. //TRISA = 0x00;
    17. TRISD = 0x00;
    18. //PORTDbits.RD0 = 0;
    19. //INTCON: INTERRUPT CONTROL REGISTER
    20. TRISB = 0xFF;
    21. INTCONbits.GIEH = 0; //clear interrupt
    22. INTCONbits.GIEH = 1; //enable interrupt
    23. INTCONbits.INT0IE = 1; //an external interrupt will occur when there is a change state in PORTB pins
    24. //INTCONbits.RBIE = 0;
    25. INTCONbits.RBIE = 1; //enables the RB port change interrupt
    26. INTCONbits.INT0IF == 0;
    27. INTCON2bits.INTEDG0 = 1; //interrupt will be triggered when on rising edge
    28. //INTCONbits.INT0IF = 1;//enable interrupt on RB0
    29.  
    30. if(INTCONbits.INT0IF == 1)
    31. //if(INTCONbits.RBIF == 1)
    32. {
    33.  //INTCONbits.RBIF == 0; //interrupts for INTCON <7:4>
    34.  
    35.  PORTDbits.RD0 = 1;
    36.  Delay10KTCYx(100);
    37.  PORTDbits.RD0 = 0;
    38.  Delay10KTCYx(100);
    39.  INTCONbits.INT0IF = 0;
    40.  
    41. }
    42. else if (INTCONbits.INT0IF = 0)
    43. {
    44.  
    45.  LED1();
    46. }
    47.  
    48. }//end of main
    49.  
    Could you please check if my interrupt setup is correct? Thanks
    By the way, how do you jump back to the subroutine that the PIC was running in C program?
    Tom
     
  2. thatoneguy

    AAC Fanatic!

    Feb 19, 2009
    6,357
    718
    Does it run in simulation?

    Do you have an ICE or ICD? (In Circuit Emulator or In Circuit Debugger)

    For PIC, it would be an ICExxxx unit, or for debuggers the ICD2 or PicKit 3
     
Loading...