Arduino mega using any pin as an interrupt pin?

Hi. I am using an arduino mega and limit switches. I have pins corresponding to each of my (8) limit switches: pins 40 - 47.

I can't change these pins given the project rn, but I need to enable interruptions on each of these pins. I'm trying to set it up so that when a limit switch is pressed, I use an interruption (the code will be the same for each interruption for these switches, which I think is good b/c the method I'm trying to use allows for two or more pins to share the same routine....

However I"m having trouble with this.

I'm trying to understand the "Simple Pin Change Interrupt on all pins" https://playground.arduino.cc/Main/PinChangeInterrupt

My questions: 1) I'm not sure which service to use? Apparently my options are: ISR (PCINT0_vect) pin change interrupt for D8 to D13 ISR (PCINT1_vect) pin change interrupt for A0 to A5 ISR (PCINT2_vect) pin change interrupt for D0 to D7

2) I really don't get how they implemented this....Please help! Namely, I don't understand these functions:

void pciSetup(byte pin) 
{
   *digitalPinToPCMSK(pin) |= bit (digitalPinToPCMSKbit(pin));  // enable pin
   PCIFR  |= bit (digitalPinToPCICRbit(pin)); // clear any outstanding interrupt
   PCICR  |= bit (digitalPinToPCICRbit(pin)); // enable interrupt for the group 
}

// Use one Routine to handle each group

ISR (PCINT0_vect) // handle pin change interrupt for D8 to D13 here
{    
    digitalWrite(13,digitalRead(8) and digitalRead(9));
} 

ISR (PCINT1_vect) // handle pin change interrupt for A0 to A5 here
{
    digitalWrite(13,digitalRead(A0));
}  

ISR (PCINT2_vect) // handle pin change interrupt for D0 to D7 here
{
    digitalWrite(13,digitalRead(7)); 
}

What am I supposed to change? What function is called for when the interrupt is activated, where's the code?

knorrLover: I'm trying to understand the "Simple Pin Change Interrupt on all pins" https://playground.arduino.cc/Main/PinChangeInterrupt

Thats referring to all pins on an Arduino UNO.

Is this the same?

https://arduino.stackexchange.com/questions/54081/arduino-mega-interrupt-not-working-use-any-pin-for-interrupt

It's not the same, but that's convenient!!!

I have pins corresponding to each of my limit switches: pins 40 - 47. I can't change these pins given the project rn, but I need to enable interruptions on each of these pins.

I don't think that any form of interrupt (neither "external" nor "pin change) is supported on pins 40-47 (that's a couple pins from PORTG and six from PORTL) The MEGA processor only has pin change interrupts on 24 pins (all of PORTB, PE0, PJ0..6, all of PORTK) You'll need to poll...

Why are you assuming that on an ATMEGA you can have interrupts on all pins ?

The data sheet for the processor is fairly clear in stating that you cannot.

Hi

I have started a new topic. I think my toppic is handle almost the same question? Interruptions

Best regards Fredrik

Hi

I have decided not to have all the mega boards in one place, as I said earlier. I will have each board as close as possible to the components but it must be possible to disconnect the component if needed!

I like connect as bellow: 1.) Connect the Solid core for the component. question A.) Am I need some soft of Shrink Tubing for the Rotary Switches - 12 pos? (The pins is closes to each other so I thinking of the magnetic field)

2.) Use the 2 pin push quick cable connector (Very nice module to work with :)

3.) The other end of the 2 pin push quick cable connector have the cable which is connected into the board. This wire is like this sort V-TEC Jumper Wires Pre-crimped Terminaler (FeMale) ;)

The bad Solid core cable is more than maybe 2 inch?! They should not be bent at all!

Fredrik

FredrikH: Hi

I have started a new topic. I think my toppic is handle almost the same question? Interruptions

Best regards Fredrik

Ah. Well why do you think anyone would be interested in a 2 year old thread on a similar subject now? You are dangerously close to duplicate posting which is not allowed here.