Pure AVR equivalent of attachInterrupt() ?

I'd like to add a "system halt" button to my mill running GRBL. The button is on D2, hardware interrupt 0. In Arduino-speak I can set it up with attachInterrupt(0...) but for GRBL I need a pure AVR C implementation.

Before I start trying to pull apart the source code in WInterrupts.c etc. I was wondering if anyone's already done this or has a reference to an example.

Thanks in advance.

Processor?

Trigger (CHANGE, RISING, FALLING, LEVEL)?

I apologize. I'm using a Uno with a 328P and would like the trigger to be on RISING.

Thanks!

For INT0 on the 328 processor, we end up at the interrupt service routine on line #276
https://github.com/arduino/Arduino/blob/master/hardware/arduino/cores/arduino/WInterrupts.c#L276

We’ll use the modern macro instead of the deprecated SIGNAL macro…

ISR( INT0_vect ) 
{
  // Your stuff goes here
}

The EICRB register does not exist does we end up with this initialization code on line #95
https://github.com/arduino/Arduino/blob/master/hardware/arduino/cores/arduino/WInterrupts.c#L95

      EICRA = (EICRA & ~((1 << ISC00) | (1 << ISC01))) | (mode << ISC00);
      EIMSK |= (1 << INT0);

RISING is defined as 3…
https://github.com/arduino/Arduino/blob/master/hardware/arduino/cores/arduino/Arduino.h#L40
…so the initialization code becomes this…

      EICRA = (EICRA & ~((1 << ISC00) | (1 << ISC01))) | (3 << ISC00);
      EIMSK |= (1 << INT0);

And, we’re done.

That's great, thanks! I won't be able to test it out until tomorrow evening but I'll let you know how it goes.

Thanks again.

It compiled fine but didn’t function until I added

#include <avr/interrupt.h>

Once I did that it worked as designed.

Thanks again for your help.

Excellent. I'm glad you have it working.