Electronic – AVR pin change interrupt

avrinterrupts

I want to turn on LEDs 0, 1 and 2 when pinc1, pinc2 and pinc3 are triggered. Also, I want to use a pin change interrupt.

Problem: only LED 1 is on.

This is my code and I am using atmega328p and Proteus for simulation:

#include <avr/io.h>
#include <avr/interrupt.h>

volatile uint8_t bemf = 0 ;
ISR(PCINT1_vect)
{

if (PINC & 00000010){bemf=1;}
if (PINC & 00000100){bemf=2;}
if (PINC & 00001000){bemf=3;}

}

int main(void)
{

DDRD = 0xFF ; 
PORTD = 0x00;
PCMSK1 |= 1<<PCINT10 | 1<<PCINT11 | 1<<PCINT9 ; // pinc1 pinc2 and pinc3
PCICR |= 1<<PCIE1 ;
sei();

while (1) 
{

  if (bemf==1){PORTD= 1<<PIND0;}  // TURN ON LED 0
  if (bemf==2){PORTD= 1<<PIND1;}  // TURN ON LED 1
  if (bemf==3){PORTD= 1<<PIND3;}  // TURN ON LED 2


}
}

Best Answer

the solution is to use this

PINC & 0b00000010

instead of

PINC & 00000010