+ Post New Thread
Results 1 to 3 of 3
  1. #1
    Member level 4
    Points: 807, Level: 6

    Join Date
    Mar 2016
    Posts
    75
    Helped
    0 / 0
    Points
    807
    Level
    6

    external interrupt on pic18f

    Hello guys
    I am new to pic micro controllers. I have a problem with it. I have written a very simple code to test the external its interrupts. I don't know why it doesn't work. could you please tell me, what I should do?
    this is block design of interrupt scheme of the micro controller:
    Click image for larger version. 

Name:	qweee.JPG 
Views:	2 
Size:	48.9 KB 
ID:	133549

    and this my code:

    Code:
    #include 
    
    #pragma config FOSC = INTOSCIO_EC   //internal ocsillator
    #pragma config WDT = OFF            //turn off WDT
    #pragma config LVP = OFF            //turn off LVP
    #pragma config BOR = ON             //enable brownout reset
    
    
    //----------------------------------------------------------------------------
    
    void main (void);
    void InterruptHandlerHigh (void);
    void delay (void)
    {
        volatile int i;
        for (i=0;i<10000;i++);
    }
    
    //----------------------------------------------------------------------------
    // Main routine
    char flag = 0;
    void
    main ()
    {
        
    INTCONbits.INT0IF = 0;
    INTCONbits.INT0IE = 1;
    INTCON2bits.INTEDG0 = 0;
    ADCON0 = 0xFF;
    INTCON2bits.RBPU = 1;
    
    RCONbits.IPEN = 1;
    INTCONbits.PEIE = 1;
    
    INTCONbits.GIE = 1;
    
    TRISAbits.TRISA0 = 0;
    
    
    TRISBbits.TRISB0 = 1;
    
      while (1)
        {
          if (flag == 1)
          {
            LATAbits.LATA0 = 1;
            delay();
            LATAbits.LATA0 = 0;
            delay();
          }
          else
              LATAbits.LATA0 = 1;
        }
         
    
    }
    
    
    #pragma code InterruptVectorHigh = 0x08
    void
    InterruptVectorHigh (void)
    {
        
      _asm
        goto InterruptHandlerHigh //jump to interrupt routine
      _endasm
    }
    
    //----------------------------------------------------------------------------
    // High priority interrupt routine
    
    #pragma code
    #pragma interrupt InterruptHandlerHigh
    
    void
    InterruptHandlerHigh ()
    {
      if (INTCONbits.INT0F)
        {       
          INTCONbits.INT0F = 0;
          flag = 1;
        }
    }
    thank you.

    •   AltAdvertisment

        
       

  2. #2
    Super Moderator
    Points: 27,493, Level: 40
    andre_teprom's Avatar
    Join Date
    Nov 2006
    Location
    Brazil
    Posts
    8,214
    Helped
    1038 / 1038
    Points
    27,493
    Level
    40
    Blog Entries
    5

    Re: external interrupt on pic18f

    It is not too usual the use of goto instructions in C programming, even worse, in an assembly call. There should have other issues, but at least the flag variable is not being cleared anywhere.
    --------------------------------------------------------------------------------------------------
    Part of the world that you live in, You are the part that you're giving ( Renaissance )



    •   AltAdvertisment

        
       

  3. #3
    Member level 4
    Points: 807, Level: 6

    Join Date
    Mar 2016
    Posts
    75
    Helped
    0 / 0
    Points
    807
    Level
    6

    Re: external interrupt on pic18f

    Quote Originally Posted by andre_teprom View Post
    It is not too usual the use of goto instructions in C programming, even worse, in an assembly call. There should have other issues, but at least the flag variable is not being cleared anywhere.
    thanks for the comment.
    yeah you're right. I usually don't use "goto" in my codes. but it is an example from microchip. and "flag" varible is not being cleared because it is a very simple project and I want to test the external interrupt.



--[[ ]]--