BL55077 驱动程序

wuchangjian2021-11-15 19:43:26编程学习

//C文件
#include “BL55077.h”
#include “GPIO.h”

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

  • 初始化 BL55077 的SDA,SCL
    ******************************************************************************/
    void BL55077_GPIO_Init(void)
    {
    stc_gpio_cfg_t stcGpioCfg;

    ///< 端口方向配置->输出(其它参数与以上(输入)配置参数一致)
    stcGpioCfg.enDir = GpioDirOut;
    ///< 端口上下拉配置->上拉
    stcGpioCfg.enPu = GpioPuEnable;
    stcGpioCfg.enPd = GpioPdDisable;
    //开漏输出
    stcGpioCfg.enOD = GpioOdEnable;
    ///<SCL H
    Gpio_WriteOutputIO(GpioPort3, GpioPin3, TRUE);
    //配置 SCL
    Gpio_Init(GpioPort3, GpioPin3, &stcGpioCfg);
    ///< 端口方向配置->输出(其它参数与以上(输入)配置参数一致)
    stcGpioCfg.enDir = GpioDirOut;
    ///< 端口上下拉配置->下拉
    stcGpioCfg.enPu = GpioPuEnable;
    stcGpioCfg.enPd = GpioPdDisable;
    //开漏输出
    stcGpioCfg.enOD = GpioOdEnable;
    ///<SDA H
    Gpio_WriteOutputIO(GpioPort3, GpioPin2, TRUE);
    //配置 SDA
    Gpio_Init(GpioPort3, GpioPin2, &stcGpioCfg);
    }

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

  • @name :void BL55077_Start(void)
  • @date :2021-11-13
  • @function :start BL55077_IIC bus
  • @parameters :None
  • @retvalue :None
    ******************************************************************************/
    void BL55077_Start(void)
    {
    BL55077_SDA_OUT();
    BL55077_SCL_SET();
    delay10us(2);
    BL55077_SDA_SET();
    delay10us(2);
    BL55077_SDA_CLR();
    delay10us(2);
    BL55077_SCL_CLR();
    delay10us(2);
    }

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

  • @name :void BL55077_Stop(void)
  • @date :2021-11-13
  • @function :stop BL55077_IIC bus
  • @parameters :None
  • @retvalue :None
    ******************************************************************************/
    void BL55077_Stop(void)
    {
    BL55077_SDA_OUT();
    BL55077_SCL_CLR();
    delay10us(2);
    BL55077_SDA_CLR();
    delay10us(2);
    BL55077_SCL_SET();
    delay10us(2);
    BL55077_SDA_SET();
    delay10us(2);
    }

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

  • @name :void BL55077_Wait_Ack(void)
  • @date :2021-11-13
  • @function :wait BL55077_IIC ack
  • @parameters :None
  • @retvalue :TRUE OR FALSE
    ******************************************************************************/
    boolean_t BL55077_Wait_Ack(void)
    {
    uint16_t waitack;
    BL55077_SDA_IN();
    BL55077_SCL_SET();
    waitack = 255;
    while(waitack)
    {
    if(BL55077_SDA_READ==0)
    {
    BL55077_SCL_CLR();
    return TRUE;
    }
    waitack–;
    }
    BL55077_Stop();
    return FALSE;
    }

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

  • @name :void Write_BL55077_Byte(uint8_t BL55077_Byte)
  • @date :2021-11-13
  • @function :Write a byte of content with BL55077_IIC bus
  • @parameters :BL55077_Byte
  • @retvalue :None
    ******************************************************************************/
    boolean_t Write_BL55077_Byte(uint8_t BL55077_Byte)
    {
    uint8_t i;
    BL55077_SDA_OUT();
    BL55077_SCL_CLR();
    for(i=0;i<8;i++)
    {
    if(BL55077_Byte&0x80)
    {
    BL55077_SDA_SET();
    }
    else
    {
    BL55077_SDA_CLR();
    }
    BL55077_Byte<<=1;
    BL55077_SCL_SET();
    delay10us(2);
    BL55077_SCL_CLR();
    delay10us(2);
    }
    return BL55077_Wait_Ack();
    }

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

  • @name :uint8_t BL55077_SCAN_SalveAddr(void)
  • @date :2021-11-13
  • @function :扫描BL55077的从机地址
  • @parameters :None
  • @retvalue :TRUE OR FALSE
    ******************************************************************************/

uint8_t BL55077_SCAN_SalveAddr(void)
{
uint8_t salveaddr;
uint8_t buff;

for(salveaddr=0;salveaddr<254;salveaddr+=2)
{
	buff = salveaddr;
	BL55077_Start();	
	if(Write_BL55077_Byte(buff))
	{
		BL55077_SDA_OUT();
		BL55077_Stop();
		return salveaddr;
	}
	BL55077_SDA_OUT();
	BL55077_Stop();
}
return 0xFF;

}

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

  • @name :void BL55077_Init(void)
  • @date :2021-11-13
  • @function :初始化BL55077
  • @parameters None
  • @retvalue :None
    ******************************************************************************/
    void BL55077_Init(void)
    {
    uint8_t i;
    boolean_t result;
    BL55077_Start();
    result = Write_BL55077_Byte(BL55077_SLAVE_ADDR);//0x70
    result = Write_BL55077_Byte(0xE8); // 睡眠控制,关睡眠
    result = Write_BL55077_Byte(0xCE); // 方式设定
    result = Write_BL55077_Byte(0xF0); // 闪烁控制
    // result = Write_BL55077_Byte(0xF0); // BANK选择
    result = Write_BL55077_Byte(0xE0); // 器件选择
    result = Write_BL55077_Byte(0x00); // 数据指针
    for(i=0;i<10;i++)
    {
    result = Write_BL55077_Byte(0x00);
    }
    BL55077_Stop();

}

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

  • @name :void BL55077_DISPLAY1(void)
  • @date :2021-11-13
  • @function :显示图片1
  • @parameters None
  • @retvalue :None
    ******************************************************************************/
    void BL55077_DISPLAY1(void)
    {
    uint8_t i;
    boolean_t result;
    BL55077_Start();
    result = Write_BL55077_Byte(BL55077_SLAVE_ADDR);//0x70
    result = Write_BL55077_Byte(0xE8); // 睡眠控制,关睡眠
    result = Write_BL55077_Byte(0xCE); // 方式设定
    result = Write_BL55077_Byte(0xF0); // 闪烁控制
    // result = Write_BL55077_Byte(0xF0); // BANK选择
    result = Write_BL55077_Byte(0xE0); // 器件选择
    result = Write_BL55077_Byte(0x00); // 数据指针
    for(i=0;i<10;i++)
    {
    result = Write_BL55077_Byte(0x0F);
    }
    BL55077_Stop();
    }

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

  • @name :void BL55077_DISPLAY2(void)
  • @date :2021-11-13
  • @function :显示图片2
  • @parameters None
  • @retvalue :None
    ******************************************************************************/
    void BL55077_DISPLAY2(void)
    {
    uint8_t i;
    boolean_t result;
    BL55077_Start();
    result = Write_BL55077_Byte(BL55077_SLAVE_ADDR);//0x70
    result = Write_BL55077_Byte(0xE8); // 睡眠控制,关睡眠
    result = Write_BL55077_Byte(0xCE); // 方式设定
    result = Write_BL55077_Byte(0xF0); // 闪烁控制
    // result = Write_BL55077_Byte(0xF0); // BANK选择
    result = Write_BL55077_Byte(0xE0); // 器件选择
    result = Write_BL55077_Byte(0x00); // 数据指针
    for(i=0;i<10;i++)
    {
    result = Write_BL55077_Byte(0xF0);
    }
    BL55077_Stop();
    }

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

  • @name :void BL55077_DISPLAY3(void)
  • @date :2021-11-13
  • @function :显示图片全部
  • @parameters None
  • @retvalue :None
    ******************************************************************************/
    void BL55077_DISPLAY_ALL(void)
    {
    uint8_t i;
    boolean_t result;
    BL55077_Start();
    result = Write_BL55077_Byte(BL55077_SLAVE_ADDR);//0x70
    result = Write_BL55077_Byte(0xE8); // 睡眠控制,关睡眠
    result = Write_BL55077_Byte(0xCE); // 方式设定
    result = Write_BL55077_Byte(0xF0); // 闪烁控制
    // result = Write_BL55077_Byte(0xF0); // BANK选择
    result = Write_BL55077_Byte(0xE0); // 器件选择
    result = Write_BL55077_Byte(0x00); // 数据指针
    for(i=0;i<10;i++)
    {
    result = Write_BL55077_Byte(0xFF);
    }
    BL55077_Stop();
    }

// .h 头文件
#ifndef BL55077_H
#define BL55077_H
#include “ddl.h”

//定义IIC从设备地址
#define BL55077_SLAVE_ADDR 0x70

//--------------IIC总线引脚定义-----------------------
#define BL55077_SDA GPIO_Pin_32 //BL55077屏IIC数据信号
#define BL55077_SCL GPIO_Pin_33 //BL55077屏IIC时钟信号

//--------------IIC端口操作定义---------------------
#define BL55077_SDA_SET() M0P_GPIO->P3OUT_f.P32 = 1
#define BL55077_SDA_CLR() M0P_GPIO->P3OUT_f.P32 = 0

#define BL55077_SCL_SET() M0P_GPIO->P3OUT_f.P33 = 1
#define BL55077_SCL_CLR() M0P_GPIO->P3OUT_f.P33 = 0

#define BL55077_SDA_IN() M0P_GPIO->P3DIR_f.P32 = 1
#define BL55077_SDA_OUT() M0P_GPIO->P3DIR_f.P32 = 0
#define BL55077_SDA_READ M0P_GPIO->P3IN_f.P32

//IIC操作函数
void IIC_Start(void);
void IIC_Stop(void);
void IIC_Wait_Ack(void);
boolean_t Write_BL55077_Byte(uint8_t IIC_Byte);
void Write_BL55077_Command(uint8_t IIC_Command);
void Write_BL55077_Data(uint8_t IIC_Data);
void Write_BL55077_nData(uint8_t* IIC_Data,uint16_t Lenth);
void BL55077_GPIO_Init(void);
void BL55077_Init(void);
uint8_t BL55077_SCAN_SalveAddr(void);

void BL55077_DISPLAY1(void);
void BL55077_DISPLAY2(void);
void BL55077_DISPLAY_ALL(void);

#endif

相关文章

发表评论    

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。