版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 【正版授权】 IEC 62037-4:2012+AMD1:2025 CSV EN Passive RF and microwave devices,intermodulation level measurement - Part 4: Measurement of passive intermodulation in coaxial cables
- 【正版授权】 IEC 60315-4:1997/AMD1:2025 FR Amendment 1 - Methods of measurement on radio receivers for various classes of emission - Part 4: Receivers for frequency-modulated sound broad
- 【正版授权】 IEC 61300-1:2022/AMD2:2025 EN Amendment 2 - Fibre optic interconnecting devices and passive components - Basic test and measurement procedures - Part 1: General and guidance
- 2025年高职第二学年(护理学)急救护理综合试题及答案
- 制药工艺用水培训课件
- 制胶车间人员安全培训课件
- 制氧安全5分钟课件
- 工程复工安全培训报告课件
- 房颤消融联合药物治疗方案
- 安全风险分级管控和隐患排查治理体系培训题库与答案解析
- 2025年结算工作总结
- 燃气管道施工事故应对方案
- 采购体系管理
- 1998年农业承包合同样本
- 俄乌战争深度分析俄乌冲突俄罗斯和乌克兰的恩怨情仇动态课件
- 食堂出入库管理制度
- 【《S电子商务公司利用亚马逊平台拓展外贸业务的探析(论文)》17000字】
- 供应商准入管理制度范文
- 建设用地报批服务投标方案(技术方案)
- 台球厅转让合同书
- 社区八一建军节活动方案
评论
0/150
提交评论