Esempio n. 1
0
void I2C_SendACK(bit ack)
{
    MSDA = ack;                  //写应答信号
    MSCL = 1;                    //拉高时钟线
    Delay_5us();                 //延时
    MSCL = 0;                    //拉低时钟线
    Delay_5us();                 //延时
}
Esempio n. 2
0
void I2C_Stop(void)
{
    MSDA = 0;                    //拉低数据线
    MSCL = 1;                    //拉高时钟线
    Delay_5us();                 //延时
    MSDA = 1;                    //产生上升沿
    Delay_5us();                 //延时
}
Esempio n. 3
0
void PCF8591_NO_ACK()
{
	PCF_SDA = 1;
	Delay_5us();
	PCF_SCL = 1;
	Delay_5us();
	PCF_SCL = 0;
	Delay_5us();
}
Esempio n. 4
0
bit I2C_RecvACK(void)
{
    MSCL = 1;                    //拉高时钟线
    Delay_5us();                 //延时
    CY = MSDA;                   //读应答信号
    MSCL = 0;                    //拉低时钟线
    Delay_5us();                 //延时
    return CY;
}
Esempio n. 5
0
void I2C_Start(void)
{
    MSDA = 1;                    //拉高数据线
    MSCL = 1;                    //拉高时钟线
    Delay_5us();                 //延时
    MSDA = 0;                    //产生下降沿
    Delay_5us();                 //延时
    MSCL = 0;                    //拉低时钟线
}
Esempio n. 6
0
/*---------------------------------------------------------------*-
 * PCF8591_Stop();
 * 
 * Send stop condition
-*---------------------------------------------------------------*/
void PCF8591_Stop(void)
{
	PCF_SCL = 0;
	PCF_SDA = 0;
	Delay_5us();
	PCF_SCL = 1;
	Delay_5us();
	PCF_SDA = 1;
	Delay_5us();
}
Esempio n. 7
0
void I2C_SendByte(u8 dat)
{
    u8 i;
    for (i=0; i<8; i++)          //8位计数器
    {
        dat <<= 1;               //移出数据的最高位
        MSDA = CY;               //送数据口
        MSCL = 1;                //拉高时钟线
        Delay_5us();             //延时
        MSCL = 0;                //拉低时钟线
        Delay_5us();             //延时
    }
    I2C_RecvACK();
}
Esempio n. 8
0
u8  I2C_RecvByte(void)
{
    u8 i;
    u8 dat = 0;
    MSDA = 1;                    //使能内部上拉,准备读取数据,
    for (i=0; i<8; i++)         //8位计数器
    {
        dat <<= 1;
        MSCL = 1;                //拉高时钟线
        Delay_5us();             //延时
        dat |= MSDA;             //读数据               
        MSCL = 0;                //拉低时钟线
        Delay_5us();              //延时
    }
    return dat;
}
Esempio n. 9
0
/*---------------------------------------------------------------*-
 * PCF8591_Write_Byte()
 * 
 * Send one byte data to slave
-*---------------------------------------------------------------*/
void PCF8591_Write_Byte(unsigned char DATA)
{
	unsigned char i;
	for (i = 0; i < 8; i++) {
		if ((DATA & 0x80) == 0)
			PCF_SDA = 0;
		else
			PCF_SDA = 1;
		DATA <<= 1;
		PCF_SCL = 0;
		Delay_5us();
		PCF_SCL = 1;
		Delay_5us();
		PCF_SCL = 0;
		Delay_5us();
	}
}
Esempio n. 10
0
/*---------------------------------------------------------------*-
 * PCF8591_Read_Byte()
 * 
 * Read one byte data from slave
-*---------------------------------------------------------------*/
unsigned char PCF8591_Read_Byte(void)
{
	unsigned char i = 0;
	unsigned char Data;

	for (i = 0; i < 8; i++) {
		PCF_SCL = 1;
		Delay_5us();
		if (PCF_SDA)
			Data |= 1;
		if (i < 7)
			Data <<= 1;
		PCF_SCL = 0;
		Delay_5us();
	}
	return Data;
}