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

📄 bitek.c

📁 Bitek 公司 bit1611b模拟屏驱动芯片外接MCU驱动DEMO源码
💻 C
📖 第 1 页 / 共 2 页
字号:
/* **********************************************************************

         Copyright (c) 2002-2006 Beyond Innovation Technology Co., Ltd

        All rights are reserved. Reproduction in whole or in parts is
    prohibited without the prior written consent of the copyright owner.
   ----------------------------------------------------------------------

    Module: BITEK.C - BITEKbus.

    Purpose: Implementation of BITEK module.

    Version: 0.01                                   07:27PM  2005/05/13

    Compiler: Keil 8051 C Compiler v8.01

    Reference:
    [1] BIT1611B Datasheet Version 1.0, 2005-11-10, Beyond Innovation Technology

   ----------------------------------------------------------------------
    Modification:

    R0.01 07:27PM  2005/05/13 Jeffrey Chang
    Reason:
        1. Original.
    Solution:

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

#define _BITEK_C_


/* ------------------------------------
    Header Files
   ------------------------------------ */
#include <intrins.h>
#include "bitek.h"

/* ------------------------------------
    Macro Definitions
   ------------------------------------ */
#if (VP_IF_CFG == VP_IF_BITEK)

    #define NOP_24  { _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_();}
    #define NOP_20  { _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); }
    #define NOP_18  { _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); }
    #define NOP_15  { _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_();  }
    #define NOP_12  { _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_();   }
    #define NOP_10  { _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_();                     }
    #define NOP_3   { _nop_(); _nop_(); _nop_(); }
    #define NOP_2   { _nop_(); _nop_(); }
    #define NOP_1   { _nop_(); }
    #define NOP_0   {  }

    #define     LO_PULSE                NOP_1
    #define     HI_PULSE                NOP_1


    #define     BITEK_GET_SDAT_HIGH     (   BITEK_ioSDAT == HIGH    )

    #define     BITEK_SET_SCLK(HiLo)    {   BITEK_ioSCLK = (HiLo) ? HIGH : LOW; }
    #define     BITEK_SET_SDAT(HiLo)    {   BITEK_ioSDAT = (HiLo) ? HIGH : LOW; }

#endif

/* ------------------------------------
    Type Definitions
   ------------------------------------ */


/* ------------------------------------
    Variables Definitions
   ------------------------------------ */
#if (VP_IF_CFG == VP_IF_BITEK)

    sbit BITEK_ioSCLK   = P1 ^ 6;
    sbit BITEK_ioSDAT   = P1 ^ 7;
#endif

static UB8 bData;

/* ------------------------------------
    Function Prototypes
   ------------------------------------ */
#if (VP_IF_CFG == VP_IF_BITEK)
    static BOOL BITEK_GetACK(void);
    static UB8  BITEK_RxData(void);
    static void BITEK_Start(void);
    static void BITEK_Stop(void);

    #if (BITEK_SET_ACK)
    static void BITEK_SetACK(void);
    #endif

    static void BITEK_TxData(UB8 bData);
#endif


#if (VP_IF_CFG == VP_IF_BITEK)


/* -------------------------------------------------------------------
    Name: BITEK_GetACK -
    Purpose: .
    Passed: None.
    Returns: LOW if OK
    Notes:
    1) The acknowledge-related clock pulse is generated by the master.
    2) The transmitter (Tx) release the SDA line (HIGH) during the
       acknowledge clock pulse.
    3) The receiver (Rx) must pull down the SDA line during the
       acknowledge clock pulse so that it remains stable LOW during
       the HIGH period of this clock pulse.
  ------------------------------------------------------------------- */
BOOL BITEK_GetACK (void)
{
    BOOL    fResult;


    BITEK_SET_SDAT(HIGH);
    HI_PULSE;

    BITEK_SET_SCLK(HIGH);
    HI_PULSE;

    fResult = BITEK_GET_SDAT_HIGH;
    HI_PULSE;

    BITEK_SET_SCLK(LOW);
    LO_PULSE;

    return( fResult );
} /* BITEK_GetACK */


/* -------------------------------------------------------------------
    Name: BITEK_Init - (VP_IF_BITEK)
    Purpose: To initialize the BITEK module.
    Passed: None.
    Returns: None.
    Notes:
  ------------------------------------------------------------------- */
void BITEK_Init (void)
{
    BITEK_SET_SDAT(HIGH);
    BITEK_SET_SCLK(HIGH);
} /* BITEK_Init */


#if (BITEK_RX_BURST)
/* -------------------------------------------------------------------
    Name: BITEK_RxBurst -
    Purpose: To receive bulk data from BITEK slave device.
    Passed:
        UB8     bSLA    = BITEK slave address
        UW16    wREG    = BITEK register address
        UB8     bCNT    = The number of data which will be received
            bCNT: 1..255. (Excludes slave and register addresses)
        UB8     *pbDATA = The pointer which points to the first DATA item
    Returns: None.
    Notes:
   ------------------------------------------------------------------- */
void BITEK_RxBurst (
UB8     bSLA,               /* BITEK slave address */
UW16    wREG,               /* BITEK register address */
UB8     bCNT,               /* The number of data which will be transmitted */
UB8     *pbDATA             /* The pointer which points 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) | 0x01);
    BITEK_GetACK();


    /* --------------------------------
        Read
       -------------------------------- */
    for (bIdx = (bCNT - 1); bIdx; bIdx--)
    {
        *pbDATA++ = BITEK_RxData();

        BITEK_SetACK();                   
    } /* for */

    // Reading last one without ACK !
    *pbDATA = BITEK_RxData();


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


#if (BITEK_RX_BYTE)
/* -------------------------------------------------------------------
    Name: BITEK_RxByte -
    Purpose: To receive one byte data from BiTEKbus slave device.
    Passed:
        UB8     bSLA    = BITEK slave address.
        UW16    wREG    = BITEK register address.
    Returns: One byte received data.
    Notes:
   ------------------------------------------------------------------- */
UB8 BITEK_RxByte (
UB8     bSLA,           /* BITEK slave address */
UW16    wREG            /* BITEK register address */
)
{
    UB8    bDATA;


    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) | 0x01);           // Read Operation !
    BITEK_GetACK();


    /* --------------------------------
        Read Data
       -------------------------------- */
    // Reading last one without ACK !
    bDATA = BITEK_RxData();


    BITEK_Stop();

    return( bDATA );
} /* BITEK_RxByte */
#endif


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


    bResult = 0x00;

    BITEK_SET_SDAT(HIGH);


    /* MSB is read first */
    for (bMask = 0x80; bMask; bMask >>= 1)
    {
        BITEK_SET_SCLK(HIGH);
        HI_PULSE;

        if ( BITEK_GET_SDAT_HIGH )
            bResult |= bMask;

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

    return( bResult );
} /* BITEK_RxData */



#if (BITEK_RX_WORD)
/* -------------------------------------------------------------------
    Name: BITEK_RxWord -
    Purpose: To receive one WORD data from BITEK slave device.
    Passed:
        UB8     bSLA    = BITEK slave address
        UW16    wREG    = BITEK register address
    Returns: One word received data.
    Notes:
   ------------------------------------------------------------------- */
UW16 BITEK_RxWord (
UB8     bSLA,               /* BITEK slave address */
UW16    wREG                /* BITEK register address */
)
{
    UW16    wDATA;


    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) | 0x01);
    BITEK_GetACK();


    /* --------------------------------
        Read Data
       -------------------------------- */
    // LSB Data
    wDATA = BITEK_RxData();                 /* Low byte */
    BITEK_SetACK();

    // Reading last one without ACK !
    wDATA = (BITEK_RxData() << 8) + wDATA;


    BITEK_Stop();

    return( wDATA );
} /* BITEK_RxWord */
#endif


#if (BITEK_SET_ACK)
/* -------------------------------------------------------------------
    Name: BITEK_SetACK -
    Purpose: .
    Passed: None.
    Returns: None.
    Notes:
   ------------------------------------------------------------------- */
void BITEK_SetACK (void)
{
    BITEK_SET_SDAT(LOW);

    BITEK_SET_SCLK(HIGH);
    HI_PULSE;

    BITEK_SET_SCLK(LOW);
    LO_PULSE;

} /* BITEK_SetACK */
#endif


/* -------------------------------------------------------------------
    Name: BITEK_Start - START condition (SDAT falling edge).
    Purpose: .

⌨️ 快捷键说明

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