Thanks for the reply. Sorry it was a typing mistake @ vary
This is not my full code. My actual code runs fine with reading port c.5 & Port B.

My problem is correctly reading Port D.2 to D.7 into variable D. and if any of the pin is high, the buzzer should NOT toggle.
But for some reason Variable D=0 is true even if Lets say PortD.2 or D.3 to D.7 is high i.e.=1

I picked important lines from my code to explain the Problem.
Is there any other way which can load PortD.2 to D.7 into variable D?