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

📄 ti2cmid2.c.svn-base

📁 最新火热的CX32 源代码
💻 SVN-BASE
字号:
/**
 *  This code and information is part of Trident DPTV API (TDAPI)
 *
 *  Copyright (C) Trident Multimedia Technologies (Shanghai) Co., Ltd.
 *         2004  All rights reserved.
 *
 *  This file contains Middle Level I2C Routines
 *
 *  Revision:
 *  11/09/2004     Created by Archie
 *
 */

#include "tdefs.h"
#include "ti2c.h"

#define _DECLARE_FASTI2C_
#include "tfasti2c.h"

#include "ti2cmid.c"

#define _TRY_TIMES_   5

Byte tdFastI2CReadByte(Byte ucSlaveAddr, Byte ucSubAddr)
{
    IByte ucTryTimes = _TRY_TIMES_;
    IByte ucData;
#ifdef _USE_SECOND_CC_
    tdEnableI2CFlag(_I2C_BUSY_);
#endif
    while (ucTryTimes--)
    {
        tdStart();
        
        if(tdI2CSendByte((Byte)(ucSlaveAddr & 0xfe)) && tdI2CSendByte(ucSubAddr))
        {
            tdStart();
            if(tdI2CSendByte((Byte)(ucSlaveAddr | 0x01)))
            {
                ucData = tdI2CReceiveByte();
                /*send No ACK*/
                tdNOACK();
                tdStop();
                break;   /* OK, return */
            } 
        } 
        tdStop();
    
        /* WRONG, try again */
    }
#ifdef _USE_SECOND_CC_
    tdDisableI2CFlag(_I2C_BUSY_);
#endif
    return ucData;
}

Void tdFastI2CWriteByte(Byte ucSlaveAddr, Byte ucSubAddr, Byte ucData)
{
    IByte ucTryTimes = _TRY_TIMES_;

#ifdef _USE_SECOND_CC_
    tdEnableI2CFlag(_I2C_BUSY_);
#endif
    while (ucTryTimes--)
    {
        tdStart();
        
        if(tdI2CSendByte((Byte)(ucSlaveAddr & 0xfe)) && tdI2CSendByte(ucSubAddr)
            && tdI2CSendByte(ucData))
        {
            tdStop();
            break;   /* OK, return */
        }
        tdStop();
        /* WRONG, try again */
    }
#ifdef _USE_SECOND_CC_
    tdDisableI2CFlag(_I2C_BUSY_);
#endif
}


⌨️ 快捷键说明

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