at24c01 problem

Hello , i cant find the mistakes according to the datasheet , though i didnt work...

Thanks for any help ! (Keil C51)

sbit SDA =P2^5; /* microcontroller's I/O lines */ sbit SCL =P2^4 ; /* assigned to I2C lines */

void start(void) { SDA = SCL = 1; SDA = 0; _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); SCL = 0; }

void stop(void) { SDA = 0; SCL = 1; _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); SDA = 1; }

bit clock(void) { bit level; /* state of SDA line */

SCL = 1; _nop_(); while(!SCL); /* if a pulse was stretched */ _nop_(); _nop_(); _nop_(); level = SDA; _nop_(); _nop_(); SCL = 0; return(level); }

bit write(uchar byte) { uchar mask = 0x80;

while(mask) { if (byte & mask) SDA = 1; else SDA = 0; clock(); mask >>= 1; } SDA = 1; return(clock()); }

uchar read(bit acknowledgment) { uchar mask = 0x80,byte = 0x00;

while(mask) { if (clock()) byte |= mask; mask >>= 1; } if (acknowledgment) { SDA = 0; clock(); SDA = 1; } else { SDA = 1; clock(); } return(byte); }

bit EEPROM_byte_write(uchar address, uchar byte) { bit status;

status = 0; /* failure by default */ start(); if (!write(address)) /* byte address */ if (!write(byte)) status = 1; /* success */ stop(); return(status); }

Reply to
zebulon
Loading thread data ...

sorry...the test instruction is just a :

while (1) { writeToLCD(EEPROM_byte_write(2,7),8); }

Reply to
zebulon

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.