i2c_write.c
来自「这是适用I/O口模拟的 I2C 程序」· C语言 代码 · 共 135 行
C
135 行
/*************************** Function Message ****************************
** Funtion Name : I2C_WriteByte
** 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_WriteByte(BYTE bAddrressWritten, BYTE bContent )
{
BYTE i;
I2C_Start();
I2C_Txd(_WR_ID__);
I2C_Txd(bAddrressWritten);
I2C_Txd(bContent);
I2C_Stop();
I2C_DELAY();
};
/*************************** Function Message ****************************
** Funtion Name : I2C_WritePage
** 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: none
** Restrictions: none
** created by: ZhangBin
** Last modified: 12/7/04 (MM/DD/YY)
** Description: the main program of the EOS System
***************************************************************************/
void I2C_WritePage(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);
do{
I2C_Txd(*dptr++);
I2C_DELAY();
}while(--bLoop);
I2C_Stop();
DelayMs(10);
};
/*************************** Function Message ****************************
** Funtion Name : I2C_WritePage
** 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: note that the dptr pointer , if in bank2 or bank3, should
** setup anoter new function
***************************************************************************/
void I2C_WritePage2(BYTE bHeadAddrress, bank2 BYTE* dptr, BYTE bLoop)
{
BYTE i;
I2C_Start();
I2C_Txd(WR_ID);
I2C_Txd(bHeadAddrress);
do{
I2C_Txd(*dptr++);
I2C_DELAY();
}while(--bLoop);
I2C_Stop();
DelayMs(10);
};
/*************************** Function Message ****************************
** Funtion Name : I2C_Erase
** 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_Erase(WORD wHeadAddrress, BYTE bData, BYTE bLoop)
{
BYTE i;
I2C_Start();
I2C_Txd(WR_ID);
i = (BYTE)(wHeadAddrress >> 8);
I2C_Txd(i);
i = (BYTE)wHeadAddrress;
I2C_Txd(i);
do{
I2C_Txd(bData);
I2C_DELAY();
}while(--bLoop);
I2C_Stop();
DelayMs(10);
};
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?