PCINT: why my code on port C don't work?

Go To Last Post
3 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello, 

I want use PCINT on port C. 

My code compile but no ISR happen.

What is wrong?

 

-------------------- CODE ----------------------------------------------------

 

#include <avr/interrupt.h>

#define Port_C0_PinA0 A0       //PCINT8

volatile byte port_C_status=1;
volatile byte actual_Port_Value =0;

void setup(){

Serial.begin(9600);

pinMode(Port_C0_PinA0, INPUT);         //Set port in Pull Up Mode
digitalWrite (Port_C0_PinA0, HIGH);      //pull-up mode enabled

cli();     //Disable interrupt
bitSet(PCICR, 1);  //Enable PCINT Interrupt For port C
Serial.print("PCRCI= "); Serial.println(PCICR, BIN);
bitSet(PCMSK1, 0);   //mask for Pin A0
sei(); //Enable interrupt
}

void loop(){
//idle
}

//PORT C INTERRUPT MANAGER
ISR (PCINT1_vect)
{
 cli();
 actual_Port_Value = PINC;
 if ( bitRead(actual_Port_Value,0) ==1 && bitRead(port_C_status,0)==0 )  Serial.println("Analog Pin 0");
 sei();
}//isr
Last Edited: Wed. Feb 14, 2018 - 05:13 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

How to properly post source code: http://www.avrfreaks.net/comment...

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi, you need to declare the interrupt:

 

attachInterrupt(digitalPinToInterrupt(pin), ISR, mode); // mode LOW, HIGH, RISING, FALLING or CHANGE

 

Beware that not all pins support interrupt.