Salve
il codice, correttamente funzionante, utilizza le PCINT sulla porta C.
La cosa strana è il settaggio che ho dovuto fare sulla porta PC1.
Qualcuno sa dirmi qualcosa a riguardo?
//-----[PINS]------------
#define Port_C_PinA0 14
#define Port_C_PinA1 3 //non dovrebbe essere 15???? <-----------------QUI
#define Led_Verde 8
#define Led_Rosso 9
#define DELAY for (volatile long i=0; i<50000; i++){}
volatile byte Previous_Port_Value=0xFF; //Memorizza lo stato precedente della porta
void setup(){
//pull-up
pinMode(Port_C_PinA1, OUTPUT);
digitalWrite(Port_C_PinA1, HIGH);
//Settaggio led
pinMode(Led_Verde, OUTPUT);
pinMode(Led_Rosso, OUTPUT);
cli(); //Disable interrupt
bitSet(PCICR, 1); //Enable PCINT Interrupt for Port C
bitSet(PCMSK1, 0); //mask for Pin A0: Tamper
bitSet(PCMSK1, 1); //mask for Pin A1: Magnetic
//bitSet(PCMSK1, 2); //mask for Pin A2: shock
sei(); //Enable interrupt
}
void loop(){
}
//PORT C INTERRUPT MANAGER
ISR (PCINT1_vect)
{
//Mi indica la posizione dei bit che sono variati
byte Pin_Changed = PINC ^ Previous_Port_Value;
//Memorizzo il nuovo stato precedente
Previous_Port_Value = PINC;
for (byte Pin_Position=0; Pin_Position<8; Pin_Position++){
if ( bitRead(Pin_Changed, Pin_Position) == true){
switch (Pin_Position) {
case 0:
if (bitRead(PINC, Pin_Position) == HIGH){PCINT8();} //Rise Edge
if (bitRead(PINC, Pin_Position) == LOW){} //Fall Edge
break;
case 1:
if (bitRead(PINC, Pin_Position) == HIGH){PCINT9();} //Rise Edge
if (bitRead(PINC, Pin_Position) == LOW){} //Fall Edge
break;
case 2:
if (bitRead(PINC, Pin_Position) == HIGH){} //Rise Edge
if (bitRead(PINC, Pin_Position) == LOW){} //Fall Edge
break;
case 3:
if (bitRead(PINC, Pin_Position) == HIGH){} //Rise Edge
if (bitRead(PINC, Pin_Position) == LOW){} //Fall Edge
break;
case 4:
if (bitRead(PINC, Pin_Position) == HIGH){} //Rise Edge
if (bitRead(PINC, Pin_Position) == LOW){} //Fall Edge
break;
case 5:
if (bitRead(PINC, Pin_Position) == HIGH){} //Rise Edge
if (bitRead(PINC, Pin_Position) == LOW){} //Fall Edge
break;
case 6:
if (bitRead(PINC, Pin_Position) == HIGH){} //Rise Edge
if (bitRead(PINC, Pin_Position) == LOW){} //Fall Edge
break;
case 7:
if (bitRead(PINC, Pin_Position) == HIGH){} //Rise Edge
if (bitRead(PINC, Pin_Position) == LOW){} //Fall Edge
break;
}//switch
}//if
}//for
}//isr
void PCINT8(){
digitalWrite(Led_Rosso, HIGH);
DELAY;
digitalWrite(Led_Rosso, LOW);
}
void PCINT9(){
digitalWrite(Led_Verde, HIGH);
DELAY;
digitalWrite(Led_Verde, LOW);
}