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

📄 i2c_rxd_txd.c

📁 这是适用I/O口模拟的 I2C 程序
💻 C
字号:
/*************************** Function  Message ****************************
** Funtion Name : I2C_Txd
** Arguments: BYTE bComOrder: the communication order
** Return Value:   return  the communication status
** Restrictions:   none
** created by: ZhangBin
** Last modified: 12/2/04 (MM/DD/YY)
** Description:  the main program  of the EOS System
***************************************************************************/
void  I2C_Txd(BYTE data)
{
 	BYTE i = 8;

	do
   	{
    	if(data & 0x80)
       		SDA_DIR_IN();              //SDA = 1;
    	else
       		SDA_DIR_OUT();             //SDA = 0;
    
    	I2C_DELAY();   
    	SCL_DIR_IN();                 //SCL = 1;  
    	I2C_DELAY();
    	SCL_DIR_OUT();                //SCL = 0;
    	I2C_DELAY();
    
    	data <<= 1;
    
 	}while(--i);
   
 	SDA_DIR = 1;
 	SCL_DIR_IN();                    //SCL = 1;  
 
 	if(!SDA) 
    	I2C_DELAY();                  //this delay must be added

 	SCL_DIR_OUT();                   //SCL = 0;
 	SDA_DIR = 0;

 	I2C_DELAY();

};


/*************************** Function  Message ****************************
** Funtion Name : I2C_Rxd
** Arguments: BYTE bComOrder: the communication order
** Return Value:   return  the communication status
** Restrictions:   none
** created by: ZhangBin
** Last modified: 12/2/04 (MM/DD/YY)
** Description:  the main program  of the EOS System
***************************************************************************/
BYTE  I2C_Rxd(void)
{
 	BYTE i = 8;
 	BYTE data = 0;

 	SDA_DIR = 1;                    //bus free;
 
 	do{
     	data <<= 1;
     	SCL_DIR_IN();                //SCL = 1;  
     	I2C_DELAY();
     	data |= SDA;
     	SCL_DIR_OUT();               //SCL = 0;
     	I2C_DELAY();  
 	}while(--i);
 
 	SDA_DIR = 0;
 
 	return data;
}; 


/*************************** Function  Message ****************************
** Funtion Name : I2C_ACK
** Arguments: BYTE bComOrder: the communication order
** Return Value:   return  the communication status
** Restrictions:   none
** created by: ZhangBin
** Last modified: 12/2/04 (MM/DD/YY)
** Description:  the main program  of the EOS System
***************************************************************************/
void  I2C_ACK(void)
{
 	SDA_DIR_OUT();                   //SDA = 0;
 	SCL_DIR_IN();                    //SCL = 1;  
 	I2C_DELAY();
 	SCL_DIR_OUT();                   //SCL = 0;
}; 

/*************************** Function  Message ****************************
** Funtion Name : I2C_ACK
** Arguments: BYTE bComOrder: the communication order
** Return Value:   return  the communication status
** Restrictions:   none
** created by: ZhangBin
** Last modified: 12/2/04 (MM/DD/YY)
** Description:  the main program  of the EOS System
***************************************************************************/
void  I2C_NACK(void)
{
 	SDA_DIR_IN();                    //SDA = 1;
 	SCL_DIR_IN();                    //SCL = 1;  
 	I2C_DELAY();
 	SCL_DIR_OUT();                   //SCL = 0;
};

⌨️ 快捷键说明

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