带参数的宏加灯控制示例

//带参宏,可以像内联函数一样使用
#define LED1(a) if (a) \
GPIO_SetBits(GPIOE,GPIO_Pin_0);\
else \
GPIO_ResetBits(GPIOE,GPIO_Pin_0)

调用示例:LED1( ON );

---------------------------------------------------------------------------------------------

/*LED1-DS2反转*/
GPIO_WriteBit(GPIOE, GPIO_Pin_2,
  (BitAction)((1-GPIO_ReadOutputDataBit(GPIOE, GPIO_Pin_2))));

typedef enum
{ Bit_RESET = 0,
Bit_SET
}BitAction;

---------------------------------------------------------------------------------------------

引申话题:

先感谢以下前辈

C语言中的换行

C语言中的换行

// \ 后面不能有空格
// \ 不能没有
#define  KEY(a)  if(a) \
                    printf("he"); \
                 else \
                    printf("ss");

// \ 后面不能有空格
// \ 可以去掉
char buf[] = {0xa, 0xb, 0xc, 0xd, \
               0xe \
             };

void fun(void)
{
    char a;
    char b;
    
    if((a == 1)
        || (b == 1))
    {
        
    }
    if((a == 1) \
        || (b == 1))
    {
        
    }
    if((a == 1) || (b == 1))
    {
        
    }
}

// \ 后面内容需要顶格写,否则前面的空格计到字符串中
void print1(void)
{
    char a;
    
    printf("ni hao %d \
di a b\n", a);

}

 

posted @ 2021-12-15 10:05  我爱茜茜公主  阅读(94)  评论(0)    收藏  举报