+ Post New Thread
Results 1 to 14 of 14
  1. #1
    Newbie level 5
    Points: 637, Level: 5

    Join Date
    Aug 2009
    Location
    gaza strip
    Posts
    8
    Helped
    0 / 0
    Points
    637
    Level
    5

    interrupts in c

    in pic 16f877 there is 14 source of interrupts
    can u tell me if you have two interrupts(low and high) in any program (write in C language)
    how i can call interrupts?

    in first we write : void interrupt()
    but in second??????
    ((interrupts in C language high level))

    •   AltAdvertisement

        
       

  2. #2
    Advanced Member level 5
    Points: 16,636, Level: 31

    Join Date
    Jul 2001
    Location
    Oberon
    Posts
    1,897
    Helped
    442 / 442
    Points
    16,636
    Level
    31

    interrupts on pic18 c language

    The Pic 16 family does not support interrupt priority, all interrupts have the same priority and there is only one interrupt vector.
    The normal procedure is to test each flag of the interrupts you have enabled and service the ones that are set.
    For Example:
    Code:
    /*--- Interrupt vector ---*/
    
    static void interrupt isr(void)
      {
      if(T0IF)
        {
        Timer 0 interrupt;
        }
    
      if(TMR1IF)
        {
        Timer 1 interrupt;
        }
      if(CCP2IF)
        {
        Capture interrupt;
        }
      }



  3. #3
    Full Member level 2
    Points: 4,835, Level: 16
    arthur0's Avatar
    Join Date
    Nov 2003
    Location
    Stockholm, Sweden
    Posts
    131
    Helped
    53 / 49
    Points
    4,835
    Level
    16

    interrupt in pic c c language

    Hi,
    I’ll try write a more general explanation below (I won’t relate to PIC or any specific C/P), in the hope that more can read and understand the concepts.

    You never "call interrupts" yourself, in a program. An interrupt not function, but an event (usually external to your program, but it can also be a software generated) that interrupts the normal flow of execution, hence the name.
    When detecting such an event, the "hardware" is built such that it will stop executing your program and select to jump and execute from a predetermined address (specific to each C/P and source).
    Your job is to write small routines to serve these interruptions, and locate them at the right addresses.

    Take Reset for instance that is an event defined on all the C/P I know of. When Reset happens (due to RESET signal kept low and then released, or elapsed watchdog timer, or low voltage detector, or whatever reason), the CPU will start executing from a specific address. When you write your program (in C) and specify main(), the compiler will locate it at the right address for your specific CPU so that it will be executed after every Reset event.

    It is more or less the same with any other interrupt source (timer, ADC, UART etc.), but since there are multiple sources, you need to let the compiler know where to place your little Interrupt Service Routines (ISR) and you do that with specific pragmas and/or compiler-specific keywords.
    It might be that all the interrupting events will use the same address to execute from. In such a case you’ll need to read specific flags and determine the source and do things accordingly, but the principle is the same.

    Interrupt priorities are a totally different matter and it’s just a way the hardware chooses to handle cases when more than one interrupting event is active.
    For instance, it might be that a timer has finished counting exactly when the ADC has finished converting, but since (we say that) the timer interrupt event has higher priority, the hardware will choose to jump and execute its ISR first and then the ADC’s.

    Now I simplified my explanation a bit, because things are a tad more complicated than this, but for serving an interrupt in C that’s about all there is to know (plus, of course, read the funky manual!).

    This is the kind of topic many have a problem with, but if you understand the simple concepts above (plus some other stingy issues that you might never encounter if you keep things simple), there’s really no reason to avoid using interrupts in your designs (on the contrary, there are great advantages).
    Maybe someone else can help with the details of PIC, which are foreign to me.

    Arthur


    2 members found this post helpful.

  4. #4
    Newbie level 5
    Points: 637, Level: 5

    Join Date
    Aug 2009
    Location
    gaza strip
    Posts
    8
    Helped
    0 / 0
    Points
    637
    Level
    5

    c language code

    i mean if you have two interrupts(ISR) in 1 program

    how you can call the 2 interrupts in C language???



    •   AltAdvertisement

        
       

  5. #5
    Advanced Member level 5
    Points: 16,636, Level: 31

    Join Date
    Jul 2001
    Location
    Oberon
    Posts
    1,897
    Helped
    442 / 442
    Points
    16,636
    Level
    31

    interrupts in c

    You dont normally call interrupts, But
    the interrupt flags in the Pic are read/write, so if you want the interrupt to fire, you can just set the interrupt flag. any time you like.
    IE:
    T0IF = 1;
    will fire Timer 0 interrupt.



  6. #6
    Advanced Member level 3
    Points: 5,367, Level: 17

    Join Date
    Jul 2009
    Posts
    734
    Helped
    82 / 87
    Points
    5,367
    Level
    17

    language c interrupt

    Quote Originally Posted by AhmedS
    i mean if you have two interrupts(ISR) in 1 program

    how you can call the 2 interrupts in C language???
    btbass answered your question directly and clearly.

    which part of btbass's answer do you have trouble understanding?



    •   AltAdvertisement

        
       

  7. #7
    Newbie level 5
    Points: 637, Level: 5

    Join Date
    Aug 2009
    Location
    gaza strip
    Posts
    8
    Helped
    0 / 0
    Points
    637
    Level
    5

    interrupt in c language

    in any program that have 1 interrupt,we write:

    void interrupt()
    {
    ----------
    }

    void main()
    {
    ------
    }


    but if u have 2 interrupts ,how you can call it in program????



  8. #8
    Advanced Member level 3
    Points: 5,367, Level: 17

    Join Date
    Jul 2009
    Posts
    734
    Helped
    82 / 87
    Points
    5,367
    Level
    17

    interrupt service routine timer 2 c

    but if u have 2 interrupts ,how you can call it in program????
    I think you should talk to your career counselor to see if you can find a living in a profession other than programming, preferably a profession that's much simpler and doesn't require much thinking and logic at all.



  9. #9
    Super Moderator
    Points: 81,430, Level: 69
    Achievements:
    7 years registered
    Awards:
    2nd Helpful Member
    betwixt's Avatar
    Join Date
    Jul 2009
    Location
    Aberdyfi, West Wales, UK
    Posts
    13,348
    Helped
    4456 / 4456
    Points
    81,430
    Level
    69

    pic18 multiple interrupt c language

    AhmedS, despite the last comment, I will try to explain:

    Interrupts are not called. They are triggered by an event happening in hardware.

    I think what you are asking is "If I have more than one source of interrupts, how do I deal with them?"

    The answer is that all interrupts in the 16F processors make the program call just one address, the interrupt vector. You write code in your interrupt routines that looks at each of the interrupt flags to see which is set. You then have to service whatever interrupt was found and also clear the interrupt flag before returning.

    It is possible that more than one interrupt occurs simultaneously or that one occurs while another is being serviced. This does not matter because when you return to your main code the global interrupt will be turned on again (GIE bit) and the the other interrupt will immediately call for attention.

    If you want to prioritize the interrupts, simply check the flags in the order needed so the highest priority is found first.

    Brian.



  10. #10
    Super Moderator
    Points: 260,228, Level: 100
    Awards:
    1st Helpful Member

    Join Date
    Jan 2008
    Location
    Bochum, Germany
    Posts
    45,443
    Helped
    13827 / 13827
    Points
    260,228
    Level
    100

    interrupt pic c language

    It should be mentioned, that the code between the processor's hardware interrupt vector and the user accessible C interrupt function is strongly implementation dependant, and also handled different with different PIC16 compilers. Thus it doesn't make much sense to dicuss it without telling a particular compiler product.


    1 members found this post helpful.

  11. #11
    Full Member level 2
    Points: 4,835, Level: 16
    arthur0's Avatar
    Join Date
    Nov 2003
    Location
    Stockholm, Sweden
    Posts
    131
    Helped
    53 / 49
    Points
    4,835
    Level
    16

    calling interrupt in c

    Ah, what a waste...
    but if u have 2 interrupts ,how you can call it in program????
    I think (hope) you meant to ask "how would I name the second ISR...?"
    If that's the case, the answer is that you can choose whatever name you please for your ISRs as long as you include the proper keyword that lets the compiler know it is an ISR.
    From btbass' concise answer I gather that that keyword is interrupt. The name of the ISR in his example is isr.
    If you had more interrupt vectors, you would've needed to specify the vector as well (different on different compilers), but the actual ISR name you choose at your discretion (say my_service_routine).
    Does this clarify the matter?

    Arthur


    1 members found this post helpful.

  12. #12
    Newbie level 6
    Points: 637, Level: 5

    Join Date
    Oct 2009
    Location
    punjab
    Posts
    11
    Helped
    0 / 0
    Points
    637
    Level
    5

    Re: interrupts in C language code

    can anyone please post an example of c code using interrupts...?
    any example with microcontroller
    thanks



  13. #13
    Junior Member level 2
    Points: 661, Level: 5

    Join Date
    Oct 2009
    Location
    Belgium
    Posts
    22
    Helped
    3 / 3
    Points
    661
    Level
    5

    Re: interrupts in C language code

    Hi Guys

    Check out this tutorial! It explains how to build a light tracking robot and uses interupts to do so.

    http://www.dwengo.org/tutorials/light-tracker

    Slorn



    •   AltAdvertisement

        
       

  14. #14
    Newbie level 1
    Points: 437, Level: 4

    Join Date
    Jun 2010
    Location
    South Africa
    Posts
    1
    Helped
    0 / 0
    Points
    437
    Level
    4

    Re: interrupts in C language code

    Hi guys,
    I am a novice to programming in general but am interested in programming PIC's in particular. I understand how interrupts work but the location of where to initialise the interupt registers to enable the interrupts is unknown to me... Do you initialise it inside the main program, before or after? All code i have found gives parts of code but not the whole code. Any help would be greatly appreciated.

    Thanks Gary



--[[ ]]--