标题: C语言宏定义求助 [打印本页]

作者: samxon    时间: 2025-4-28 12:08
标题: C语言宏定义求助
大家好,我想宏定义两个语句实现电机正反转功能,这个宏定义语句应该怎么写。谢谢大家。
#define RW P1.1=0 P1.2=1
#define FW P1.1=1 P1.2=0

已解决

#define RW P11=0; P12=1
#define FW P11=1; P12=0




作者: GlenXu    时间: 2025-4-29 08:50
第一次看见这么定义的,学习了
作者: woshinh    时间: 2025-4-29 15:37
// 反转(RW):P1.1=0, P1.2=1
#define RW  do { P1 = (P1 & 0xF9) | 0x02; } while(0)

// 正转(FW):P1.1=1, P1.2=0
#define FW  do { P1 = (P1 & 0xF9) | 0x04; } while(0)

作者: Longan.Wang    时间: 2025-5-17 11:56
woshinh 发表于 2025-4-29 15:37
// 反转(RW):P1.1=0, P1.2=1
#define RW  do { P1 = (P1 & 0xF9) | 0x02; } while(0)

极好,极好,极好
作者: rundstedt    时间: 2025-5-17 16:12
正反转的英文是CW(clockwise)和CCW(counter clockwise)。
作者: rundstedt    时间: 2025-5-17 16:13
正反转的英文是CW(clockwise)和CCW(counter clockwise)。




欢迎光临 (http://www.51hei.com/bbs/) Powered by Discuz! X3.1