找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 653|回复: 8
收起左侧

puya32f030串口驱动Tm1652显示问题

[复制链接]
ID:1066795 发表于 2025-5-6 14:32 | 显示全部楼层 |阅读模式
我想请问为啥我的串口 设置是这样 驱动不了TM1652 是不是我的哪里程序有问题 有帮忙看看的么
51hei图片_20250506142624.png 51hei图片_20250506142632.png

代码附在下面
tm1652规格书: Tm1652.pdf (366.28 KB, 下载次数: 0)
/*********************************************************************
* INCLUDES
*
*/
#include "stdlib.h"
#include "py32f0xx_hal.h"
#include "py32f0xx_hal_uart.h"
#include "tm1652.h"


/*********************************************************************
* LOCAL VARIABLES
*/
uint8_t s_7number[10] = {0x3F, 0x06, 0x5B, 0x4F, 0x66, 0x6D, 0x7D, 0x07, 0x7F, 0x6F}; // 7段显示方式0~9
uint8_t Buffer_Tab[11] = {0x77, 0x14, 0x6E, 0x3E, 0x1D, 0x3B, 0x7B, 0x16, 0x7F, 0x3F};

uint8_t seg_no_dot[11] = {0x3f, 0x06, 0x5b, 0x4F, 0x66, 0x6D, 0x7D, 0x07, 0x7F, 0x6F, 0x00};
uint8_t seg_with_dot[11] = {0xbf, 0x86, 0xdb, 0xcF, 0xe6, 0xeD, 0xfD, 0x87, 0xfF, 0xeF, 0x80};

UART_HandleTypeDef Uart1_Handle;
/*********************************************************************
* PUBLIC FUNCTIONS
*/




void HAL_UART_MspInit(UART_HandleTypeDef *UartHandle)
{

    if (UartHandle->Instance == USART1)
    {
        GPIO_InitTypeDef Uart_GPIO_InitConfig;

        /*USART1时钟使能*/
        TM1652_Tx_GPIO_CLK_ENABLE();
        __HAL_RCC_USART1_CLK_ENABLE();

        Uart_GPIO_InitConfig.Pin = TM1652_Tx_GPIO_PIN;
        Uart_GPIO_InitConfig.Mode = GPIO_MODE_AF_PP;
        Uart_GPIO_InitConfig.Pull = GPIO_PULLUP;
        Uart_GPIO_InitConfig.Speed = GPIO_SPEED_FREQ_HIGH;
        Uart_GPIO_InitConfig.Alternate = GPIO_AF0_USART1;
        HAL_GPIO_Init(TM1652_Tx_GPIO_PORT, &Uart_GPIO_InitConfig);

    }
}

void address_auto_add1(uint8_t addr,uint8_t dat1,uint8_t dat2,uint8_t dat3)
{
        uint8_t dat_buf[4] = {0};
        dat_buf[0] = addr;
        dat_buf[1] = seg_no_dot[dat1];
        dat_buf[2] = seg_with_dot[dat2];
        dat_buf[3] = seg_no_dot[dat3];
        HAL_UART_Transmit(&Uart1_Handle,dat_buf,4,0xfff);
        HAL_Delay(5);
        
        dat_buf[0] = 0x18;
        dat_buf[1] = 0x1D;
        HAL_UART_Transmit(&Uart1_Handle,dat_buf,2,0xfff);
        HAL_Delay(5);
}

void close_seg(void)
{
        uint8_t dat_buf[2] = {0};
        dat_buf[0] = 0x18;
        dat_buf[1] = 0x00;
        HAL_UART_Transmit(&Uart1_Handle,dat_buf,2,0xfff);
        HAL_Delay(5);
}

void tm1652_init(void)
{
    Uart1_Handle.Instance = USART1;
    Uart1_Handle.Init.BaudRate = 19200;
    Uart1_Handle.Init.WordLength = UART_WORDLENGTH_9B;
    Uart1_Handle.Init.StopBits = UART_STOPBITS_1;
    Uart1_Handle.Init.Parity = UART_PARITY_ODD; // 修改为奇校验
    Uart1_Handle.Init.Mode = UART_MODE_TX;
    Uart1_Handle.Init.HwFlowCtl = UART_HWCONTROL_NONE;

    HAL_UART_Init(&Uart1_Handle);

}
/*********************************************************************
*

*/

/****************************************************END OF FILE****************************************************/


#ifndef _TM1652_H_
#define _TM1652_H_

/*********************************************************************
* INCLUDES
*/
#include "py32f0xx_hal.h"

/*********************************************************************
* DEFINITIONS
*/

#define TM1652_Tx_GPIO_CLK_ENABLE __HAL_RCC_GPIOB_CLK_ENABLE
#define TM1652_Tx_GPIO_PORT GPIOB
#define TM1652_Tx_GPIO_PIN GPIO_PIN_6
/*********************************************************************
* API FUNCTIONS
*/
extern uint8_t seg_with_dot[11];
extern uint8_t seg_no_dot[11];
extern uint8_t s_7number[10];
extern uint8_t Buffer_Tab[11];

void tm1652_init(void);
void address_auto_add1(uint8_t addr,uint8_t dat1,uint8_t dat2,uint8_t dat3);
void address_auto_add1_low(uint8_t addr,uint8_t dat1,uint8_t dat2,uint8_t dat3);
void close_seg(void);


#endif /* _TM1650_H_ */

int main(void)
{
  /* Reset of all peripherals, Initializes the Systick. */
  HAL_Init();

  /* Configure the system clock */
  APP_SystemClockConfig();
  tm1652_init();
        
  while (1)
               
  {
    address_auto_add1(0x08, Buffer_Tab[0], Buffer_Tab[0], Buffer_Tab[0]);


  }
}
回复

使用道具 举报

ID:1066795 发表于 2025-5-6 14:42 | 显示全部楼层
我参考这个的来着 "基于STM32CUBE的UART串口驱动TM1652程序"
回复

使用道具 举报

ID:1066795 发表于 2025-5-6 16:44 | 显示全部楼层
address_auto_add1(0x08, Buffer_Tab[0], Buffer_Tab[0], Buffer_Tab[0]);改成   address_auto_add1(0x08, 1, 2, 1);
回复

使用道具 举报

ID:69038 发表于 2025-5-7 16:39 | 显示全部楼层
你可以先用PC的串口助手发数据,来观察一下1652会不会正常?
回复

使用道具 举报

ID:1066795 发表于 2025-5-7 17:06 | 显示全部楼层
zhuls 发表于 2025-5-7 16:39
你可以先用PC的串口助手发数据,来观察一下1652会不会正常?

51hei图片_20250507170603.png
不太行 没显示
回复

使用道具 举报

ID:1066795 发表于 2025-5-7 17:09 | 显示全部楼层
zhuls 发表于 2025-5-7 16:39
你可以先用PC的串口助手发数据,来观察一下1652会不会正常?

51hei图片_20250507170603.png
没显示
51hei图片_20250506142632.png
51hei图片_20250506142624.png
回复

使用道具 举报

ID:1066795 发表于 2025-5-7 17:37 | 显示全部楼层
51hei图片_20250507170603.png
回复

使用道具 举报

ID:1066795 发表于 2025-5-7 17:50 | 显示全部楼层
zhuls 发表于 2025-5-7 16:39
你可以先用PC的串口助手发数据,来观察一下1652会不会正常?

可能我的串口有问题 发送下面的HEX TX灯都不闪
08 3F 06 5B 4F FF
18 1D
回复

使用道具 举报

ID:1066795 发表于 2025-5-8 14:50 | 显示全部楼层
yslsdas 发表于 2025-5-7 17:50
可能我的串口有问题 发送下面的HEX TX灯都不闪
08 3F 06 5B 4F FF
18 1D

破案了一把直接用到坏芯片啊 可以正常显示
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表