Pin Change Interrupts - Difference in PORT Read & DigitalRead

Hi,
I am trying Pin Change Interrupt Code as Below

#include<avr/interrupt.h>
volatile boolean recvPCInt = false;
volatile byte portValue ;
ISR(PCINT0_vect){
  recvPCInt = true;
  portValue = PORTB;
}

void setup() {
cli(); //Clear all interrupts
PCICR |= 0b00000001; //Enable port B Registers i.e D8-D13
PCMSK0 |= bit(PCINT1);// Pin9
sei(); //enable all interrupts
pinMode(9,INPUT);
digitalWrite(9,HIGH);//enable pull up in pin 9
Serial.begin(9600);
}

void loop() {
  if(recvPCInt == true){
     //if interrupt received
     Serial.println(portValue,BIN);
     Serial.println(digitalRead(9));
     recvPCInt = false;
  }
}

The Reading with PortD (portValue) is Not Changing where as digitalRead(pin) Changes.

what iam doing wrong here ? (is volatile usage correct ?)
See the output in attached image

Try: portValue = PINB;

See the output in attached image

A picture of text? Why did you need to piss away so much bandwidth posting a picture of 20 characters?

PaulS:
A picture of text? Why did you need to piss away so much bandwidth posting a picture of 20 characters?

Ok, that's my bad - i will try to post characters now onwards.

But why did you reply on THAT without giving me information on whats the problem in the code ?

Don't you think that piss away bandwidth ?

The Reading with PortD (portValue) is Not Changing where as digitalRead(pin) Changes.

Can you point out the part of the code that reads PortD?

PaulS:
Can you point out the part of the code that reads PortD?

That's a typo - Its Actually PortB

portValue = PORTB;

arduarn:
Try: portValue = PINB;

Output is

100010
1
111101
0

I think i am getting same value - but why other bits are changing ?

but why other bits are changing ?

Floating pins

What is your hardware?

Arduino Uno.

I am connecting wire from pin9 to GND to change the level

I am connecting wire from pin9 to GND to change the level

"change" implies that the pin has a one known state and is being set to another known state.

If there is nothing connected to the pin, and it's mode is not INPUT_PULLUP or the internal pullup resistor has not been turned on, then it does NOT have a known state at all times.

Grounding the pin puts it in a known state. Ungrounding it returns it to an unknown state.

anilkunchalaece:
Output is

100010

1
111101
0




I think i am getting same value - but why other bits are changing ?

As stated by others, floating pins will read with undefined results.

Pin 9 is Port B 1, which is the second bit from the right. So from your miniscule output sample, the port value is now correctly matching the digitalRead() value.