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

📄 i2c.c

📁 调频收音机芯片5763的驱动代码,C语言编写,直接移植即可,代码已经验证OK
💻 C
字号:
/*-------------------------------------------------------

	Property of Synergy Digital Technology Ltd.

	Question/comment : chifai.cheung@synergytech.cn

	Complier : Keil uvision C-51

-------------------------------------------------------*/


#include "i2c.h"

char i2c_start()
{
	SDA = 1;
	SCL = 1;

	if (!SCL) return (1);				// if SCL is busy, return error
	if (!SDA) return (1);				// if SDA is busy, return error

	SDA = 0;
	SCL = 0;

	return (0);							// return OK
}


void i2c_stop()
{
	SDA = 0;
	SCL = 1;
	SDA = 1;
}


unsigned char i2c_out(unsigned char DATA)
{
	unsigned i;

	for (i=0; i<8; i++)
	{
		if (DATA & 0x80) SDA = 1;
		else SDA = 0;

		SCL = 1;
		DATA <<= 1;
		SCL = 0;
	}

	SCL = 1;
	i = SDA;
	SCL = 0;

	return (i);							// 0 - ack, 1 - nack
}


unsigned char i2c_in(void)
{
	unsigned char i, j;

	SDA = 1;

	for (i=0; i<8; i++)
	{
		SCL = 1;
		j <<= 1;
		if (SDA) j |= 0x01;
		SCL = 0;
	}
        
    return j;							// return received DATA
}


void i2c_ack(void)
{
	SDA = 0;							// acknowledgement
	SCL = 1;
	SCL = 0;
}


void i2c_nak(void)
{
	SDA = 1;							// nagative acknowledgement
	SCL = 1;
	SCL = 0;
}

⌨️ 快捷键说明

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