【发布时间】:2017-06-29 23:04:17
【问题描述】:
我正在为 LPC1343 微控制器使用 cortex m3 编程。当我编译我的代码时,我在SetLed((eLeds_t *)h1, false); 行中出现错误,它显示Error[Pe018]: expected a ")",好像我所做的演员阵容不够好。
遵循枚举类型 def 声明和 :
#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
【问题讨论】:
-
为什么要将枚举值转换为指针?
-
您可以声明一个 eLeds_t 类型的局部变量并指定
h1。您可以将该变量的引用传递给函数。但是你为什么要这样做呢? -
我无法重现该错误。你确定你复制的代码正确吗?
-
我得到的唯一警告是
switch()不能处理noled的情况。 -
真正的代码可能在某处缺少
;。
标签: c types syntax enums casting