void Send_N_byte(uint8 Sla,uint8 Subaddr,uint8 Data) { uint8 ii=0; I2C0CONCLR =(1<<3); I2C0CONSET = (1<<5); I2C0DAT = Sla&0xfe; // 和屏蔽部分对照,改成这样,第2步读到的状态位正常--18,使用屏蔽部分,第2步读到的状态位为 20,不是18 // while ( ((I2C0STAT & 0xf8)!=0x08) && ((I2C0STAT & 0xf8)! =x10) ); // && (ii++<0xff) ); // temptemp = I2C0STAT; // I2C0DAT = 0x34; I2C0CONCLR = 1<<3; while ( ((I2C0STAT & 0xf8)!=0x18) && ((I2C0STAT & 0xf8)!=0x20) );// && (ii++<0xffff) ); // temptemp = I2C0STAT; // if((I2C0STAT & 0xf8)!=0x18) // { I2C0DAT = Subaddr; I2C0CONCLR = 1<<3; // } // else // { // I2C0CONCLR =0x28; // I2C0CONSET=1<<4; // return ; // } // ii=0; while ( ((I2C0STAT & 0xf8)!=0x28) && ((I2C0STAT & 0xf8)!=0x30) && (ii++<0xff) ); temptemp = I2C0STAT; //该句测试用 状态变为08H,不懂为什么,求助 if(((I2C0STAT & 0xf8)!=0x28)) { I2C0DAT = Data; I2C0CONCLR = 1<<3; ii=0; } else { I2C0CONCLR =0x28; I2C0CONSET=1<<4; return ; } while ( ((I2C0STAT & 0xf8)!=0x28) && ((I2C0STAT & 0xf8)!=0x30) && (ii++<0xffff) ); temptemp = I2C0STAT; I2C0CONCLR =0x28; // 清零 SI 和 STA I2C0CONSET=1<<4; // 1<<3 he 1<<5 temptemp = I2C0STAT; } |