Stefan Malig wrote:
> Gibt es dafür eine einfache Syntax?
Nein.
Da wird dir nichts anderes übrig bleiben, als jedes Bit
einzeln zu behandeln
1 | #define LESE_PORT_A PORTB
|
2 | #define LESE_PORT_B PORTF
|
3 |
|
4 |
|
5 | uint8_t Result;
|
6 |
|
7 | Result = 0;
|
8 | Result |= LESE_PORT_A & ( 1 << BIT_0 );
|
9 | Result |= LESE_PORT_A & ( 1 << BIT_1 );
|
10 | Result |= LESE_PORT_A & ( 1 << BIT_2 );
|
11 | Result |= LESE_PORT_A & ( 1 << BIT_3 );
|
12 | Result |= ( LESE_PORT_B & ( 1 << BIT_0 ) ) << 4;
|
13 | Result |= ( LESE_PORT_B & ( 1 << BIT_1 ) ) << 4;
|
14 | Result |= ( LESE_PORT_B & ( 1 << BIT_2 ) ) << 4;
|
15 | Result |= ( LESE_PORT_B & ( 1 << BIT_3 ) ) << 4;
|
Wenn dann auch noch die 'Nibble-Bits' völlig frei zugeordnet
werden sollen, dann wirds noch aufwändiger.
1 | #define PORT_BIT_A PORTB // vom PORTB ...
|
2 | #define BIT_A 5 // ... nimm Bit Nr 5 ...
|
3 | #define RESULT_BIT_A 0 // ... und gib es im Ergebnis auf
|
4 | // Bit Nr 0
|
5 |
|
6 | #define PORT_BIT_B PORTC // vom PORTC ...
|
7 | #define BIT_B 0 // ... nimm Bit Nr 0 ...
|
8 | #define RESULT_BIT_B 2 // ... und gib es im Ergebnis auf
|
9 | // Bit Nr 2
|
10 |
|
11 | ...
|
12 |
|
13 | Result = 0;
|
14 | Result |= ( ( PORT_BIT_A & ( 1 << BIT_A ) ) ? 1 : 0 ) << RESULT_BIT_A;
|
15 | Result |= ( ( PORT_BIT_B & ( 1 << BIT_B ) ) ? 1 : 0 ) << RESULT_BIT_B;
|
16 | Result |= ( ( PORT_BIT_C & ( 1 << BIT_C ) ) ? 1 : 0 ) << RESULT_BIT_C;
|
17 | Result |= ( ( PORT_BIT_D & ( 1 << BIT_D ) ) ? 1 : 0 ) << RESULT_BIT_D;
|
18 | Result |= ( ( PORT_BIT_E & ( 1 << BIT_E ) ) ? 1 : 0 ) << RESULT_BIT_E;
|
19 | Result |= ( ( PORT_BIT_F & ( 1 << BIT_F ) ) ? 1 : 0 ) << RESULT_BIT_F;
|
20 | Result |= ( ( PORT_BIT_G & ( 1 << BIT_G ) ) ? 1 : 0 ) << RESULT_BIT_G;
|
21 | Result |= ( ( PORT_BIT_H & ( 1 << BIT_H ) ) ? 1 : 0 ) << RESULT_BIT_H;
|
Flexibilität hat nun mal seinen Preis.