How to write ISR function for Hardware and software Interrupt

Discussion in 'Embedded Systems and Microcontrollers' started by Allen_Lusy, May 18, 2015.

  1. Allen_Lusy

    Thread Starter New Member

    Dec 10, 2014
    10
    0
    Till now I used Vendor(Controller Vendor) ISR for handling the Interrupt. But I want to know how to write the ISR. I know about the Vector Table. Will take one simple example for GPIO Interrupt for Port 0. which is having the vector table P0INT_VECTOR(according to datasheet).
    1. Now can any one tell me, how to write a ISR function for this.
    I have seen the vendor example,

    #pragmavector= P0INT_VECTOR
    __interrupt void p0_ISR(void)
    {
    /*Some statement*/
    }
    why it is #pragma, and how the function defined as p0_ISR, can we change the function name. What will be the impact of changing the name

    I am not used the Software Interrupt much, but I know some basic, it will be used via INT commands.
    2.How to write Software ISR.
     
  2. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,386
    1,605
    We would need to know what compiler and what device you are using to offer any specific advice.

    "#pragma" is a C statement used when the core C statements can't handle something (so we do something pragmatic). As far as I know the function name itself is of little importance as normally you never call this function from your other code. C just needs a handle that is not used any where else.
     
  3. Allen_Lusy

    Thread Starter New Member

    Dec 10, 2014
    10
    0
    I am using GNU Compiler and 8051 Controller. Can you please bit Clear, as I am not having Much experience in the controller. I will be thankful if you describe it from Basic point of view.
     
  4. Papabravo

    Expert

    Feb 24, 2006
    10,138
    1,789
    In the interrupt service routine
    1. Verify that the interrupt flag gets cleared. In some cases this must be done by an instruction to clear it, sometimes this is automatic.
    2. Re-enable interrupts, if you allow nesting.
    3. Capture data from or output data to the hardware registers.
    4. Return from the interrupt
    Resist the urge to do extensive processing in an interrupt routine.
    Don't allow any variables to be modified in both the interrupt service routine and the background process.
     
  5. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,386
    1,605
    Sorry I am not familiar with the GNU compiler so I have to drop out of the discussion.
     
Loading...