Tips and tricks (4)

Previous T&T

Once again, the tips deals with… interrupts 😉

I was in the process of developping a new version of my rotary encoder libray for which I wanted to be able to set pins and ports. I quickly faced the question of the ISR. Should I write three identical routines ? (blah!). Should I write an external routine called by the three ISRs ? (Not better).

The answer is: ISR_ALIASOF!

All you have to do is to write an Interrupt Service Request routine like this one

ISR(PCINT0_vect) {
  // Put your stuff here
}

And add the next two lines of code

// Use PCINT0_vect for PCINT1_vect and PCINT2_vect
ISR(PCINT1_vect, ISR_ALIASOF(PCINT0_vect));
ISR(PCINT2_vect, ISR_ALIASOF(PCINT0_vect));

PCINT1_vect and PCINT2_vect will be ‘trampolined” to PCINT0_vect !

End of game!

Read more about interrupts here

Next T&T

Leave a Reply

You must be logged in to post a comment.