Welcome to our site! EDAboard.com is an international Electronic Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.
Be very careful remembering which to use under which conditions, as reading the wrong register is the cause of more than a few beginner program problems. PortD is primarily for controlling the port when it's configured as an output (DDRB == 1) As setting portb will change it from sourcing to sinking curent. When DDRD == 0 (set to input) portD controls weather or not the internal pullup resistors are enabled or not (1 == pullups on, 0 == pin is floating) PinD is a direct access register to the logic state of the pins. When DDRB is set to 0 you read the pin register to read the state of the pin. So remember, DDRD is for setting input/ouput PORTD is for setting I/O source/sink and individual pullups, and PIND will always return the current logic state of the port (mind you this can detect short circuits in or out of an I/O pin if the pin port is exactly opposite of what it's supposed to be)