24c02存储多个数据_第1页
24c02存储多个数据_第2页
24c02存储多个数据_第3页
24c02存储多个数据_第4页
24c02存储多个数据_第5页
已阅读5页,还剩4页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

24c02存储多个数据24c02存储多个数据#include<reg51.h>#include<intrins.h>#defineuintunsignedint#defineuchar#include<reg51.h>#include<intrins.h>#defineuintunsignedint#defineucharunsignedcharsbitsda=P2^0;//IOsbitscl=P2^1;//此为待写入24c02重复的。charcodemusic[]={0x55,0xaa,0x0f,0xf0,0x55,0xaa,0x0f,0xf0,0x55,0xaa,0x0f,0xf0,0x55,0xaa,0x0f,0xf0,0x55,0xaa,0x0f,0xf0,0x55,0xaa,0x0f,0xf0,0x55,0xaa,0x0f,0x55,0xaa,0x0f,0xf0,0x55,0xaa,0x0f,0xf0,0x55,0xaa,0x0f,0xf0,0x55,0xaa,0x0f,0xf0,0x55,0xaa,0x0f,0xf0,0x55,0xaa,0x0f,0xf0,0x55,0xaa,0x0f,0xf0,0x55,0xaa,0x0f,0xf0,0x55,0xaa,0x0f,0xf0,0x55,0xaa,0x0f,0xf0};//由于最终还要讲这些数据读出送到P1P1口相连led15ucharuchardatabuffer[100];//24c02delay(delay(unsignedintm){unsignedintn,p;for(n=m;n>0;n--)for(p=125;p>0;p--);}voidvoidnop{_nop_;_nop_;_nop_;_nop_;}/////////24C02读写驱动程序/////////24C02读写驱动程序////////////////////voidvoiddelay1(unsignedintm){unsignedunsignedintn;for(n=0;n<m;n++);}voidvoidinit//24c02初始化子程序{scl=scl=1;nop;sda=1;nop;}voidvoidstart//I2C{sda=1;sda=1;nop;scl=1;nop;sda=0;nop;nop;sclscl=0;nop;}voidvoidstop//I2C{sda=0;nop;sda=0;nop;scl=1;nop;sda=1;nop;}voidvoidwritebyte(unsignedcharj)//写一个字节{unsignedchari,unsignedchari,temp;temp=j;for(i=0;i<8;i++){temp=temp<<1;scl=0;nop;sda=CY;nop;scl=1;nop;//tempCY//sdascl}}scl=0;nop;sda=1;nop;unsignedunsignedcharreadbyte//读一个字节{unsignedchari,j,unsignedchari,j,k=0;scl=0;nop;sda=1;for(i=0;i<8;i++){nop;scl=1;nop;if(sda==1)j=1;elseelsej=0;kj=0;k=(k<<1)|j;scl=0;}nop;return(k);}voidclock{//I2Cunsignedchari=0;scl=1;nop;while((sdawhile((sda==1)&&(i<255))i++;scl=0;nop;}////////从////////从24c02的地址address中读取一个字节数据/////unsignedcharread24c02(unsignedcharaddress){unsignedchari;start;writebyte(0xa0);clock;writebyte(address);clock;start;unsignedchari;start;writebyte(0xa0);clock;writebyte(address);clock;start;writebyte(0xa1);clock;i=readbyte;stop;delay1(100);return(i);}//////向//////向24c02的address地址中写入一字节数据info/////voidwrite24c02(unsignedcharaddress,unsignedcharinfo){start;writebyte(0xa0);clock;start;writebyte(0xa0);clock;writebyte(address);writebyte(address);clock;writebyte(info);clock;stop;clock;writebyte(info);clock;stop;delay1(5000);//这个延时肯定要足够长,否则会出错。由于24c02在从sda上取得数据后,还需要肯定时间的烧录过程。}voidvoidmain{ucharadd,i,j,m;init;P1=0X55;while(add!=//24C02sizeof(music)){write24c02(0x00+add,write24c02(0x00+add,music[add]);add++;if(add%4==0)P1=~P1;}P1=0X00;//到此为止,向//到此为止,向24C02中写入数据的过程均已完毕。下面的程序为附加的。//P1led的亮灭来检验写入的数据是否正确。while为附加的。//P1led的亮灭

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论