欢迎来到天天文库
浏览记录
ID:48368655
大小:63.50 KB
页数:14页
时间:2019-11-28
《I2C总线协议时序编程I2Cbusprotocol,sequentialprogramming.doc》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、I2C总线协议时序编程(I2Cbusprotocol,sequentialprogramming)I2Cbusprotocol,scqucntialprogramming—AT24C01--_COPYRIGHT(c)2008BYbill.—ALL,RIGHTS,RESERVED—FileName:I2C.hAuthor:billCreated:2007/12/12Modified:NORevision:keilv3・0Fosc=12Mttifndef_I2C_Httdefine_I2C_Httinclude#defineui
2、ntunsignedint#defineucharunsignedcharSbitSda=,〃P1〃,0;SbitSc>,〃P1〃,J;SbitWp二,〃Pl〃,辽;/C+CV.+slzslzslzslzslzslz//不不不不不不不不不不不不不不不不不不不不不不不不不不0l/d丄L不不不不不不不不不不/VoidStart(void){Sda二〃1〃〃;Scl二〃1〃〃;_nop_0;_nop_0;_nop_0;_nop_0;Sda=〃0〃〃nop_();nop_();nop_();/slzJ4-Z*VX^lz^lz^lz^lz^lzsf^//
3、不不平平不不平平不不不不平不不不0LOU不平平平不不平平平平平不不不不不不/VoidStop(void){Sda二〃0〃〃;Scl二〃1〃〃;_nop_();_nop_();_nop_();_nop_();Sda二〃1〃〃;nop_();nop_();nop_();/AcI”vizvizvizvizviz^£z^£z%fz%fz%fz%fz%fzvf^vf^%fz%fz%fz//r(l4、_nop_();nop_0;nop_0;_nop0;Scl二〃1_nop_();_nop_();_nop_();Scl二〃0〃〃NoAck***************************//***************VoidNoAck(void)Sda=_nop_();_nop_();_nop_();_nop_();C1H〃〃Scl二1_nop_();_nop_();nop_();Scl二〃0〃〃;Sendachar***************************//*****************VoidSend(ucharD5、ata)//senddatatosendsubroutineDatacharacterUcharBitCount二〃8〃;//forentrancetosendthecharacterDataUchartemp;//returnvalueDoTemp二"Data";Scl二〃0〃〃;nop_();nop_();_nop_();If(temp&0x80)Sda二〃1〃〃;ElseSda=〃0〃〃;Scl二〃1〃〃;Temp二"Data"<<1;Data二"temp";BitCount--;}while(BitCount);Scl二〃0〃〃;}Rea6、dachar*********************//slzslz%Iz/xtxxt%>1%>1%>1%>1%>1%UcharRead(void)//noentrance{//exportreaddatatempUchartemp二〃0〃〃;Uchartempl=O;UcharBitCount二〃8〃〃;Sda二〃1〃〃;do{scl二〃0〃;-nop_0;-nop_0;-nop_0;-nop_0;scl二〃1〃;-nop_0;-nop_0;-nop_0;-nop_0;if(sda)temp二"temp0x01〃;elsetemp二"temp7、"&Oxfe;if(bitcount一1)tempi二temp<<1;temp二"tempi";bitcount;while(bitcount);returntemp./***************************writeachartorome,************************/voidwrrorom(uchardata[],ucharaddress,ucharnum)//写多字节函数{//入口为要写的数组data[]uchari二0;//地址addressuchar*pdata;//字节数numpdata二"data8、";start();send(OxaO);ack();send(address);ack();for(i二0;i
4、_nop_();nop_0;nop_0;_nop0;Scl二〃1_nop_();_nop_();_nop_();Scl二〃0〃〃NoAck***************************//***************VoidNoAck(void)Sda=_nop_();_nop_();_nop_();_nop_();C1H〃〃Scl二1_nop_();_nop_();nop_();Scl二〃0〃〃;Sendachar***************************//*****************VoidSend(ucharD
5、ata)//senddatatosendsubroutineDatacharacterUcharBitCount二〃8〃;//forentrancetosendthecharacterDataUchartemp;//returnvalueDoTemp二"Data";Scl二〃0〃〃;nop_();nop_();_nop_();If(temp&0x80)Sda二〃1〃〃;ElseSda=〃0〃〃;Scl二〃1〃〃;Temp二"Data"<<1;Data二"temp";BitCount--;}while(BitCount);Scl二〃0〃〃;}Rea
6、dachar*********************//slzslz%Iz/xtxxt%>1%>1%>1%>1%>1%UcharRead(void)//noentrance{//exportreaddatatempUchartemp二〃0〃〃;Uchartempl=O;UcharBitCount二〃8〃〃;Sda二〃1〃〃;do{scl二〃0〃;-nop_0;-nop_0;-nop_0;-nop_0;scl二〃1〃;-nop_0;-nop_0;-nop_0;-nop_0;if(sda)temp二"temp0x01〃;elsetemp二"temp
7、"&Oxfe;if(bitcount一1)tempi二temp<<1;temp二"tempi";bitcount;while(bitcount);returntemp./***************************writeachartorome,************************/voidwrrorom(uchardata[],ucharaddress,ucharnum)//写多字节函数{//入口为要写的数组data[]uchari二0;//地址addressuchar*pdata;//字节数numpdata二"data
8、";start();send(OxaO);ack();send(address);ack();for(i二0;i
此文档下载收益归作者所有