|
我想請(qǐng)問(wèn)為啥我的串口 設(shè)置是這樣 驅(qū)動(dòng)不了TM1652 是不是我的哪里程序有問(wèn)題 有幫忙看看的么
51hei圖片_20250506142624.png (951.45 KB, 下載次數(shù): 0)
下載附件
2025-5-6 14:37 上傳
51hei圖片_20250506142632.png (220.96 KB, 下載次數(shù): 0)
下載附件
2025-5-6 14:37 上傳
代碼附在下面
tm1652規(guī)格書(shū):
Tm1652.pdf
(366.28 KB, 下載次數(shù): 0)
2025-5-6 14:42 上傳
點(diǎn)擊文件名下載附件
/*********************************************************************
* 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時(shí)鐘使能*/
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; // 修改為奇校驗(yàn)
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]);
}
}
|
|