Can I Read 8 Pins Into One Byte (or Write 8 At One Time) With Mega??

Can I read 8 pins into one byte (or write 8 at one time) with Mega?? Projects Programming October 15, 2011, 2:49am 1

I notice the Mega shows the following assignments: PA 0 = Pin22 PA 1 = Pin23 PA 2 = Pin24 .... PA 7 = Pin29

This seems to show that Port A (PA) is assigned the 8 pins from Pin22 to Pin29. In other micros, I could do something like...

digitalRead (PA, myInput)

So I would DEFINE myInput as a Byte, and "reading" PA says "Read the 8 pins I defined as Port A (22-29)" I could then compare myInput with oldMyInput to check for a change.

Does Mega allow this? Can I lump 8-bits into a single 8-bit port and write it out in one command, or read in 8-bits of digital input and process them as a single byte???

I'm writing a digital game with 8 digital switch inputs and the logic will drive 8 LEDs using PWM, so the ability to "talk" using an entire byte instead of processing inputs and outputs on a bit-wise level, would be an advantage.

October 15, 2011, 2:53am 2

just do "myInput = PINA"

October 15, 2011, 3:10am 3

Yes you can do direct port commands to set input or output mode, read a byte and write a byte using the port name.

http://www.arduino.cc/playground/Learning/PortManipulation

Lefty

Topic Replies Views Activity
How to READ or WRITE one byte (8 bits) at once with Arduino UNO or Mega2560 General Guidance 5 240 September 12, 2025
Transferring Bytes Programming 13 1605 June 9, 2021
Mega 2560 Ports Mega 2560 3 6571 June 29, 2024
Working with PORTS, not PINS Programming 3 66 October 4, 2025
Direct Port Manipulation Using the Arduino Giga Board Programming 13 928 October 11, 2024
Unfortunately, your browser is unsupported. Please switch to a supported browser to view rich content, log in and reply.

Tag » Arduino Write Byte To Pins