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

📄 bitek.c

📁 Bitek 公司 bit1611b模拟屏驱动芯片外接MCU驱动DEMO源码
💻 C
📖 第 1 页 / 共 2 页
字号:
    Passed: None.
    Returns: None.
    Notes:
    Reference:
   ------------------------------------------------------------------- */
void BITEK_Start (void)
{

    BITEK_SET_SDAT(HIGH);

    BITEK_SET_SCLK(HIGH);

    HI_PULSE;
    HI_PULSE;
    HI_PULSE;

    BITEK_SET_SDAT(LOW);
    LO_PULSE;
    LO_PULSE;

    BITEK_SET_SCLK(LOW);
    LO_PULSE;
} /* BITEK_Start */


/* -------------------------------------------------------------------
    Name: BITEK_Stop - STOP condition (SDAT rising edge).
    Purpose: .
    Passed: None.
    Returns: None.
    Notes:
    Reference:
  ------------------------------------------------------------------- */
void BITEK_Stop (void)
{
    BITEK_SET_SDAT(LOW);
    LO_PULSE;

    BITEK_SET_SCLK(HIGH);
    HI_PULSE;
    HI_PULSE;
    HI_PULSE;

    BITEK_SET_SDAT(HIGH);
    HI_PULSE;
    HI_PULSE;
    HI_PULSE;
} /* BITEK_Stop */



#if (BITEK_TX_BURST)
/* -------------------------------------------------------------------
    Name: BITEK_TxBurst -
    Purpose: To transmit bulk data to BiTEKbus slave device.
    Passed:
        UB8  bSLA       = BiTEKbus slave address
        UW16 wREG       = BiTEKbus register address
        UB8  bCNT       = The number of data which will be transmitted
            excluding slave and register address (bCNT: 1..255).
        UB8  *pbDATA    = The pointer which points to the first data item.
    Returns: None.
    Notes:
   ------------------------------------------------------------------- */
void BITEK_TxBurst (
UB8  bSLA,          /* BITEK slave address */
UW16 wREG,          /* BITEK register address */
UB8  bCNT,          /* The number of data which will be transmitted */
UB8  *pbDATA        /* Point to the first DATA item */
)
{
    UB8 bIdx;


    BITEK_Start();

    BITEK_TxData(bSLA);

    BITEK_GetACK();


    // If Extension = 1 !
    if (bSLA & 0x01)
    {
        // MSB Slave Address [14:7]
        BITEK_TxData(wREG >> 7);
        BITEK_GetACK();
    }

    // LSB Slave Address [6:0]
    BITEK_TxData(wREG << 1);
    BITEK_GetACK();


    /* --------------------------------
        Write Data
       -------------------------------- */
    for (bIdx = bCNT; bIdx; bIdx--)
    {
        bData = *pbDATA++;
        BITEK_TxData(bData);
        BITEK_GetACK();
    } /* for */


    BITEK_Stop();
} /* BITEK_TxBurst */
#endif


#if (BITEK_TX_BYTE)
/* -------------------------------------------------------------------
    Name: BITEK_TxByte -
    Purpose: To transmit one byte data to BiTEKbus slave device.
    Passed:
        UB8  bSLA   = BiTEKbus slave address.
        UW16 wREG   = BiTEKbus register address.
        UB8  bDATA  = One byte transmitted data.
    Returns: None.
    Notes:
   ------------------------------------------------------------------- */
void BITEK_TxByte (
UB8  bSLA,          /* BITEK slave address */
UW16 wREG,          /* BITEK register address */
UB8  bDATA          /* DATA item */
)
{
    BITEK_Start();

    BITEK_TxData(bSLA);

    BITEK_GetACK();


    // If Extension = 1 !
    if (bSLA & 0x01)
    {
        // MSB Slave Address [14:7]
        BITEK_TxData(wREG >> 7);
        BITEK_GetACK();
    }

    // LSB Slave Address [6:0]
    BITEK_TxData(wREG << 1);
    BITEK_GetACK();


    /* --------------------------------
        Write Data
       -------------------------------- */
    BITEK_TxData(bDATA);
    BITEK_GetACK();

    BITEK_Stop();
} /* BITEK_TxByte */
#endif


/* -------------------------------------------------------------------
    Name: BITEK_TxData -
    Purpose: To do BITEK parallel/serial conversion for transmission.
    Passed:
    Returns: None.
    Notes:
   ------------------------------------------------------------------- */
void BITEK_TxData (UB8 bData)
{
    UB8     bMask;

    /* MSB is sent first */
    for (bMask = 0x80; bMask; bMask >>= 1)
    {
        BITEK_SET_SDAT(bData & bMask)
        LO_PULSE;

        BITEK_SET_SCLK(HIGH);
        HI_PULSE;

        BITEK_SET_SCLK(LOW);
        LO_PULSE;
    }
} /* BITEK_TxData */


#if (BITEK_TX_REPEAT)
/* -------------------------------------------------------------------
    Name: BITEK_TxRepeat -
    Purpose: To transmit the same data to BiTEKbus slave device repeatly.
    Passed:
        UB8  bSLA   = BiTEKbus slave address.
        UW16 wREG   = BiTEKbus register address.
        UB8  bCNT   = The number of data which will be transmitted
            excluding slave and register address (bCNT: 1..255).
        UB8  bDATA  = The repeated data.
    Returns: None.
    Notes:
   ------------------------------------------------------------------- */
void BITEK_TxRepeat (
UB8  bSLA,          /* BITEK slave address */
UW16 wREG,          /* BITEK register address */
UB8  bCNT,          /* The number of data which will be transmitted */
UB8  bDATA          /* The repeated DATA */
)
{
    UB8 bIdx;


    if (bCNT == 0)
        return;

    BITEK_Start();

    BITEK_TxData(bSLA);

    BITEK_GetACK();


    // If Extension = 1 !
    if (bSLA & 0x01)
    {
        // MSB Slave Address [14:7]
        BITEK_TxData(wREG >> 7);
        BITEK_GetACK();
    }

    // LSB Slave Address [6:0]
    BITEK_TxData(wREG << 1);
    BITEK_GetACK();


    /* --------------------------------
        Write Data
       -------------------------------- */
    for (bIdx = bCNT; bIdx; bIdx--)
    {
        BITEK_TxData(bDATA);           
        BITEK_GetACK();                
    } /* for */


    BITEK_Stop();
} /* BITEK_TxRepeat */
#endif // BITEK_TX_REPEAT


#if (BITEK_TX_WORD)
/* -------------------------------------------------------------------
    Name: BITEK_TxWord -
    Purpose: To transmit one word data to BiTEKbus slave device.
    Passed:
        UB8  bSLA   = BiTEKbus slave address.
        UW16 wREG   = BiTEKbus register address.
        UB8  bDATA  = One word transmitted data.
    Returns: None.
    Notes: To send LSB first and then MSB.
   ------------------------------------------------------------------- */
void BITEK_TxWord (
UB8  bSLA,          /* BITEK slave address */
UW16 wREG,          /* BITEK register address */
UW16 wDATA          /* DATA item */
)
{
    BITEK_Start();

    BITEK_TxData(bSLA);

    BITEK_GetACK();


    // If Extension = 1 !
    if (bSLA & 0x01)
    {
        // MSB Slave Address [14:7]
        BITEK_TxData(wREG >> 7);
        BITEK_GetACK();
    }

    // LSB Slave Address [6:0]
    BITEK_TxData(wREG << 1);
    BITEK_GetACK();


    /* --------------------------------
        Write Data
       -------------------------------- */
    // LSB Data
    BITEK_TxData(wDATA);            /* Low Byte */
    BITEK_GetACK();

    // MSB Data
    BITEK_TxData(wDATA >> 8);       /* High Byte */
    BITEK_GetACK();

    BITEK_Stop();
} /* BITEK_TxWord */
#endif


#else

/* -------------------------------------------------------------------
    Name: BITEK_Init -
    Purpose: To initialize the BITEK module via I2C.
    Passed: None.
    Returns: None.
    Notes:
  ------------------------------------------------------------------- */
void BITEK_Init (void)
{
} /* BITEK_Init */


/* -------------------------------------------------------------------
    Name: BITEK_TxRepeat -
    Purpose: To transmit the same data to BiTEKbus slave device repeatly via I2C.
    Passed:
        UB8  bSLA   = BiTEKbus slave address.
        UW16 wREG   = BiTEKbus register address.
        UB8  bCNT   = The number of data which will be transmitted
            excluding slave and register address (bCNT: 1..255).
        UB8  bDATA  = The repeated data.
    Returns: None.
    Notes:
   ------------------------------------------------------------------- */
void BITEK_TxRepeat (
UB8  bSLA,          /* BITEK slave address */
UW16 wREG,          /* BITEK register address */
UB8  bCNT,          /* The number of data which will be transmitted */
UB8  bDATA          /* The repeated DATA */
)
{
    UB8 bIdx;

    if (bCNT == 0)
        return;

    I2C_Start();

    I2C_TxData(bSLA | (((wREG) >> 7) & 0x1E));

    I2C_GetACK();


    I2C_TxData(wREG);
    I2C_GetACK();


    /* --------------------------------
        Write Data
       -------------------------------- */
    for (bIdx = bCNT; bIdx; bIdx--)
    {
        I2C_TxData(bDATA);          
        I2C_GetACK();               
    } /* for */


    I2C_Stop();
} /* BITEK_TxRepeat */

#endif

/* -------------------------------------------------------------------
    Name:  -
    Purpose: .
    Passed: None.
    Returns: None.
    Notes:
   ------------------------------------------------------------------- */


/* **********************************************************************

    Description:


   ********************************************************************** */

/* %% End Of File %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% */

⌨️ 快捷键说明

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