wie macht man sowas hier richtig?
1 | #define LED_SET_ON(PRT,PIN,INV)\
|
2 | #if(INV == 0)\
|
3 | PORT##PRT |= (1<<PIN)\
|
4 | #else\
|
5 | PORT##PRT &=~(1<<PIN)
|
6 |
|
7 | #define LED_SET_OFF(PRT,PIN,INV)\
|
8 | #if(INV == 1)\
|
9 | PORT##PRT |= (1<<PIN)\
|
10 | #else\
|
11 | PORT##PRT &=~(1<<PIN)
|
Im code bzw. in weiteren makros will ich es so nutzen:
1 | LED_SET_ON(D,5,1); // PD5 low -> LED an
|
2 | LED_SET_ON(D,6,0); // PD6 high -> LED an
|
3 | (...)
|
4 | LED_SET_OFF(D,5,1); // PD5 high -> LED aus
|
5 | LED_SET_OFF(D,6,0); // PD6 low -> LED aus
|
Die LED-Markos sind noch falsch definiert, sodass der Compiler einen
Fehler wirft:
1 | myfile.c:203:31: error: '#' is not followed by a macro parameter
|
daher werden die Markos auch im code als Funktionen mit Parametern
interpretiert:
1 | myfile.c:223:16: error: 'D' undeclared (first use in this function)
|