Direct Port Manipulation for ATMEGA2560

Hi

Referring to pin map of ATMEGA2560, I learnt that Pin 42-49 digital outputs are mapped to PORTL of the MCU. I have connected digital inputs to these ports. Used digital read to verify and they are OK. I tried to use PORTS for faster read, but they are not working

I just added the following code in set up
DDRL = B00000000;

and in loop

Serial.println(PORTL);

It is printing "0". What could be wrong?

Hi,
Have you googled port manipulation arduino mega

Pleased post your complete code.

Tom.... :slight_smile:

Yes But please suggest if it is wrong

What could be wrong? Nothing.

Printing "0" is the equivalent of B00000000. This simply states that the value of the PORT pins is each zero. As you have defined the entire port to be INPUT (DDRL = B00000000) this is what you would expect as the PORTn register is tied to OUTPUT. If you want the status of INPUT pins, print the PINL register.

Thank you. It is resolved