




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 焦作空压机采购合同范本
- 风电运维总包合同协议书
- 甲方转乙方猎头合同范本
- 物料设计制作合同协议书
- 网络平台会员协议书范本
- 特种车辆雇佣协议书模板
- 美业学徒合同协议书模板
- 离婚法院调解协议书范本
- 项目文化墙设计合同范本
- 银行个性化分期协议合同
- GB 20664-2006有色金属矿产品的天然放射性限值
- 小学数学课堂教学有效性的课件
- 北理工概率与数理统计-往年考题-课件
- 2022年北京公共交通控股(集团)有限公司招聘笔试试题及答案解析
- 江西省宜春市各县区乡镇行政村村庄村名明细及行政区划代码
- 露天煤矿生产安全安全事故应急预案
- 土木工程概论全套课件完整版电子教案最新板
- 超星尔雅学习通《声光影的内心感动电影视听语言(四川大学)》章节测试答案
- 上教社深圳版小学英语1-6年级单词汇总
- 微生物细胞的破碎表现和测定
- 医养结合养老院项目可行性研究报告写作参考范文
评论
0/150
提交评论