Hello.
Many of your questions are answered by the ATmega644 datasheet, which I strongly recommend you take a look at. The 3x16 header on the right side of the X2’s bottom board gives you access to pins PA0 - PA7 (not 8) and PD0 - PD7. The mega644 actually has four ports: A, B, C, and D. Port C connects to the user LEDs, pushbuttons, and the LCD data lines (see the quickstart sheet for a block diagram and schematic). Most of port B is used for LCD, buzzer, and motor control, but pins PB2 and PB4 are unused and can be accessed via labeled pads on the bottom board.
The line DDRC &= ~(1 << PC5) sets pin PC5 as a digital input. PC5 is an LCD data line and it also connects to a user LED.
By default, pins PA6 and PA7 are connected to a battery-monitoring voltage divider and the user trimmer potentiometer, respectively, through solder jumpers on the underside of the bottom board. If these solder jumpers are in place, I recommend you avoid connecting external devices to these two pins. If you want to use these pins for something else, use a soldering iron to break the solder jumpers on the PCB. The X2 schematic shows you which pins are connected to the various on-board components. Pins PA0 - PA5, PD0 - PD7, PB2, and PB4 are reserved solely for user I/O and are not connected to any of the X2’s hardware.
I’m not sure what you’re asking with regard to the ADC. Port A pins can be used as digital I/Os or analog inputs (or both). The mega644 datasheet explains how to use the ADC to read the analog voltages on these pins, and the Orangutan X2 test code (under the resources tab of the product page) gives an example of using the ADC. If you have sensors that output an analog voltage, you will want to plug them into port A pins and use the ADC.
All of the mega644 registers have addresses, but you rarely need to concern yourself with them since they can be referenced via convenient macros when you include <avr/io.h>. In the line:
if (PIND & 0x20)
0x20 isn’t an address, it’s a bitmask. The address is PIND, which comes from <avr/io.h>. The line is requesting the byte that represents the digital input values of the eight port D pins, which is then bitwise-anded with 0x20 (0b00100000). This lets me check the value of bit 5 of PIND (i.e. the digital input value of pin PD5). If the bitwise-and results in 0, pin PD5 is reading low, otherwise pin PD5 is reading high. Does this make sense?
- Ben