port-related questions

I'm planning to use a 2560 board to multiplex 40-50 switches in a machine control panel to an emc2 controller via modbus. Scanning this number of inputs will be much more efficient if done as parallel operations, via port manipulations, rather than as single bits. Even the 2560 doesn't provide enough uncommitted dio pins, so I will need to use some of the ports that have been assigned to other uses (analog in, for example). I haven't been able to find in the documentation, either Arduino or AVR, what process, if any, is needed to set the operating mode of a port to either general digital i/o or special purpose. Can someone clarify this?

On a somewhat related note, I have been searching for definitions of the port manipulation registers (DDR etc) for the 2560 board. A previous post on this board provided:

for your ATMega 2560 controller, you can find the information in file "C:\arduino-0022\hardware\tools\avr\avr\include\avr\iomxx0_1.h". So there's no need to define the register names yourself.

my installation of arduino-0022 (on ubuntu 10.04) shows nothing in the tools directory but arvdude. Anybody have an idea where the rest of the data went?

thanks in advance


Looking at the block diagram in the 2560 documentation (http://www.atmel.com/dyn/resources/prod_documents/doc2549.pdf) I se the following port usages:

Port A: External RAM access. Port B: SPI, 8 bit Timer/Counter 0, 16 bit Timer/Counter 1, 8 bit Timer/Counter 2, Pin change interrupts 0-3 Port C: External Ram access. Port D: Two Wire Interface (I2C), 8 bit Timer/Counter 0, 16 bit Timer/Counter 1, USART 1 external clock Port E: USART 0, Analog Comparator, 16 bit Timer/Counter 3 Port F: JTAG, Analog Inputs Port G: External Ram access, Clock input/output. Port H: USART 2, 8 bit Timer/Counter 2, 16 bit Timer/Counter 4 Port J: USART 3 Port K: Analog Inputs Port L: 16 bit Timer/Counter 4, 16 bit Timer/Counter 5

You just have to decide which of those features you don't need.

I'd suggest Port A and Port C unless you plan to add external RAM to your 2560. That will give you a 64-switch matrix to scan.