文档介绍:/***************writer:******************/#include<>#include<>#defineuintunsignedint#defineucharunsignedcharbitI2C_Busy,NO_Ack,Bus_Fault,point;ucharbdataa;sbitLSB=a^0;sbitMSB=a^7;sbitSDA=P3^3;sbitSCL=P3^2;ucharArray[]={'0','1','2','3','4','5','6','7','8','9'};mand_data[]= 0xac,0x00,0xee,0xa1,0x00,0x00,0xa2,0x00,0x00,0xaaucharPrompt[]="Waitingforawhile...\r";uchari;voidDelayMS(uintms) uchari; while(ms--) for(i=0;i<120;i++);voidSendStop() SDA=0; SCL=1; _nop_(); SDA=1; I2C_Busy=0;voidSendByte(ucharwd) uchari; a=wd; for(i=0;i<8;i++) SCL=0; _nop_(); _nop_(); SDA=MSB; a<<=1; _nop_(); _nop_(); SCL=1; _nop_(); _nop_(); SCL=0; SDA=1; SCL=1; _nop_(); _nop_(); if(!SDA) SCL=0; _nop_(); _nop_(); else NO_Ack=1; SCL=0; _nop_(); _nop_();voidMaster(ucharslave_addr) I2C_Busy=1; NO_Ack=0; Bus_Fault=0; if(!SCL||!SDA) Bus_Fault=1; else SDA=0; _nop_(); _nop_(); SCL=0; _nop_(); _nop_(); SendByte(slave_addr);ucharRecvByte(t) uchari,rcv_data; for(i=0;i<8;i++) SDA=1; SCL=1; _nop_(); LSB=SDA; if(i<7) a<<=1; _nop_(); SCL=0; _nop_(); t==1) SDA=1; else SDA=0; SCL=1; _nop_(); SCL=0; SDA=1; _nop_(); rcv_data=a; returnrcv_data; voidSendData(ucharslave_address,ucharstart,ucharend) Master(slave_address); for(i=start;i<=end;i++) mand_data[i]); SendStop();voidInitialiseSerialPort() TMOD=0x20; TH1=0xfd; SCON=0x50; TR1=1;voidSendCharToSerialPort(ucharch) SBUF=ch; while(!TI); TI=0;voidSendTe