1、AT24C256完整程序AT24C256完整程序/* 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) /* I2c sotp condition SDA=0-1 while SCL=1 */ void I2cStop(void) ISDA=0;
2、 I2cWait(); ISCL=1; I2cWait(); ISDA=1; I2cWait(); /* I2c Init Initialize I2C interface Release I2c BUS * void I2cInit(void) ISDA=1; ISCL=1; I2cWait(); */ /* I2c SentByte master transfer data to slave and return acknowledge bit dont include */ bit I2cSentByte(unsigned char bytedata) unsigned char i;
3、bit ack; for(i=0;i8;i+) if(bytedata & 0x80) ISDA=1; else ISDA=0; 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) unsigne
4、d char i; unsigned char bytedata=0; ISCL=0; I2cWait(); for(i=0;i8;i+) ISCL=1; I2cWait(); bytedata=bytedata8); /送高位地址 I2cSentByte(addr&0xff); /送低位地址 I2cSentByte(value); I2cStop(); delay1ms(15); /* 24c64 WriteMulti page:0-255 count:要写入的数个数 */void _24c64WriteMulti(unsigned int page,unsigned char count,
5、unsigned char *SenBuf) unsigned char i; unsigned int addr=page*32; I2cStart(); I2cSentByte(0xa0); I2cSentByte(addr8); /送高位地址 I2cSentByte(addr&0x00ff); /送低位地址 for(i=0;i8); /送高位地址 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) unsigned int addr=page*32; unsigned char i; for(i=0;icount;i+) RedBufi=_24c64ReadByte(addr); addr+; SendAcknowledge(1); I2cStop();
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1