24c02读写程序大全

上传人:飞****9 文档编号:130565008 上传时间:2020-04-28 格式:DOC 页数:32 大小:313KB
返回 下载 相关 举报
24c02读写程序大全_第1页
第1页 / 共32页
24c02读写程序大全_第2页
第2页 / 共32页
24c02读写程序大全_第3页
第3页 / 共32页
24c02读写程序大全_第4页
第4页 / 共32页
24c02读写程序大全_第5页
第5页 / 共32页
点击查看更多>>
资源描述

《24c02读写程序大全》由会员分享,可在线阅读,更多相关《24c02读写程序大全(32页珍藏版)》请在金锄头文库上搜索。

1、24c02读写程序大全2C总线的应用(24C02子程序)/ 对24C02的读、写/ extern void DelayMs(unsigned int);/ extern void Read24c02(unsigned char *RamAddress,unsigned char RomAddress,unsigned char bytes);/ extern void Write24c02(unsigned char *RamAddress,unsigned char RomAddress,unsigned char bytes);/*/#defineWriteDeviceAddress 0x

2、a0#defineReadDviceAddress 0xa1#include #include #include /*/sbitSCL=P27;sbitSDA=P26;bitDOG;/*/void DelayMs(unsigned int number) unsigned char temp;for(;number!=0;number-,DOG=!DOG) for(temp=112;temp!=0;temp-) /*/void Start() SDA=1;SCL=1;SDA=0;SCL=0;/*/void Stop() SCL=0;SDA=0;SCL=1;SDA=1;/*/void Ack()

3、 SDA=0;SCL=1;SCL=0;SDA=1;/*/void NoAck() SDA=1;SCL=1;SCL=0;/*/bit TestAck() bit ErrorBit;SDA=1;SCL=1;ErrorBit=SDA;SCL=0;return(ErrorBit);/*/void Write8Bit(unsigned char input) unsigned char temp;for(temp=8;temp!=0;temp-) SDA=(bit)(input&0x80);SCL=1;SCL=0;input=input1;/*/void Write24c02(unsigned char

4、 *Wdata,unsigned char RomAddress,unsigned char number) Start();Write8Bit(WriteDeviceAddress);TestAck();Write8Bit(RomAddress);TestAck();for(;number!=0;number-) Write8Bit(*Wdata);TestAck();Wdata+;Stop();DelayMs(10);/*/unsigned char Read8Bit() unsigned char temp,rbyte=0;for(temp=8;temp!=0;temp-) SCL=1;

5、rbyte=rbyte1;rbyte=rbyte|(unsigned char)(SDA);SCL=0;return(rbyte);/*/void Read24c02(unsigned char *RamAddress,unsigned char RomAddress,unsigned char bytes) /unsigned char temp,rbyte;Start();Write8Bit(WriteDeviceAddress);TestAck();Write8Bit(RomAddress);TestAck();Start();Write8Bit(ReadDviceAddress);Te

6、stAck();while(bytes!=1) *RamAddress=Read8Bit();Ack();RamAddress+;bytes-;*RamAddress=Read8Bit();NoAck();Stop();单片机应用24c02的读写程序电子工匠 发表于 2007-1-4 22:33:07 ;-从24C02整组读数据RD_INI:LCALLDELAYRD_AREA:LCALLDELAYLCALLSTARTLCALLDELAYLCALLWRITE;24C02信息的读入LCALLDELAYLCALLACKLCALLDELAYJCRD_AREAMOVR2,#8CLRP1.7;起始地址为0

7、0ADDR_0:LCALLDELAYLCALLDELAYSETBP1.6LCALLDELAYLCALLDELAYCLRP1.6LCALLDELAYDJNZR2,ADDR_0LCALLACKLCALLDELAYJCRD_AREALCALLDELAYLCALLSTARTMOVR0,#SAVE0MOVR3,#8;6个字节LCALLDELAYLCALLREADLCALLDELAYLCALLACKJCRD_AREARD_R_0:LCALLDELAYLCALLDELAYLCALLRD_INFOLCALLDELAYINCR0DJNZR3,RD_R_1lcallack_2lcalldelayLCALLSTOP

8、RETrd_r_1:lcallack_1sjmprd_r_0;-向24C02整组写数据WR_INI:LCALLDELAYLCALLSTARTLCALLDELAYLCALLWRITELCALLDELAYLCALLACKLCALLDELAYJCWR_INICLRP1.7MOVR2,#8WR_W_0:LCALLDELAY;写地址SETBP1.6LCALLDELAYLCALLDELAYCLRP1.6LCALLDELAYDJNZR2,WR_W_0LCALLDELAYLCALLACKLCALLDELAYJCWR_INIMOVR0,#SAVE0MOVR3,#8;6个字节WR_W_1:LCALLWR_INFO

9、LCALLDELAYLCALLACKLCALLDELAYJCWR_INIINCR0DJNZR3,WR_W_1LCALLDELAYLCALLSTOPRET;-24C02启动START:SETBP1.7SETBP1.6LCALLDELAYCLRP1.7LCALLDELAYCLRP1.6RET;-24C02读命令字;片选为00;-READ:MOVA,#10100001BMOVR2,#8RD1:RLCAMOVP1.7,CSETBP1.6LCALLDELAYCLRP1.6LCALLDELAYDJNZR2,RD1RET;-24C02写命令字;片选为00;-WRITE:MOVA,#10100000BMOVR2,#8WR1:RLCAMOVP1.7,CSETBP1.6LCALLDELAYCLRP1.6CLRP1.7LCALLDELAYDJNZR2,WR1RET;-24C02结束命令字STOP:CLRP1.7LCALLDELAYSETBP1.6LCALLDELAYSETBP1.7LCALLDELAYCLRP1.6RET;-24C02的应答信息ACK:SETBP1.7SETBP1.6LCALLDELAYmova,p1

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 中学教育 > 教学课件 > 初中课件

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号