⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 i2c_eep_subs_24lc32a.c

📁 pic18f-i2c
💻 C
字号:
#include <p18cxxx.h>
#include <i2c.h>


/********************************************************************
*     Function Name:    EEByteWrite                                 *
*     Return Value:     error condition status                      *
*     Parameters:       EE memory device control, address and data  *
*                       bytes.                                      *
*     Description:      Write Multiple data byte to I2C EE memory     *
*                       device. This routine can be used for any I2C*
*                       EE memory device, which only uses 1 byte of *
*                       address data as in the 24LC01B/02B/04B/08B. *
* 
*	return code :                                                   *  
*					0 : Error Free 
*					1 : Bus Collision Error
*					2 : Command Write Error
*					3 : Data Write Error 
********************************************************************/

int EEByteWrite_Multi( unsigned char control, unsigned int address, unsigned char *data , unsigned char count )
{
  unsigned char ByteValue ;
  int			W_Loop ;
  IdleI2C();                      // ensure module is idle
  StartI2C();                     // initiate START condition

  while ( SSPCON2bits.SEN );      // wait until start condition is over 
  if ( PIR2bits.BCLIF )           // test for bus collision
  {
    return ( -1 );                // return with Bus Collision error 
  }
  else                            // start condition successful
  {
    if ( WriteI2C( control ) != 0 )    // write byte - R/W bit should be 0
    {
	  StopI2C(); 
      return ( -2 );              		// set error for write collision
    }

    if ( !SSPCON2bits.ACKSTAT )   		// test for ACK condition received
    { 

	  ByteValue = (address >> 8) & 0x00ff ;
      if ( WriteI2C(ByteValue) != 0 )  // write word address for EEPROM
      {
	    StopI2C(); 
        return ( -3 );            		// set error for write collision
      }

      if ( WriteI2C( (char)(address & 0x00ff) )!= 0)  // write word address for EEPROM
      {
	    StopI2C(); 
        return ( -3 );            		// set error for write collision
      }

	  // 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -