版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、/* AT24C64C语言程序 copyrightlance */ #include "c8051F020.h"#include "24C256.h"#include "LCD_display.h" sbit ISCL = P14;sbit ISDA = P13; /* I2c Wait Wait for some time to get proper I2C timing */ void I2cWait(void) / unsigned int i=10; /24C64 unsigned int i=5;/24C256 while(
2、i-); /* i2c start condition SDA 1-0 while SCL=1 */ void I2cStart(void) ISDA=1; ISCL=1; I2cWait(); ISDA=0; I2cWait(); ISCL=0; I2cWait(); /* I2c sotp condition SDA=0-1 while SCL=1 */ void I2cStop(void) ISDA=0; I2cWait(); ISCL=1; I2cWait(); ISDA=1; I2cWait(); /* I2c Init Initialize I2C interface Releas
3、e I2c BUS * void I2cInit(void) ISDA=1; ISCL=1; I2cWait(); */ /* I2c SentByte master transfer data to slave and return acknowledge bit don't include<intrins.h> */ bit I2cSentByte(unsigned char bytedata) unsigned char i; bit ack; for(i=0;i<8;i+) if(bytedata & 0x80) ISDA=1; else ISDA=0
4、; bytedata<<=1; I2cWait(); ISCL=1; I2cWait(); ISCL=0; I2cWait(); ISDA=1; I2cWait(); ISCL=1; I2cWait(); ack=ISDA; ISCL=0; I2cWait(); return ack; /* I2c ReceiveByte slave trransfer data to master */ unsigned char I2cReceiveByte(void) unsigned char i; unsigned char bytedata=0; ISCL=0; I2cWait();
5、for(i=0;i<8;i+) ISCL=1; I2cWait(); bytedata=bytedata<<1; if(ISDA=1) bytedata = bytedata|0x01; I2cWait(); ISCL=0; I2cWait(); return bytedata; /* I2c SendAcknowledge Master send acknowledge bit to slave acknowledge="0",non-acknowledge="1" */ void SendAcknowledge(bit ack) I
6、SDA=ack; ISCL=1; I2cWait(); ISCL=0; /* 24c64 WriteByte addr:0-8192 value:数据 */ void _24c64WriteByte(unsigned int addr,unsigned char value) I2cStart(); I2cSentByte(0xA0); I2cSentByte(addr>>8); /送高位地址 I2cSentByte(addr&0xff); /送低位地址 I2cSentByte(value); I2cStop(); delay1ms(15); /* 24c64 WriteM
7、ulti page:0-255 count:要写入的数个数 */void _24c64WriteMulti(unsigned int page,unsigned char count,unsigned char *SenBuf) unsigned char i; unsigned int addr=page*32; I2cStart(); I2cSentByte(0xa0); I2cSentByte(addr>>8); /送高位地址 I2cSentByte(addr&0x00ff); /送低位地址 for(i=0;i<count;i+) I2cSentByte(Sen
8、Bufi); I2cStop(); delay1ms(15); /* 24c64 ReadByte addr:0-8192 */ unsigned char _24c64ReadByte(unsigned int addr) unsigned char temp; I2cStart(); I2cSentByte(0xa0); I2cSentByte(addr>>8); /送高位地址 I2cSentByte(addr&0x00ff); /送低位地址 I2cStart(); I2cSentByte(0xa1); temp=I2cReceiveByte(); SendAcknowledge(1); I2cStop(); return temp; /* 24c64 ReadMulti page:0-256,count0-32 count:要读出的数的个数 */ void _24c64ReadMulti(unsigned int page,unsigned char count,unsigned char *RedBuf)
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 数据加密技术及应用研究
- 数据备份恢复方案设计与实施技术要领
- 2026年教育心理学在实践中的应用试题
- 2026年医学知识竞赛试题及答案详解
- 2026年健康管理运动健身科学方法与实践题集
- 2026年电子商务运营策略网店运营方案题库
- 2026年国家司法考试考点专项模拟试题
- 2026年航空航天项目管理核心考点题
- 2026年医学专业研究生入学考试题库全解
- 2026年大学英语四级考试阅读填空翻译练习题型突破训练
- 2025年江苏省苏州市中考数学模拟试卷(含答案)
- GB/T 45133-2025气体分析混合气体组成的测定基于单点和两点校准的比较法
- 九年级下册语文必背古诗文(字帖描红)
- 北京市行业用水定额汇编(2024年版)
- 婚内财产协议书标准版
- 基于大数据的金融风险评估模型构建
- 供应链与生产制造L1-L4级高阶流程规划框架 相关两份资料
- 光伏电站施工管理要点培训
- 国际贸易合同履行中的运输保险索赔程序与操作指南
- 龙泽滴灌带生产项目可行性研究报告
- 运动系统疾病
评论
0/150
提交评论