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: https://www.avrfreaks.net/comment...

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://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.