程序如下: void TaskStart(void *pdata) { uint8 i; uint8 DataBuf[11];
pdata = pdata; /* 避免编译警告 */
TargetInit(); /* 目标板初始化 */ IODIR |= BEE; /* 设置蜂鸣器为输出*/ PINSEL0 = (PINSEL0 & 0xcffff3ff); /* 管教选择模块初始化 */ IOSET = BEE; for (i = 0; i < 10; i++) { DataBuf[i + 1] = i + '0'; } DataBuf[0] = 0; /* 扩展地址 */ I2cWrite(CSI24WC02, DataBuf, 11);
OSTimeDly(OS_TICKS_PER_SEC / 100 + 1); I2cRead(CSI24WC02, DataBuf, DataBuf, 1, 10); for (i = 0; i < 10; i++) { if (DataBuf != (i + '0')) { break; } } if ( i < 10) { /* 读写错误 */ while (1) { IOCLR = BEE; OSTimeDly(OS_TICKS_PER_SEC / 5); IOSET = BEE; OSTimeDly(OS_TICKS_PER_SEC / 5); } } else { /* 读写成功 */ IOCLR = BEE; OSTimeDly(OS_TICKS_PER_SEC); IOSET = BEE; while (1); } }
疑问:前面的程序如此赋值 DataBuf[i + 1] = i + '0';也就是说 DataBuf[1] = 0 ...... DataBuf[10] = 9 那么if (DataBuf != (i + '0'))当i=0时该语句不成立,其他情况也就是i=1、...9时,该语句都成立,那么就会执行错误处理,不知为何如此编写程序!!!!!!!!!!! |