I'm attempting to read the values of 8 pins at a time into a byte.
The obvious answer to this seems to be the Port registers, however with the way the Arduino is wired, I'd have to split my read across two registers.
In this case, I need a way to combine the lower 5 bits of PORTB with the upper 3 bits of PORTD into a single byte.
For example, this is the physical layout with the data lines I'm attempt to read/write to and their corresponding port assignments.
SCSI
DB7 DB6 DB5 DB4 DB3 DB2 DB1 DB0
| | | | | | | |
PB4 PB3 PB2 PB1 PB0 PD7 PD6 PD5
AVR
From what I can gather I need to use some shift operators to achieve this, perhaps something like:
hi = PORTB & 3;
lo = PORTD >> 3;
But I'm unsure if that's correct and then how I would combine them.
Is it possible to write a macro to make getting and setting this byte easier?
Is there a good learning resource on bit manipulation like this?
(PORTB & (32-1) << 3) | (PORTD >> 5)
but I'm still uncertain how to go about it for writing.