首页 at24c512驱动程序

at24c512驱动程序

举报
开通vip

at24c512驱动程序at24c512驱动程序 2008-06-27 09:09 AT24C512Çý??#include #include #include #include #define BAUDRATE 9600 #define SYSCLK 11059200 #define uchar unsigned char #define uint unsigned int #define _Nop() _nop_(),_nop_(),_nop_(),_nop_() /*??Òå?ÕÖ?Áî*/ uchar s...

at24c512驱动程序
at24c512驱动程序 2008-06-27 09:09 AT24C512Çý??#include #include #include #include #define BAUDRATE 9600 #define SYSCLK 11059200 #define uchar unsigned char #define uint unsigned int #define _Nop() _nop_(),_nop_(),_nop_(),_nop_() /*??Òå?ÕÖ?Áî*/ uchar save_buf[7]; sbit WP =P1^0; sbit SCL =P1^1; sbit SDA =P1^2; sbit led =P3^5;void IICpwrite(unsigned char highaddress,unsigned char lowaddress,unsigned char *psr); void IICpread(unsigned char highaddress,unsigned char lowaddress,unsigned char *dst); void ByteWrite(unsigned char bytedata,unsigned char highaddress,unsigned char lowaddress); uchar ByteRead(unsigned char highaddress,unsigned char lowaddress); void IICWriteByte(unsigned char sendbyte); void IICWriteByte(unsigned char sendbyte); uchar IICReadByte(void); void IICStart(void); void IICStop(void); void IICAck(void); void Noack(void); void main() { WP=0;_Nop();_Nop();_Nop();_Nop();_Nop();_Nop();_Nop();_Nop();led=0 ; save_buf[0]=1; save_buf[1]=2; save_buf[3]=3; IICpread(0x00,0x00,save_buf); // IICpwrite(0x00,0x00,save_buf); // save_buf[0]=ByteRead(0x00,0x00); // ByteWrite(save_buf[0],0x00,0x02); while(1);} /*******************Ò?ÃæÐ?Êý?Ý*********************/ void IICpwrite(unsigned char highaddress,unsigned char lowaddress,unsigned char *psr) { int i; // WP=0;_nop_();_nop_();_nop_();_nop_(); IICStart(); IICWriteByte(0xa0); IICWriteByte(highaddress); IICWriteByte(lowaddress); for(i=0;i<5;i++) { IICWriteByte(*psr++); } IICStop(); // WP=1; }/*******************Ò?Ãæ?ÁÊý?Ý********************/ void IICpread(unsigned char highaddress,unsigned char lowaddress,unsigned char *dst) { int i;//WP=0; IICStart(); IICWriteByte(0xa0); IICWriteByte(highaddress); IICWriteByte(lowaddress); IICStart(); IICWriteByte(0xa1); for(i=0;i<5;i++) { *dst++=IICReadByte(); if(i<4) IICAck(); else Noack(); } IICStop(); // WP=1; } /*******************Ëæ?úÐ?Êý?Ý*********************/ void ByteWrite(unsigned char bytedata,unsigned char highaddress,unsigned char lowaddress) { IICStart(); IICWriteByte(0xa0); IICWriteByte(highaddress); IICWriteByte(lowaddress); IICWriteByte(bytedata); IICStop(); // Delay2(10000); }/**********************Ëæ?ú?ÁÊý?Ý**********/ uchar ByteRead(unsigned char highaddress,unsigned char lowaddress) { unsigned char ReadByte; IICStart(); IICWriteByte(0xa0); IICWriteByte(highaddress); IICWriteByte(lowaddress); IICStart(); IICWriteByte(0xa1); ReadByte=IICReadByte(); IICStop(); return(ReadByte); }/*******************ÏòIIC×ÜÏßÐ?Êý?Ý*********************/ void IICWriteByte(unsigned char sendbyte) { unsigned char j; // SCL=0; for(j=8;j>0;j--) { sendbyte<<=1; //ÎÞÂÛC51ÔõÑùʵÏÖÕâ?ö?Ù×???Ê?ÖÕ?áÊ?CY=sendbyte^7; SDA=CY; SCL=1; SCL=0; } SDA=1; SCL=1; while(SDA); SCL=0; } /**********************?ÓIIC×ÜÏßÉÏ?ÁÊý?Ý×Ó?ÌÐò**********/ uchar IICReadByte(void) { uchar receivebyte=0,i=8; // SCL=0; SDA=1; for(i=0;i<8;i++) { receivebyte=(receivebyte<<1)|SDA; SCL=1; SCL=0; } SDA=1;SCL=0; return(receivebyte); }/*****************Æô??×ÜÏß**********************/ void IICStart(void) { SDA=1; /*??ËÍÆðÊ?Ìõ?þµÄÊý?ÝÐźÅ*/ _Nop(); SCL=1; _Nop(); /*ÆðÊ?Ìõ?þ??Á?Ê??ä?óÓÚ4.7us,ÑÓÊ?*/ _Nop(); _Nop(); _Nop(); _Nop(); SDA=0; /*??ËÍÆðÊ?ÐźÅ*/ _Nop(); /* ÆðÊ?Ìõ?þËø??Ê??ä?óÓÚ4?Ìs*/ _Nop(); _Nop(); _Nop(); _Nop(); SCL=0; /*Ç?×?I2C×ÜÏß??×?????ËÍ?ò?ÓÊÕÊý?Ý */ _Nop(); _Nop(); _Nop(); _Nop(); }/*****************Í?Ö?IIC×ÜÏß****************/ void IICStop(void) { SDA=0; /*??ËÍ?áÊøÌõ?þµÄÊý?ÝÐźÅ*/ _Nop(); /*??ËÍ?áÊøÌõ?þµÄÊ?ÖÓÐźÅ*/ SCL=1; /*?áÊøÌõ?þ??Á?Ê??ä?óÓÚ4?Ìs*/ _Nop(); _Nop(); _Nop(); _Nop(); _Nop(); SDA=1; /*??ËÍI2C×ÜÏß?áÊøÐźÅ*/ _Nop(); _Nop(); _Nop(); _Nop(); } void IICAck(void) { SDA=0;_Nop();_Nop();_Nop();_Nop(); SCL=1;_Nop();_Nop();_Nop();_Nop();_Nop(); SCL=0;_Nop();_Nop(); // SDA=1;_nop_(); } void Noack(void) { SDA=1;_Nop();_Nop();_Nop();_Nop(); SCL=1;_Nop();_Nop();_Nop();_Nop();_Nop(); SCL=0;_Nop();_Nop(); }
本文档为【at24c512驱动程序】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
该文档来自用户分享,如有侵权行为请发邮件ishare@vip.sina.com联系网站客服,我们会及时删除。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。
本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。
网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。
下载需要: 免费 已有0 人下载
最新资料
资料动态
专题动态
is_014457
暂无简介~
格式:doc
大小:22KB
软件:Word
页数:7
分类:
上传时间:2017-09-17
浏览量:59