How to Write ISR function for Hardware and Software Interrupt

cmicrocontroller

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, 




 #pragma vector = 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.

  1. How to write Software ISR.

Best Answer

Pragmas are a standardized way of providing 'extra' information to your compiler, however the meaning is not defined outside the context of that particular compiler. So you need to consult the manual for the compiler to find out exactly what is going on. In this case it tells the compiler to populate the interrupt vector table entry 13 (P0INT_VECTOR is a constant defined in a header file) to point to the below routine.

__interrupt is a keyword extension that causes the compiler to emit code to do appropriate context save and restore for an interrupt. Again, see the compiler manual.

p0_ISR is an arbitrary name with no specific meaning to the compiler.

You would write an ISR for a software interrupt the same as any other interrupt, if SWI was supported by the '51 hardware (I don't think it is)- look up the name of the constant for the vector table.

All this stuff is very compiler- and processor-dependent so generalizations are not so useful. If you understand assembly programming for a particular processor you know what information you have to slip to the compiler for it to be able to emit correct code.

If the processor supports SWI, actually invoking a SWI might involve a keyword extension or you might have to dip into inline assembly etc.