我正在为LPC1343微控制器编程一个皮层m3。当我编译我的代码时,我得到一行SetLed((eLeds_t *)h1, false);
错误,它说Error[Pe018]: expected a ")"
好像这个演员我做的不够好,我猜。传递一个typedef枚举作为c参数抛出错误
遵循枚举类型定义声明和:
#ifndef _LEDS_h
#define _LEDS_h
#ifndef bool
typedef unsigned char bool;
# define true 1;
# define false 0;
#endif // ifndef bool
enum eLeds
{
noled, p1l, p1r, p2l, p2r, h1, h2
};
typedef enum eLeds eLeds_t;
void SetLed(eLeds_t led, bool action)
{
switch (led)
{
case p1l:
GPIOSetValue(PORT2, 5, action);
break;
case p1r:
GPIOSetValue(PORT2, 8, action);
break;
case p2l:
GPIOSetValue(PORT0, 9, action);
break;
case p2r:
GPIOSetValue(PORT0, 8, action);
break;
case h1:
GPIOSetValue(PORT0, 5, action);
break;
case h2:
GPIOSetValue(PORT0, 7, action);
break;
}
}
void leds_init(void)
{
GPIOSetDir(PORT2, 5, 1); // p1l
GPIOSetDir(PORT2, 8, 1); // p1r
GPIOSetDir(PORT0, 9, 1); // p2l
GPIOSetDir(PORT0, 8, 1); // p2r
GPIOSetDir(PORT0, 5, 1); // h1
GPIOSetDir(PORT0, 7, 1); // h2
LPC_IOCON->PIO2_5 &= ~0x07;
LPC_IOCON->PIO2_8 &= ~0x07;
LPC_IOCON->PIO0_9 &= ~0x07;
LPC_IOCON->PIO0_8 &= ~0x07;
LPC_IOCON->PIO0_5 &= ~0x07;
LPC_IOCON->PIO0_7 &= ~0x07;
eLeds_t value = h1;
SetLed(&value, false);
}
#endif // ifndef _LEDS_h
你为什么将枚举值转换为指针? – Barmar
您可以声明eLeds_t类型的本地并分配该“h1”。您可以将该变量的引用传递给函数。但你为什么要这么做? – MKR
我无法重现该错误。你确定你正确地复制了代码吗? – Barmar