Du hast auch Port A und B auf Ausgang gestellt und Port D auf Eingang mit PullUp.
Mit Port D machst du aber nichts.