版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- DB33T 828.7-2011 社会单位消防安全标准化建设指南 第7部分:小场所
- 红色2026年春季征兵宣传教育
- 绿色简约小清新新中式工作总结计划
- 构网型储能安全白皮书
- 某塑料制品厂安全生产细则
- 新课标人教版二下语文第六单元达标测试题(一)
- 2026福建福州新区(长乐区)新任教师(教育部直属师范大学公费师范生)招聘1人备考题库附参考答案详解(巩固)
- 2026福建宁德市蕉城区教育局补充招聘紧缺急需人才6人备考题库(三)附参考答案详解(综合卷)
- 2026山东济南市中心医院招聘卫生高级人才(控制总量)10人备考题库及参考答案详解1套
- 2026西藏拉萨发展集团有限公司招聘46人备考题库附参考答案详解ab卷
- 2023版马克思主义基本原理课件 专题八 共产主义论
- 发电工程钢筋铁件加工制作施工投标文件
- 体育旅游课件第五章体育旅游目的地
- 滑坡地质灾害应急调查报告
- 制氢装置转化炉设计简介
- 大学二级管理办法
- 线材基础知识
- LD 52-1994气瓶防震圈
- GB/T 3375-1994焊接术语
- GB/T 11546.1-2008塑料蠕变性能的测定第1部分:拉伸蠕变
- 生物学酶工程-酶分子定向进化课件
评论
0/150
提交评论