Portmanipulation for one byte

Hello,

I stuck in programming my Leonardo. I want to write a one byte variable with port manipulation to PORTB (5,6,7,8) and PORTF (5,6,7,8). In the setup I configured the ports as followed:

void setup()
{
  DDRB |= 0b11110000;
  DDRF |= 0b11110000;
}

Now I don't know, how I get the variable to the ports.

Bit | Port

0 | B5
1 | B6
2 | B7
3 | B8
4 | F5
5 | F6
6 | F7
7 | F8
Does anybody know a way?

7  |  F0Do you really mean that ?

Does anybody know a way?

So, you want to write the highest 4 bits to the highest 4 bits of PORT B, and the lowest 4 bits to the highest 4 bits of PORT F?

The bitwise operators, masking, and the right shift operator are just what you need.

Or, use the bitRead() and bitSet() macros and 2 for loops.

UKHeliBob:
7  |  F0Do you really mean that ?

No, sorry. It should be F8.

PaulS:
So, you want to write the highest 4 bits to the highest 4 bits of PORT B, and the lowest 4 bits to the highest 4 bits of PORT F?

The bitwise operators, masking, and the right shift operator are just what you need.

Or, use the bitRead() and bitSet() macros and 2 for loops.

Yes.

PaulS:
So, you want to write the highest 4 bits to the highest 4 bits of PORT B, and the lowest 4 bits to the highest 4 bits of PORT F?

The bitwise operators, masking, and the right shift operator are just what you need.

Or, use the bitRead() and bitSet() macros and 2 for loops.

Thanks. I tried it with bitRead() and DigitalWrite() and it works.