This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

EEPROM 93c46 with 89c51

I am looking for example(s) on writing/reading EEPROMs (93c46) using 89c51 in C.
Any help shall be higly appreciated.

Mansoor

Parents Reply Children
  • Hi Mansoor,
    If you don't care about the overhead, I think you can use the following method to implement your own 8-bit read/write.

    #define S_CONST_EEPROM_START_ADDR	0x01	// 0x01 ~ 0x3f
    #define GET_HIGH(xx)		( (BYTE) ((xx) >> 8) )
    #define GET_LOW(xx)			( (BYTE) ((xx) & 0x00ff) )
    
    //////////////////////////////////////////////////////////////////////////////
    // Function name  : EepromWriteOneByte
    // Description 	  : Eeprom Write One Byte through Driver
    // Return Value   :
    // [#05]
    BYTE EepromWriteOneByte(BYTE pos, BYTE byteValue)
    {
    	BYTE cAdr, cResult;
    	WORD sData, sDataOut;
    
    	// write out a word
    	cAdr = S_CONST_EEPROM_START_ADDR + pos / 2;
    	vWriteDisable();
    	sDataOut = sReadWord(cAdr);  // Address from 0x00 to 0x3F
    	if (pos % 2)
    		sData = (GET_HIGH(sDataOut)<<8) | byteValue;	// odd
    	else
    		sData = GET_LOW(sDataOut) | (byteValue << 8);	// even
    
    	vWriteEn();
    	cWriteWord(cAdr, sData);
    	vWriteDisable();
    	cResult = EepromReadOneByte(pos);
    
    
    	return cResult;
    }
    
    //////////////////////////////////////////////////////////////////////////////
    // Function name  : EepromReadOneByte
    // Description 	  : Eeprom Read One Byte through Driver
    // Return Value   :
    // [#05]
    BYTE EepromReadOneByte(BYTE pos)
    {
    	BYTE cAdr, cResult;
    	WORD sDataOut;
    
    
    	// read back check
    	cAdr = S_CONST_EEPROM_START_ADDR + pos / 2;
    	vWriteDisable();
    	sDataOut = sReadWord(cAdr);  // Address from 0x00 to 0x3F
    	if (pos % 2)
    		cResult = GET_LOW(sDataOut); // odd
    	else
    		cResult = GET_HIGH(sDataOut); // even
    
    
    	return cResult;
    }
    

  • What do you mean by overheads. Thanks for your efforts in answering my query.

    Mansoor

  • I have just completed the project. Thanks for all who helped. I have tried to develop generalize routines for reading/writing in 8 bits.
    Any body interested,Pl. contact me on mansoork38@hotmail.com.

    Mansoor