24c02读写程序(已通过测试),24C02 read / write process
关键字:24c02读写程序(已通过测试)
24c02读写程序(已通过测试)
24c02读写程序(已通过测试)#ifndef _24C02_H #define _24C02_H
// 脚定义 sbit SCL = P3^7; //24c02 SCL sbit SDA = P3^6; //24c02 SDA
// 功能函数 void x24c02_delay(char x) { int i; for(i=0;i}
void x24c02_start() { SDA = 1; SCL = 1; SDA = 0; SCL = 0; }
void x24c02_stop() { SDA=0; SCL=1; SDA=1; } void x24c02_writex(char j) { char i,temp; temp=j; for (i=0;i<8;i++) { temp=temp<<1; SCL=0; SDA=CY; SCL=1; } SCL=0; SDA=1; } char x24c02_readx() { char i,j,k=0; SCL=0; SDA=1; for (i=0;i<8;i++) { SCL=1; if (SDA==1) j=1; else j=0; k=(k<<1)|j; SCL=0; } return(k); } void x24c02_clock() { char i=0; SCL=1; while ((SDA==1)&&(i<255))i++; SCL=0; }
void x24c02_init() { SCL = 1; SDA = 1; }
char x24c02_read(char address) { char i; x24c02_start(); x24c02_writex(0xa0); x24c02_clock(); x24c02_writex(address); x24c02_clock(); x24c02_start(); x24c02_writex(0xa1); x24c02_clock(); i=x24c02_readx(); x24c02_stop(); x24c02_delay(10); return(i); }
void x24c02_write(char address, char info) { EA=0; x24c02_start(); x24c02_writex(0xa0); x24c02_clock(); x24c02_writex(address); x24c02_clock(); x24c02_writex(info); x24c02_clock(); x24c02_stop(); EA=1; x24c02_delay(50); }
void x24c02_writestr(char address, unsigned char *wdata, unsigned char wlen) { unsigned char k=0; do { x24c02_write(address+k, *(wdata + k)); k++; } while(k < wlen); }
void x24c02_readstr(char address, unsigned char *rdata, unsigned char rlen) { unsigned char k=0; do { rdata[k] = x24c02_read(address+k); k++; } while(k < rlen); }
#endif
|