MEGA 1280 unable to read high digital (pins 38-53) using PORT level code

Hi guys.
I'm pretty new to Arduino (2 weeks), but have a lot of dev experience.
While the Atmel chips are great, the Arduino IDE hides too much of the magic that can be done.. but it does make it easy to get started !

My problem is that I need to read 16 discrete digital inputs.
I tried the analog inputs (for a different reason), but they're way too slow with digitalRead()
So I shifted down to the high digital I/O (pins 38-53)

Faster - but still quite slow with digitalRead()

OK, no big deal...
pinMode( pin_number, INPUT_PULLUP);
// then manually grab the port bits with -
input_bits = PORTL; // (for example)

But I don't get anything meaningful back from all those 16 pins
(unfortunately they're mashed across PORTS D G L B)

Any suggestions ?

ACTUAL CODE SNIPPETS - I've added a printf() function of my own - no problem...
The rest of the code handles a serial UI, 6 servos and 4 steppers, and all runs fine.

// ---------------------------------------
unsigned int input_bits;
char index;

// SETUP ------------------------------
::
for (index=38; index <= 53; index++) { // switch inputs
pinMode(index, INPUT_PULLUP);
digitalWrite(index, HIGH); // probably not neccessary, but docs are sooo bad!
}
::

// LATER ------------------------------
::
input_bits = PORTL;
printf("\r\nIN_BITS = %4X", input_bits); // displays FF regardlesss of pin states
::
// ---------------------------------------

ACTUAL CODE SNIPPETS

Actual code required.

Lose the colours, use code tags, please.

I tried the analog inputs (for a different reason), but they're way too slow with digitalRead()

Citation required.

PORTx for output, PINx for input.

Thanks for the replies...
PIN is fine 'Arduino-speak' to read a pin, but I'd much rather read the whole PORT to save cycles.

It compiles and runs fine, but simply doesn't return the PORT value...

Did you read reply #2?

lastchancename:
Thanks for the replies...
PIN is fine 'Arduino-speak' to read a pin, but I'd much rather read the whole PORT to save cycles.

As already posted PINx reads a whole port back to a variable, Where x is the port letter you wish to read, as in PINB

It compiles and runs fine, but simply doesn't return the PORT value...

lastchancename:
PIN is fine 'Arduino-speak' to read a pin, but I'd much rather read the whole PORT to save cycles.

It isn't 'Arduino-speak' it is 'Atmega328-datasheet-speak'. See for example page 92.

For each set of 8 input/output ports there is a PORTx (eg. PORTD) which you write to, to set all 8 outputs simultaneously and a PINx (eg. PIND) which you read to get all 8 inputs simultaneously.

This saves cycles, which is why I mentioned it. You don't read the current "inputs" on the pin by reading from PORTx. If you read back PORTx you will probably find what you last wrote to PORTx, which might be useful if the ports are configured as outputs.

My problem is that I need to read 16 discrete digital inputs.

So you read to read PINx and PINy assuming that you have connected them to contiguous ports on the processor.

It compiles and runs fine, but simply doesn't return the PORT value...

It will return the value present at the physical port, isn't that what you want? (if it is set as an input).

Ahh ok. SORRY !

Coming from another planet - I wrongly assumed PINx would return the value of a PIN.
PORTx compiles and runs - just appears to do nothing. (What does PORTx actually do ?)

So I apologise to y'all for dissing the Arduino libraries, but to me - having been plugging code into micro's since the late 70's - a PORT typically repesented a byte/word or other collection of individual 'PINs'.

Cheers & thanks again.
QUESTION CLOSED

Signetics 2650 -> Z80 -> PDP-8 -> PDP-11/03 PDP-11/23 -> VAX 11/780 -> Apple LISA -> Wintel x86 / PIC / RABBIT / ...
Machine code -> Assembler -> CB/86 -> FORTRAN -> VB3/4/5/6/S -> C ...

lastchancename:
(What does PORTx actually do ?)
...
QUESTION CLOSED

Closed or not?

PORTx is for writing to the output port (8 pins). PINx is for reading from the same port (8 bits).

and DDRx is for changing the direction between input and output. Thus completing mention of the different I/O registers.