国防大学 发表于 2013-3-10 10:01:38

关于C51中的带参宏的用法,希望高手能给与解答

我在KEI环境下
#include<reg52.h>

typedef unsigned char u8;

#define SPI_MASTER                1

sfr SPCTL       = 0xCE;
#define MSTR                = 0x10;
#define SSIG                = 0x80;

#define AssignBit(type ,flag , which_bit, val) ((((type)which_bit)&((type)val)) | ((flag)&(~((type)which_bit))))

#define SPI_SetMode(mode)                                        { AssignBit(u8, SPCTL, (u8)(MSTR | SSIG), ((mode<<4) | (mode<<7)) ); }

void SPI_Init(void)
{
        SPI_SetMode(SPI_MASTER);       
}

也就是我定义了一个带参宏AssignBit,然后又根据AssignBit定义了一个带参宏 SPI_SetMode,然后使用SPI_SetMode进行初始化,可是编译器老是报错
MAIN.C(40): error C141: syntax error near '='
MAIN.C(40): error C141: syntax error near ';'
MAIN.C(40): error C141: syntax error near '|'
MAIN.C(40): error C141: syntax error near ')'
MAIN.C(40): error C190: '&': not an lvalue
MAIN.C(40): error C141: syntax error near ')'
MAIN.C(40): error C141: syntax error near '='
MAIN.C(40): error C141: syntax error near ';'
MAIN.C(40): error C141: syntax error near '|'
MAIN.C(40): error C141: syntax error near ')'

希望高手能指点一下

国防大学 发表于 2013-3-10 10:02:09

自己先顶一下

sgzzour 发表于 2013-3-10 10:11:25

我也帮你顶一下。。、。

国防大学 发表于 2013-3-10 10:17:16

我在VC6.0上调试都可通过,是不是KEIL编译器的问题??

yklstudent 发表于 2013-3-10 10:47:39

国防大学 发表于 2013-3-10 10:17 static/image/common/back.gif
我在VC6.0上调试都可通过,是不是KEIL编译器的问题??

VC6.0上可以调试通过?结果正确????
不知道怎么调的
#define MSTR                = 0x10;
#define SSIG                = 0x80;
这里的 = ;放进去能没有问题?????
页: [1]
查看完整版本: 关于C51中的带参宏的用法,希望高手能给与解答