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

📄 i2c_read.c

📁 这是适用I/O口模拟的 I2C 程序
💻 C
字号:
/*************************** Function  Message ****************************
** Funtion Name : I2C_ReadByte
** Arguments: wAddrressWritten  :  the  address of  the  memory  byte unit   
**            of  the E2prom  which will be written  and  the  written 
**            content  is   the  followed  argument : bContent ;
**            bContent  :  the  content  will be  written  to  the  byte 
**            unit  of the  E2Prom
** Return Value: TRUE :   write  successfully           
**               FALSE :  write  error
** Restrictions:   none
** created by: ZhangBin
** Last modified: 12/7/04 (MM/DD/YY)
** Description:  the main program  of the EOS System
***************************************************************************/
BYTE    I2C_ReadByte(BYTE  bAddrressRead)
{
 	BYTE i;
 	BYTE data;
 
 	I2C_Start();

 	I2C_Txd(WR_ID);
 
        I2C_Txd(bAddrressRead);

 	I2C_ReStart();

 	I2C_Txd(RD_ID);

    	data = I2C_Rxd();	

    	I2C_NACK();	

    	I2C_Stop();
	
 	return data;	
};



/*************************** Function  Message ****************************
** Funtion Name : I2C_ReadPage
** Arguments: wAddrressWritten  :  the  address of  the  memory  byte unit   
**            of  the E2prom  which will be written  and  the  written 
**            content  is   the  followed  argument : bContent ;
**            bContent  :  the  content  will be  written  to  the  byte 
**            unit  of the  E2Prom
** Return Value: TRUE :   write  successfully           
**               FALSE :  write  error
** Restrictions:   none
** created by: ZhangBin
** Last modified: 12/7/04 (MM/DD/YY)
** Description:  the main program  of the EOS System
***************************************************************************/
void    I2C_ReadPage(WORD wHeadAddrress, BYTE* dptr, BYTE bLoop)
{
 	BYTE i;
 
 	I2C_Start();
 	I2C_Txd(WR_ID);
 
 	i = (BYTE)(wHeadAddrress >> 8);
 	I2C_Txd(i);
 	i = (BYTE)wHeadAddrress;	
 	I2C_Txd(i);
	
 	I2C_ReStart();
 	I2C_Txd(RD_ID);
 
 	bLoop--;
 	
 	do{
     	*dptr++ = I2C_Rxd();
     	I2C_ACK();		
		
 	}while(--bLoop);
	
 	*dptr = I2C_Rxd();	
 	I2C_NACK();	
	
 	I2C_Stop();
};

/*************************** Function  Message ****************************
** Funtion Name : I2C_Compare
** Arguments: wAddrressWritten  :  the  address of  the  memory  byte unit   
**            of  the E2prom  which will be written  and  the  written 
**            content  is   the  followed  argument : bContent ;
**            bContent  :  the  content  will be  written  to  the  byte 
**            unit  of the  E2Prom
** Return Value: TRUE :   write  successfully           
**               FALSE :  write  error
** Restrictions:   none
** created by: ZhangBin
** Last modified: 12/7/04 (MM/DD/YY)
** Description:  the main program  of the EOS System
***************************************************************************/
BOOL    I2C_Compare(WORD wHeadAddrress, BYTE* dptr,  BYTE bLoop)
{
 	BYTE i;
 
 	I2C_Start();
 	I2C_Txd(WR_ID);
 
 	i = (BYTE)(wHeadAddrress >> 8);
 	I2C_Txd(i);
 	i = (BYTE)wHeadAddrress;	
 	I2C_Txd(i);
	
 	I2C_ReStart();
 	I2C_Txd(RD_ID);
 
 	bLoop--;
 	
 	do{
     	i = I2C_Rxd();
     	if(*dptr++ != i)
          	return   FALSE ;
     	I2C_ACK();		
     		
 	}while(--bLoop);
	
 	i = I2C_Rxd();
 	if(*dptr != i)
          return   FALSE ;	
 	I2C_NACK();	
	
 	I2C_Stop();	
 
 	return	TRUE;
};

⌨️ 快捷键说明

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