




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年石家庄市税务系统遴选面试真题附带题目详解含答案
- 2024年移动互联网行业市场前景及投资研究报告-培训课件
- 麻醉学中级题库(附答案)
- 老年居家安全课件
- 老师职业介绍课件下载
- 2025年搬运车行业市场突围建议及需求分析报告
- 铲车司机职业病防治及健康保障协议
- 财务分析智能财务咨询顾问解决方案软件合同
- 厂房搬迁与智能化生产系统合同
- 高新技术企业厂房租赁中介服务合同样本
- 《种衣剂知识培训》课件
- 特种设备安全管理的应急预案编制
- 2024年重大事故隐患判定标准考核试题
- 人教版八年级英语上册 Unit 2 Section A 教案(同步教学设计)
- 高压环网柜施工方案
- 报销医保委托书
- 氨水培训课件
- 2025-2030年中国汽车模具产业运行状况及前景趋势分析报告
- 2025年中远海运集团招聘笔试参考题库含答案解析
- 《中学心理危机干预体系构建》
- 人工智能模拟题
评论
0/150
提交评论