找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 230|回復: 8
打印 上一主題 下一主題
收起左側(cè)

puya32f030串口驅(qū)動Tm1652顯示問題

[復制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:1066795 發(fā)表于 2025-5-6 14:32 | 只看該作者 |只看大圖 回帖獎勵 |倒序瀏覽 |閱讀模式
我想請問為啥我的串口 設置是這樣 驅(qū)動不了TM1652 是不是我的哪里程序有問題 有幫忙看看的么


代碼附在下面
tm1652規(guī)格書: Tm1652.pdf (366.28 KB, 下載次數(shù): 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空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏1 分享淘帖 頂 踩
回復

使用道具 舉報

沙發(fā)
ID:1066795 發(fā)表于 2025-5-6 14:42 | 只看該作者
我參考這個的來著 "基于STM32CUBE的UART串口驅(qū)動TM1652程序"
回復

使用道具 舉報

板凳
ID:1066795 發(fā)表于 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 發(fā)表于 2025-5-7 16:39 | 只看該作者
你可以先用PC的串口助手發(fā)數(shù)據(jù),來觀察一下1652會不會正常?
回復

使用道具 舉報

5#
ID:1066795 發(fā)表于 2025-5-7 17:06 | 只看該作者
zhuls 發(fā)表于 2025-5-7 16:39
你可以先用PC的串口助手發(fā)數(shù)據(jù),來觀察一下1652會不會正常?


不太行 沒顯示
回復

使用道具 舉報

6#
ID:1066795 發(fā)表于 2025-5-7 17:09 | 只看該作者
zhuls 發(fā)表于 2025-5-7 16:39
你可以先用PC的串口助手發(fā)數(shù)據(jù),來觀察一下1652會不會正常?


沒顯示

51hei圖片_20250506142632.png (220.96 KB, 下載次數(shù): 0)

51hei圖片_20250506142632.png

51hei圖片_20250506142624.png (951.45 KB, 下載次數(shù): 0)

51hei圖片_20250506142624.png
回復

使用道具 舉報

7#
ID:1066795 發(fā)表于 2025-5-7 17:37 | 只看該作者

回復

使用道具 舉報

8#
ID:1066795 發(fā)表于 2025-5-7 17:50 | 只看該作者
zhuls 發(fā)表于 2025-5-7 16:39
你可以先用PC的串口助手發(fā)數(shù)據(jù),來觀察一下1652會不會正常?

可能我的串口有問題 發(fā)送下面的HEX TX燈都不閃
08 3F 06 5B 4F FF
18 1D
回復

使用道具 舉報

9#
ID:1066795 發(fā)表于 2025-5-8 14:50 | 只看該作者
yslsdas 發(fā)表于 2025-5-7 17:50
可能我的串口有問題 發(fā)送下面的HEX TX燈都不閃
08 3F 06 5B 4F FF
18 1D

破案了一把直接用到壞芯片啊 可以正常顯示
回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

手機版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術交流QQ群281945664

Powered by 單片機教程網(wǎng)

快速回復 返回頂部 返回列表