LED 驱动控制专用电路
作者:向阳逐梦
- 2023-11-24 四川
本文字数:2482 字
阅读完需:约 8 分钟

一、基本概述
TM1628 是一种带键盘扫描接口的 LED(发光二极管显示器)驱动控制专用 IC,内部集成有 MCU 数
字接口、数据锁存器、LED 驱动、键盘扫描等电路。本产品质量可靠、稳定性好、抗干扰能力强。
主要适用于家电设备(智能热水器、微波炉、洗衣机、空调、电磁炉)、机顶盒、电子称、智能电
表等数码管或 LED 显示设备。
二、特性说明
采用 CMOS 工艺
多种显示模式(10 段×7 位 ~ 13 段×4 位)
最大支持矩阵按键 10×2
辉度调节电路(8 级占空比可调)
串行接口(CLK,STB,DIO)
振荡方式:内置 RC 振荡
内置上电复位电路
内置数据锁存电路
抗干扰能力强
封装形式:SOP28
三、引脚定义

四、指令说明





五、显示




六、应用电路



七、封装尺寸


电路原理图设计

程序代码
.c文件
#include "TM1628.h"
u8 const CODE[]={0xC0,0xC2,0xC4,0xC6,0xC8,0xCA,0xCC};//GRID1 GRID2 GRID3 GRID4 GRID5 GRID6 GRID7
/*************************************
函数名称:Tm1628init
函数说明:TM1628初始化
函数参数:NULL
函数返回:NULL
*************************************/
void Tm1628init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7 | GPIO_Pin_5;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //
GPIO_Init(GPIOB, &GPIO_InitStructure); //
GPIO_SetBits(GPIOB,GPIO_Pin_5);
Tm1628_ClearDisplay(); //清屏
Tm1628_GrayScale(2); //亮度2
}
/*************************************
函数名称:Tm1628_Write_Bit
函数说明:写单个字节
函数参数:命令返回
函数返回:NULL
*************************************/
void Tm1628_Write_Bit(uint8_t data)
{
uint8_t i;
for(i = 0; i < 8; i++)
{
if((data & 0x01) == 1)
{
Tm1628_DIO_H;
}
else
{
Tm1628_DIO_L;
}
Tm1628_CKL_L;
Tm1628_CKL_H;
data = data >> 1;
}
}
/*************************************
函数名称:Tm1628_Write_Command
函数说明:写命令
函数参数:命令参数
函数返回:NULL
*************************************/
void Tm1628_Write_Command(u8 unm)
{
Tm1628_STB_H;
Tm1628_STB_L;
Tm1628_Write_Bit(unm);
}
/*************************************
函数名称:Tm1628_Continuous
函数说明:固定写显示
函数参数:(1)add 地址 (2)data 数据
函数返回:NULL
*************************************/
void Tm1628_Continuous(uint8_t add,uint8_t data)
{
Tm1628_Write_Command(0x03);
Tm1628_Write_Command(0x44);
Tm1628_Write_Command(add);
Tm1628_Write_Bit(data);
Tm1628_Write_Command(0x8F);
Tm1628_STB_H;
}
/*************************************
函数名称:Tm1628_ClearDisplay
函数说明:清屏
函数参数:NULL
函数返回:NULL
*************************************/
void Tm1628_ClearDisplay(void)
{
uint8_t i;
Tm1628_Write_Command(0x03); //7位10段
for(i = 0; i < 7; i++)
{
Tm1628_Write_Command(CODE[i]);
Tm1628_Write_Bit(0x00);
Tm1628_STB_H;
}
}
/*************************************
函数名称:Tm1628_GrayScale
函数说明:用于亮度调节 0 - 9
函数参数:亮度 0 - 9
函数返回:NULL
*************************************/
void Tm1628_GrayScale(uint8_t data)
{
switch(data)
{
case(0): Tm1628_Write_Command(GrayScale_ON); break;
case(1): Tm1628_Write_Command(GrayScale1); break;
case(2): Tm1628_Write_Command(GrayScale2); break;
case(3): Tm1628_Write_Command(GrayScale3); break;
case(4): Tm1628_Write_Command(GrayScale4); break;
case(5): Tm1628_Write_Command(GrayScale5); break;
case(6): Tm1628_Write_Command(GrayScale6); break;
case(7): Tm1628_Write_Command(GrayScale7); break;
case(8): Tm1628_Write_Command(GrayScale8); break;
}
}
复制代码
.h文件
#ifndef __TM1628_H
#define __TM1628_H
#include "sys.h"
#include "delay.h"
#define Tm1628_CKL_H GPIO_WriteBit(GPIOB,GPIO_Pin_6,Bit_SET)
#define Tm1628_CKL_L GPIO_WriteBit(GPIOB,GPIO_Pin_6,Bit_RESET)
#define Tm1628_DIO_H GPIO_WriteBit(GPIOB,GPIO_Pin_7,Bit_SET)
#define Tm1628_DIO_L GPIO_WriteBit(GPIOB,GPIO_Pin_7,Bit_RESET)
#define Tm1628_STB_H GPIO_WriteBit(GPIOB,GPIO_Pin_5,Bit_SET)
#define Tm1628_STB_L GPIO_WriteBit(GPIOB,GPIO_Pin_5,Bit_RESET)
#define GrayScale_OFF 0x80 //关显示
#define GrayScale_ON 0x81 //开显示
#define GrayScale1 0x88 //灰度等级1
#define GrayScale2 0x89 //灰度等级2
#define GrayScale3 0x8A //灰度等级3
#define GrayScale4 0x8B //灰度等级4
#define GrayScale5 0x8C //灰度等级5
#define GrayScale6 0x8D //灰度等级6
#define GrayScale7 0x8E //灰度等级7
#define GrayScale8 0x8F //灰度等级8
void Tm1628init(void); //TM1628初始化
void Tm1628_Fixed(uint8_t data, uint8_t add); //固定写地址 data 地址 add 数据
void Tm1628_Continuous(uint8_t add,uint8_t data);
void Tm1628_ClearDisplay(void); //清屏
void Tm1628_GrayScale(uint8_t data); //亮度调节
void Tm1628_Write_Command(u8 unm);
#endif
复制代码
main主函数
int main(void)
{
RCC_Configuration();
Tm1628init();//TM1628初始化程序
while(1)
{
Tm1628_Continuous(0xCA,0xFF); //GRID6
Tm1628_Continuous(0xC8,0xFF); //GRID5
Tm1628_Continuous(0xC6,0xFF); //GRID4
Tm1628_Continuous(0xC4,0xFF); //GRID3
Tm1628_Continuous(0xC2,0xFF); //GRID2
Tm1628_Continuous(0xC0,0xFF); //GRID1
}
}
复制代码
实物效果

划线
评论
复制
发布于: 刚刚阅读数: 6
版权声明: 本文为 InfoQ 作者【向阳逐梦】的原创文章。
原文链接:【http://xie.infoq.cn/article/4453e99990bbba2c3fca1db14】。文章转载请联系作者。


向阳逐梦
关注
人生享受编程,编程造就人生! 2022-06-01 加入
某公司芯片测试工程师,嵌入式开发工程师,InfoQ签约作者,阿里云星级博主,华为云·云享专家。座右铭:向着太阳,追逐梦想!
评论