版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- AI在国际标准舞中的应用
- 2026年加油站手机扫码支付安全风险培训
- 2026年幼儿个体发展档案建立与分析方法
- 2025贵州省中考语文真题(原卷版)
- 2025湖南省长沙市中考地理试题(原卷版)
- 上海立达学院《安全工程信息技术与管理》2025-2026学年第一学期期末试卷(B卷)
- 2026年某公司风险管理实施细则
- 2026年小学数学教育与英语教育的有机结合
- 2026年数字货币发行流通安全风险与监管措施
- 2026年钢结构安装高处作业应急处理指南
- 2026年中级社会工作者《社会工作综合能力》考试押题密卷带答案详解(模拟题)
- 焊接质量检测技术全套课件
- GB/T 32580.4-2026轨道交通地面装置高压交流开关设备及互感器第4部分:电压互感器
- 儿童狂犬病暴露后预防专家共识(2025年版)
- 2026年广东交通职业技术学院单招职业技能测试题库及完整答案详解
- 肿瘤终末期患者便秘与腹泻症状管理方案
- 2025-2030中国抽水蓄能行业深度评估及竞争格局展望分析研究报告
- 2026届语文二轮复习:专题03 文学评点题(复习讲义)(解析版)
- 2025年超星尔雅学习通《口腔医学导论》考试备考题库及答案解析
- 物业维修管理流程标准操作
- 雨课堂在线学堂《三江源生态》单元考核测试答案
评论
0/150
提交评论