最近写一个硬件I2C驱动,程序中调试的错误码是error C237: : function already has a body
/*代码如下(未完工)*/
/*定义I2C控制寄存器命令*/
#define wait 0x80
#define start 0x81
#define txdc 0x82
#define rack 0x83
#define rxdc 0x84
#define tack 0x85
#define stop 0x86
#define start_txdc_rack 0x89
#define txdc_rack 0x8a
#define rxdc_ack 0x8b
#define rxdc_nak 0x8c
/*定义I2C主机读写控制指令*/
#define rd 1
#define wt 0
/*定义I2C主机状态命令*/
#define ack_t 0x01
#define ack_r 0x02
i2c_init(uc i2c_s_add,uc rw) /*片内I2C硬件驱动器初始化函数*/
{
iuc combuf;
I2CCFG=0xfe; /*启动I2C,设置本机为主机,波特率为86400*/
combuf=i2c_s_add<<1; /*器件地址左移1位*/
if(rw && combuf%2) /*如果指令为读,且左移过后地址合法(0-127之间)*/
{
combuf|=0x01; /*将最低位设置为1*/
}
whl(I2CMSST & ack_r) /*等待标志位*/
{
;
}
I2CMSST |= 0x02; /*恢复标志位*/
I2CMSCR=start;
I2CTXD=combuf;
}
/*取消宏定义*/
#undef ack_t
#undef ack_r
#undef rd
#undef wt
#undef wait
#undef start
#undef txdc
#undef rack
#undef rxdc
#undef tack
#undef stop
#undef start_txdc_rack
#undef txdc_rack
#undef rxdc_ack
#undef rxdc_nak
#undef SCL
#undef SDA
|