FD650B数码管驱动

FD650B数码驱动

最近手头有几个4位带时钟点的数码管模块,使用的是FD650B驱动芯片,官方网站上没有找到编程资料,共享一下:
主要是头文件:

#ifndef __FD650_H
#define __FD650_H

#include "main.h"

/* FD650 Function Define */
#define FD650_BIT_ENABLE					0x01					//开启/关闭位
#define FD650_BIT_SLEEP						0x04					//睡眠控制位
#define FD650_BIT_7SEG						0x08					//7段控制位
#define FD650_BIT_INTENS1					0x10					//1级亮度
#define FD650_BIT_INTENS2					0x20					//2级亮度
#define FD650_BIT_INTENS3					0x30					//3级亮度
#define FD650_BIT_INTENS4					0x40					//4级亮度
#define FD650_BIT_INTENS5					0x50					//5级亮度
#define FD650_BIT_INTENS6					0x60					//6级亮度
#define FD650_BIT_INTENS7					0x70					//7级亮度
#define FD650_BIT_INTENS8					0x00					//8级亮度

#define FD650_SYSOFF				0x0400															//关闭显示、关闭键盘
#define FD650_SYSON				( FD650_SYSOFF | FD650_BIT_ENABLE )		//开启显示、键盘
#define FD650_SLEEPOFF		FD650_SYSOFF													//关闭睡眠
#define FD650_SLEEPON			( FD650_SYSOFF | FD650_BIT_SLEEP )		//开启睡眠
#define FD650_7SEG_ON			( FD650_SYSON | FD650_BIT_7SEG )			//开启七段模式
#define FD650_8SEG_ON			( FD650_SYSON | 0x00 )								//开启八段模式
#define FD650_SYSON_1			( FD650_SYSON | FD650_BIT_INTENS1 )		//开启显示、键盘、1级亮度
//以此类推
#define FD650_SYSON_4			( FD650_SYSON | FD650_BIT_INTENS4 )		//开启显示、键盘、4级亮度
//以此类推
#define FD650_SYSON_8			( FD650_SYSON | FD650_BIT_INTENS8 )		//开启显示、键盘、8级亮度


//加载字数据命令
#define FD650_DIG0					0x1400				//数码管位0显示,需另加8位数据
#define FD650_DIG1					0x1500				//数码管位1显示,需另加8位数据
#define FD650_DIG2					0x1600				//数码管位2显示,需另加8位数据
#define FD650_DIG3					0x1700				//数码管位3显示,需另加8位数据
#define FD650_DOT						0x0080				//数码管小数点显示

//读取按键代码命令
#define FD650_GET_KEY				0x0700				//获取按键,返回按键代码

//延时宏定义
#define FD650_DELAY()				HAL_Delay(1)

typedef struct
{
	uint8_t character;
	uint8_t bitmap;
}
LED_Bitmap_Typedef;


void FD650_Start(void);
void FD650_Stop(void);
void FD650_WriteOneByte(uint8_t WriteByte);
//uint8_t FD650_ReadOneByte(void);
void FD650_WriteCommand(uint16_t WriteCommand);
void FD650_Display_All(void);
void FD650_Display_Clean(void);
void FD650_Display(uint8_t Data1, uint8_t Data2, uint8_t Data3, uint8_t Data4, uint8_t Brightness);
void FD650_PutDisplayValue(uint16_t DispVal, uint8_t Brightness);

#endif
//

然后是源文件了,因为只有数码管显示,没有按键,所以取消了读取函数:

#include "fd650.h"

#define FD650_SCL_SET()		HAL_GPIO_WritePin(FD650_CLK_GPIO_Port,FD650_CLK_Pin,GPIO_PIN_SET)
#define FD650_SCL_CLR()		HAL_GPIO_WritePin(FD650_CLK_GPIO_Port,FD650_CLK_Pin,GPIO_PIN_RESET)

#define FD650_SDA_SET()		HAL_GPIO_WritePin(FD650_SDA_GPIO_Port,FD650_SDA_Pin,GPIO_PIN_SET)
#define FD650_SDA_CLR()		HAL_GPIO_WritePin(FD650_SDA_GPIO_Port,FD650_SDA_Pin,GPIO_PIN_RESET)

/* the numbering of the frontpanel LED:
           --0--
         5|     |1
           --6--
         4|     |2
           --3-- .7
*/
uint8_t  FD650_DispSegCode[]= {0x3F, 0x06, 0x5B, 0x4F, 0x66, 0x6D, 0x7D, 0x07, 0x7F, 0x6F, 0x77, 0x7C, 0x39, 0x5E, 0x79, 0x71};	 //共阴段码
const LED_Bitmap_Typedef BCD_decode_tab[] =
{
	{'0', 0x3F}, {'1', 0x06}, {'2', 0x5B}, {'3', 0x4F},
	{'4', 0x66}, {'5', 0x6D}, {'6', 0x7D}, {'7', 0x07},
	{'8', 0x7F}, {'9', 0x6F}, {'a', 0x77}, {'A', 0x77},
	{'b', 0x7C}, {'B', 0x7C}, {'c', 0x58}, {'C', 0x39},
	{'d', 0x5E}, {'D', 0x5E}, {'e', 0x79}, {'E', 0x79},
	{'f', 0x71}, {'F', 0x71}, {'L', 0x38}, {'P', 0x73},
	{'r', 0x50}, {'t', 0x78}, {'n', 0x54}, {'o', 0x5c},
	{'U', 0x3e}, {'s', 0x6D}, {'H', 0x76}, {'h', 0x74},
	{'-', 0x40}, {'N', 0x37}, {'O', 0x3F},
};//BCD码字映射


void FD650_Start(void)
/**
* \brief       FD650_Start
*
* \param       None
*
* \retval      None
*/
{
//	FD650_SDA_D_OUT(); 	//SDA输出模式
	FD650_SDA_SET();
	FD650_SCL_SET();
	FD650_DELAY();
	FD650_SDA_CLR();
	FD650_DELAY();
	FD650_SCL_CLR();
}

void FD650_Stop(void)
/**
* \brief       FD650_Stop
*
* \param       None
*
* \retval      None
*/
{
//	FD650_SDA_D_OUT(); 	//SDA输出模式
	FD650_SDA_CLR();
	FD650_DELAY();
	FD650_SCL_SET();
	FD650_DELAY();
	FD650_SDA_SET();
	FD650_DELAY();
//	FD650_SDA_D_IN();		//SDA输入模式
}

void FD650_WriteOneByte(uint8_t WriteByte)
/**
* \brief       Write One Byte data
*
* \param       WriteByte
*
* \retval      None
*/
{
	uint8_t i;
//	FD650_SDA_D_OUT(); 	//SDA输出模式
	for(i = 0; i != 8; i++)
	{
		if(WriteByte & 0x80)
		{
			FD650_SDA_SET();
		}
		else
		{
			FD650_SDA_CLR();
		}
	  FD650_DELAY();
		FD650_SCL_SET();
		WriteByte <<= 1;
		FD650_DELAY();
	  FD650_SCL_CLR();
	}
//	FD650_SDA_D_IN();		//SDA输入模式
	FD650_SDA_SET();
	FD650_DELAY();
	FD650_SCL_SET();
	FD650_DELAY();
	FD650_SCL_CLR();
}

//uint8_t FD650_ReadOneByte(void)
///**
//* \brief       Read One Byte data
//*
//* \param       WriteByte
//*
//* \retval      None
//*/
//{
//	uint8_t i, ReadByte = 0;
//	FD650_SDA_SET();
//	FD650_SDA_D_IN();		//SDA输入模式
//	for(i = 0; i != 8; i++)
//	{
//		FD650_DELAY();
//		FD650_SCL_SET();
//		FD650_DELAY();
//		ReadByte <<= 1;
//		if(FD650_SDA_READ()) ReadByte++;
//		FD650_SCL_CLR();
//	}
//	FD650_SDA_SET();
//	FD650_DELAY();
//	FD650_SCL_SET();
//	FD650_DELAY();
//	FD650_SCL_CLR();
//	return ReadByte;
//}

void FD650_WriteCommand(uint16_t WriteCommand)
/**
* \brief       通过发送命令参数
*
* \param       WriteCommand
*
* \retval      None
*/
{
	FD650_Start();
	FD650_WriteOneByte(((uint8_t)((WriteCommand >> 7) & 0x3E) | 0x40));
	FD650_WriteOneByte((uint8_t)WriteCommand);
	FD650_Stop();
}

void FD650_Display_All(void)
/**
* \brief       display all
*
* \param       None
*
* \retval      None
*/
{
	FD650_WriteCommand(FD650_SYSON_8);
	FD650_WriteCommand(FD650_DIG0 | 0xFF );
	FD650_WriteCommand(FD650_DIG1 | 0xFF );
	FD650_WriteCommand(FD650_DIG2 | 0xFF );
	FD650_WriteCommand(FD650_DIG3 | 0xFF );
}

void FD650_Display_Clean(void)
/**
* \brief       not display all
*
* \param       None
*
* \retval      None
*/
{
	FD650_WriteCommand(FD650_SYSON_8);
	FD650_WriteCommand(FD650_DIG0 | 0x00);
	FD650_WriteCommand(FD650_DIG1 | 0x00);
	FD650_WriteCommand(FD650_DIG2 | 0x00);
	FD650_WriteCommand(FD650_DIG3 | 0x00);
}

void FD650_Display(uint8_t Data1, uint8_t Data2, uint8_t Data3, uint8_t Data4, uint8_t Brightness)
/**
* \brief       not display all
*
* \param       None
*
* \retval      None
*/
{
	FD650_WriteCommand(FD650_SYSON | Brightness);
	FD650_WriteCommand(FD650_DIG0 | FD650_DispSegCode[Data1]);
	FD650_WriteCommand(FD650_DIG1 | FD650_DispSegCode[Data2]);
	FD650_WriteCommand(FD650_DIG2 | FD650_DispSegCode[Data3]);
	FD650_WriteCommand(FD650_DIG3 | FD650_DispSegCode[Data4]);
}

void FD650_PutDisplayValue(uint16_t DispVal, uint8_t Brightness)
{
	FD650_Display(DispVal / 1000	% 10, DispVal / 100 % 10, DispVal / 10 % 10, DispVal / 1 % 10, Brightness);
}


//

单片机使用的是STM32F103C8的最小系统板,主时钟频率8M,
硬件端口使用
PB10----SCL,
PB11----SDA.
FD650B的推荐频率在100KHz,因为只是验证驱动,直接套用的延时函数是HAL_Delay(1)微秒延时,造成刷屏比较慢,实际使用可以根据情况调整。

上一篇:IIC的SDA_IN SDA_OUT


下一篇:IIC通信笔记