小编baj*_*tec的帖子

有没有办法将多个值作为C中单个定义的宏值传递给宏函数?

我想在全局标头中将引脚定义声明为一条简单的行,例如:

#define STATUS_LED B,7
Run Code Online (Sandbox Code Playgroud)

然后,我想将此引脚定义传递给以上功能:

CMBset_out(STATUS_LED);
Run Code Online (Sandbox Code Playgroud)

我不知道该如何处理-MY_PIN格式正确,可以在预编译阶段替换。

#define CMBsbi(port, pin) (PORT##port) |= (1<<pin)
#define CMBset_out(port,pin) (DDR##port) |= (1<<pin)
// define pins 
#define STATUS_LED B,7
Run Code Online (Sandbox Code Playgroud)

Then, I want to pass this pin definition to function above (hw_init_states() is declared in the same header file called from main C file):

// runtime initialization
void hw_init_states(){
#ifdef STATUS_LED
    CMBset_out(STATUS_LED);
#endif
}
Run Code Online (Sandbox Code Playgroud)

But I get a compilation error:

Error   1   macro "CMBset_out" requires 2 arguments, but only 1 given   GENET_HW_DEF.h  68  23  Compass …
Run Code Online (Sandbox Code Playgroud)

c macros gcc avr

13
推荐指数
2
解决办法
309
查看次数

标签 统计

avr ×1

c ×1

gcc ×1

macros ×1