In avr microcontroller, when using interrupt service routine ,you write the function :



To use this function you must include < avr/interrupt.h>. so now , i don't want to use the interrupt.h file because i am trying to write my driver. how to use interrupt service routine without interrupt.h file?


closed as unclear what you're asking by Scott Seidman, Daniel Grillo, Autistic, pipe, Bence Kaulics Oct 11 '16 at 9:55

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 3
    \$\begingroup\$ Maybe I'm misinterpreting the word "driver," but why would writing your own driver cause you to not want to include the manufacturer provided interface to interrupts? \$\endgroup\$ – Cort Ammon Oct 6 '16 at 22:35
  • 2
    \$\begingroup\$ Why don't you open the interrupt.h file and see what it's doing? \$\endgroup\$ – DoxyLover Oct 6 '16 at 22:35
  • \$\begingroup\$ @CortAmmon yes i want to use my own functions \$\endgroup\$ – Ahmed Yasen Oct 6 '16 at 22:38
  • \$\begingroup\$ @DoxyLover it is not understandable :) \$\endgroup\$ – Ahmed Yasen Oct 6 '16 at 22:39
  • 3
    \$\begingroup\$ "I don't want to use the interrupt.h file because I am trying to write my own driver" is a non sequitur. Unclear why you're asking, or what. \$\endgroup\$ – user207421 Oct 7 '16 at 1:15

avr/interrupt.h is actually pretty simple as far as interrupt headers go. Looking through it, I don't see anything you wouldn't need to keep in order to make interrupts work. There's very little extraneous fluff. It'd be helpful to take the time to get to where interrupt.h is understandable before you try to write your own replacement for it. I'd say that if you look at the define macros that you need (i.e. don't look at ISR_ALIAS unless you need to alias ISRs). Of those portions you are looking at, I'd say 90-100% of it is essential to handling interrupts. The only thing that might be optional is that you can avoid using variadic macros and __VA_ARGS__ if you are willing to rewrite that code every time rather than using a macro.

Interrupts are very compiler dependent and very processor dependent. You can look in your manual for the processor to find exactly what parts of memory to write to to enable interrupts, and then you can make your driver do that. However, you will have to use all of the flags which interrupt.h puts on your functions to make sure they are compatible with being called as an interrupt (or write your own interrupt handler in assembly).


The way you write interrupt handlers is extremely compiler dependent. If you are trying to write a compiler independent library, you would basically need to have a set of #ifdef directives that try and detect which compiler environment you are in and emit the specific includes and code accordingly, then delegate all the compiler agnostic code to inline functions.

  • \$\begingroup\$ if there is any tutorial for that. if no , what should i study ? \$\endgroup\$ – Ahmed Yasen Oct 6 '16 at 22:49
  • \$\begingroup\$ It will be hard to find tutorials, because the vast majority of people whom tutorials target will want to use interrupt.h rather than write their own. As for what you should study, the first question would be "why do you want to do this?" The path forward for someone who "just wants to prove that they can do it to themselves" is very different from someone who "wants to market an alternate AVR toolchain" \$\endgroup\$ – Cort Ammon Oct 6 '16 at 22:58

Not the answer you're looking for? Browse other questions tagged or ask your own question.