我用我的MSP430下面的宏功能来检查GPIO引脚的状态:宏函数读取寄存器
#define PIN(port) port##IN // register name
#define IN_(port,pin,act) PIN(port) & (1<<(pin)) // request pin status
#define IN(name) IN_(name) // final macro function call
然后我能够得到这样一个GPIO引脚的状态:
enum {ACT_LOW = 0 , ACT_HIGH};
#define STATUS_LED P3,0,ACT_LOW // P3 ... port name,
// 0 ... associated port pin,
// ACT_LOW ... pin intended for active low action
void main()
{
if(!IN(STATUS_LED))
printf("Status LED connected to P3.0 is switched on");
else
printf("Status LED connected to P3.0 is switched off");
}
现在我想将我的引脚的活动状态考虑进去,以便在编程时不打扰我的LED切换低端('0'= LED已打开)。 我的方法当时以下代替上述第2行:
#define IN_(port,pin,act) \
do{ \
if((act) == ACT_HIGH) \
PIN(port) & (1<<(pin)); \
else \
~(PIN(port) & (1<<(pin))); \
}while(0)
但是,编译器“期望的表达”。 我的错误是什么?我错了什么?
它应该是一个语法错误,其中行是给出错误? –
'do ... while'是一个陈述,而不是一个表达。它不评估任何东西。因此,你不能在'if'语句中使用它。 – 2014-02-09 14:00:28