《将流水灯程序写入24C02的程序.docx》由会员分享,可在线阅读,更多相关《将流水灯程序写入24C02的程序.docx(3页珍藏版)》请在第一文库网上搜索。
1、/*将数据写入AT24C02然后从24C02中读出*数据在Po口显示,显示效果,为IoOMS*流水灯p0口流水灯的接口P3.6P37为24C()2*的sc和sda接口*/#inc1ude#inc1udeftdefineuintunsignedint#defineucharunsignedcharsbitscI=P36;sbitsda=P37;uchartemp=0xfe,0xfd,0xfbz0xf7,Oxef,0xdfz0xbfz0x7f;voidde1ay()(-opj);_nop_();_nop_();_nop_();-0P-();_nop_();_nop_();_nop_();)void
2、de1ayms(uintt)(uintx,y;for(x=t;x0;x-)for(y=110;y0;y-);)voidstart(void)(sda=1;de1ay();sc1=1;de1ay();sda=O;de1ay();)voidstop(void)(sda=O;deay();sc1=1;de1ay();sda=1;de1ay。;)voidack(void)(uchari;sc1=1;de1ay();whi1e(sda=1)&(i200)i+;sc1=O;de1ay();)voidwrite_byte(uchardat)(uchari;for(i=0;i8;i+)(dat=dat1;sc
3、1=O;de1ay();sda=CY;sc1=1;de1ay();)sc1=O;)ucharread_byte()(uchardatezi;for(i=0;i8;i+)(date=date1;sc1=1;de1ay();if(sda)(date=date0x01;)sc1=O;)returndate;)voidwrite_dat2402(ucharadd,uchardat)向24C02写一个字节进去start();write_byte(OxaO);/器件地址以及写入操作ack();write_byte(add);/写入数据的地址ack();write_byte(dat);/写入的数据ack()
4、;stop();)ucharread_dat2402(ucharadd)从24C02读一个字节进去(uchardat;start();write_byte(0xa0);/器件地址以及写入操作ack();write_byte(add);/读出数据的地址ack();start();write_byte(Oxa1);/器件地址以及读取操作ack();dat=read_byte();stop();returndat;)voidmain()(ucharnumj;whi1e(1)(for(i=0;i8;i+)(num=read_dat2402;Write_dat2402(7,tempi);力口写入24C02de1ayms(100);P0=num;)