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

📄 i2c.c

📁 本程序是汽车音响中不可缺少的LCD显示程序
💻 C
字号:
#define BlueI2cSdaHigh()         { Blue_SDA = 1;NOP();NOP();NOP(); }
#define BlueI2cSdaLow()          { Blue_SDA = 0; NOP();NOP();NOP(); }
#define BlueI2cSclHigh()         { Blue_SCL = 1; NOP();NOP();NOP(); }
#define BlueI2cSclLow()          { Blue_SCL = 0; NOP();NOP();NOP(); }
#define Blue_sda_in                   Blue_SDAIN
#define BlueI2cSdaInput()        {Blue_SDA = 1;/*TFT_SDA = 1;P1CR = 0xd7;*/}
#define BlueI2cOutput()          {NOP();/*P1CR = 0xdf;TFT_SDA = 1;*/}

void BlueStartCondition(void)
{
	BlueI2cSdaHigh();
	BlueI2cSclHigh();
	BlueI2cSdaLow();
	BlueI2cSclLow();
	return;
}
//----------------------------------------
// P_Condition for TWD protocol
//----------------------------------------
void BlueStopCondition(void)
{
        BlueI2cSdaLow();
	BlueI2cSclLow();
	BlueI2cSclHigh();
	BlueI2cSdaHigh();
	return;
}
//--------------------------------------------------
// Send_Byte
//    Send a byte to master with a acknowledge bit
//--------------------------------------------------
unsigned char BlueSendByte(unsigned char cData)
{
	unsigned char ix;
	unsigned char cTWtryTime;
	cTWtryTime = 255;

	for(ix = 0; ix < 8; ix++)
	{
		BlueI2cSclLow();
                NOP();
                NOP();

		if(cData&0x80)
		{
			BlueI2cSdaHigh();
		}
		else
		{
			BlueI2cSdaLow();
		}
		cData <<= 1;
                NOP();
                NOP();
		BlueI2cSclHigh();
                NOP();
                NOP();
                NOP();
                NOP();

	}
	/* wait ack */
	BlueI2cSclLow();
                NOP();
                NOP();

	BlueI2cSdaHigh();   /* release data line for acknowledge */
                NOP();
                NOP();

	BlueI2cSclHigh();   /* Send a clock for Acknowledge */
                NOP();
                NOP();
	BlueI2cSdaInput();
                NOP();
                NOP();

        while(Blue_sda_in)
	{
           --cTWtryTime;
           if (cTWtryTime == 0)
           {
               BlueStopCondition();
               BlueI2cOutput();
               return(1);
           }
	}
	BlueI2cOutput();
	BlueI2cSclLow();
                NOP();
                NOP();
        return(0);
}
//--------------------------------------------------
//   Read_Byte
//   Read a byte from master with a acknowledge bit
//--------------------------------------------------
unsigned char BlueReadByte(unsigned char cNum)
{
	unsigned char ix;
	unsigned char cRetval;
	cRetval = 0;

	BlueI2cSdaInput();
	for(ix=0; ix<8; ix++)
	{
		cRetval <<= 1;   /* the first bit is the most bit */
		BlueI2cSclLow();
		NOP();
		NOP();

		BlueI2cSclHigh();
		NOP();
		NOP();

		if(Blue_sda_in)	cRetval |= 0x01;
		NOP();
		NOP();
		NOP();
	}
	BlueI2cOutput();
		NOP();
		NOP();

	BlueI2cSclLow();
		NOP();
		NOP();

	if(cNum)
	{
		BlueI2cSdaHigh();
	}
	else
	{
		BlueI2cSdaLow();
	}

		NOP();
		NOP();
	BlueI2cSclHigh();
		NOP();
		NOP();

	BlueI2cSclLow();
		NOP();
		NOP();

	BlueI2cSdaHigh();
		NOP();
		NOP();
	return cRetval;
}

⌨️ 快捷键说明

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