找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 73|回复: 2
打印 上一主题 下一主题
收起左侧

puya32f030串口驱动Tm1652显示问题

[复制链接]
跳转到指定楼层
楼主
我想请问为啥我的串口 设置是这样 驱动不了TM1652 是不是我的哪里程序有问题 有帮忙看看的么


代码附在下面
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]);


  }
}
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享淘帖 顶 踩
回复

使用道具 举报

沙发
ID:1066795 发表于 2025-5-6 14:42 | 只看该作者
回复

使用道具 举报

板凳
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);
回复

使用道具 举报

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

本版积分规则

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

Powered by 单片机教程网

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