1026 views|3 replies

32

Posts

0

Resources
The OP
 

Using CH32V103 to drive TM1637 four-digit digital tube module [Copy link]

 This post was last edited by Xinxin Technology on 2023-5-10 19:20

I refer to the official example and use CH32V103 to drive TM1637 digital tube successfully. The code is very simple. I hope you guys don't criticize me.
TM1637.h:

#ifndef __TM1637_H__
#define __TM1637_H__

#include "ch32v10x_conf.h"

#define  TM1637_DIO_H  GPIO_SetBits(GPIOA,GPIO_Pin_1)    //配置SDA接口高电平
#define  TM1637_DIO_L  GPIO_ResetBits(GPIOA,GPIO_Pin_1)  //配置SDA接口低电平

#define  TM1637_CLK_H  GPIO_SetBits(GPIOA,GPIO_Pin_2)    //配置SCL接口高电平
#define  TM1637_CLK_L  GPIO_ResetBits(GPIOA,GPIO_Pin_2)  //配置SCL接口低电平

#define  TM1637_SDA_READ()  GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_1)  //读SDA口线状态

void TM1637_Init(void);              //初始化TM1637引脚
void TM1637_start(void);               // IIC开始
void TM1637_ack(void);                 // IIC应答
void TM1637_stop(void);                // IIC停止
void TM1637_Write(unsigned char DATA); // 写数据函数
void TM1637_SetBRI(unsigned char i);   // 设置亮度
void TM1637_display(unsigned char a, unsigned char b,
                    unsigned char c, unsigned char d); // 按顺序显示

#endif

TM1637.c:

#include "TM1637.h"
unsigned char tab[] =
    {
        0x3F, /*0*/
        0x06, /*1*/
        0x5B, /*2*/
        0x4F, /*3*/
        0x66, /*4*/
        0x6D, /*5*/
        0x7D, /*6*/
        0x07, /*7*/
        0x7F, /*8*/
        0x6F, /*9*/
        0x77, /*10 A*/
        0x7C, /*11 b*/
        0x58, /*12 c*/
        0x5E, /*13 d*/
        0x79, /*14 E*/
        0x71, /*15 F*/
        0x76, /*16 H*/
        0x38, /*17 L*/
        0x54, /*18 n*/
        0x73, /*19 P*/
        0x3E, /*20 U*/
};


void TM1637_Init(void)//初始化TM1637引脚
{
    GPIO_InitTypeDef GPIO_InitStructure;

    RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOA, ENABLE );

    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1|GPIO_Pin_2;//使用PA1和PA2作为模拟IIC引脚,PA1对应SDA,PA2对应SCL
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP ;   //推挽输出模式
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_Init(GPIOA, &GPIO_InitStructure);
    //IIC_Idle_State();
}

void TM1637_start(void) // IIC开始
{
    TM1637_CLK_H;
    TM1637_DIO_H;
    Delay_Us(2);
    TM1637_DIO_L;
}

void TM1637_ack(void) // IIC应答
{
    u8 i=0;
    TM1637_CLK_L;
    Delay_Us(5);
    TM1637_CLK_H;
    while (TM1637_SDA_READ() == 1 && (i < 250))
        i++;
    TM1637_CLK_H;
    Delay_Us(2);
    TM1637_CLK_L;
}

void TM1637_stop(void) // IIC停止
{
    TM1637_CLK_L;
    Delay_Us(2);
    TM1637_DIO_L;
    Delay_Us(2);
    TM1637_CLK_H;
    Delay_Us(2);
    TM1637_DIO_H;
    Delay_Us(2);
}

void TM1637_Write(unsigned char DATA) // 写数据函数
{
    unsigned char i;
    for (i = 0; i < 8; i++)
    {
        TM1637_CLK_L;
        if (DATA & 0x01)
            TM1637_DIO_H;
        else
            TM1637_DIO_L;
        Delay_Us(2);
        DATA = DATA >> 1;
        TM1637_CLK_H;
        Delay_Us(2);
    }
    // TM1637_ack();
}


void TM1637_display(unsigned char a, unsigned char b, unsigned char c, unsigned char d) // 按顺序显示
{
    TM1637_start();
    TM1637_Write(0x40);
    TM1637_ack();
    TM1637_stop();
    TM1637_start();
    TM1637_Write(0xc0);
    TM1637_ack();

    TM1637_Write(tab[a]);
    TM1637_ack();
    TM1637_Write(tab[b]);
    TM1637_ack();
    TM1637_Write(tab[c]);
    TM1637_ack();
    TM1637_Write(tab[d]);
    TM1637_ack();
    TM1637_stop();
}

void TM1637_SetBRI(unsigned char i) // 设置亮度
{
    TM1637_start();
    TM1637_Write(0x87 + i);
    TM1637_ack();
    TM1637_stop();
}

用CH32V103驱动TM1637数码管.rar

465.44 KB, downloads: 2

This post is from Domestic Chip Exchange

Latest reply

Oh, it should be a module.   Details Published on 2023-5-11 14:18
 
 

5998

Posts

6

Resources
2
 

What does the TM1637 digital tube look like?

This post is from Domestic Chip Exchange

Comments

It should be programmed with TM1637 to drive the digital tube  Details Published on 2023-5-10 14:12
Personal signature

在爱好的道路上不断前进,在生活的迷雾中播撒光引

 
 
 

1w

Posts

25

Resources
3
 
Qintianqintian0303 posted on 2023-5-10 13:41 What does the TM1637 digital tube look like?

It should be programmed with TM1637 to drive the digital tube

This post is from Domestic Chip Exchange

Comments

Oh, it should be a module.  Details Published on 2023-5-11 14:18
 
 
 

5998

Posts

6

Resources
4
 
dcexpert posted on 2023-5-10 14:12 It should be programming to use TM1637 to drive the digital tube

Oh, it should be a module.

This post is from Domestic Chip Exchange
Personal signature

在爱好的道路上不断前进,在生活的迷雾中播撒光引

 
 
 

Guess Your Favourite
Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

Featured Posts
Homemade STEVAL-IPM05F 3Sh board: FOC motor control 400V/8A non-sensing/sensing Hall/sensing encoder and other reference programs...

This post was last edited by music_586 on 2019-4-4 19:06 This content was originally created by EEWORLD forum user musi ...

Based on IPM05F 3Sh board: FOC motor control 400V non-sensing sensory encoder all design data summary (schematic diagram/BOM table...

Based on IPM05F 3Sh board: FOC motor control 400V sensorless and sensory encoder all design data summary (schematic diag ...

"Recommend Chinese chips" + domestic chips

I have used or seen quite a lot of domestic chips. I won't mention Shenwei and Loongson. Basically, anyone who works wit ...

Two highlights of EFM32PG22

I think the M33 core and 16-bit ADC are pretty good.

[HPM-DIY] HPM6750 uses cherryusb to read UVC camera to display VGA resolution

I received the display module from EE last week and finally used it tonight. HPM6750 acts as a host to read the UVC came ...

Is it possible to perform socket communication without IP and port number?

When using socket communication, whether it is internal communication within the local machine or communication betwee ...

全志V853 NPU 转换部署 YOLO V5 模型

# NPU conversion and deployment of YOLO V5 model This article takes the YOLO v5s model as an example to detail the conve ...

What is light load mode?

The technique of improving efficiency when using less output current is called light load mode. It is also called burst ...

[ST NUCLEO-U5A5ZJ-Q development board review] 2. EXTI, PWM and serial port printf

Serial port printf output The serial port 1 of Nucleo-U5A5 is connected to the serial port of STlinkV3 to output the pri ...

What are the functions of the five pins INT, MOSI, MISO, SCK, and NCS of the MPU attitude sensor? Is the waveform correct?

What are the functions of the five pins INT, MOSI, MISO, SCK, and NCS of the MPU attitude sensor? Is the waveform correc ...

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list