ht32 驱动txrx串口屏代码
时间: 2024-01-01 09:53:03 浏览: 149
STM32驱动RX8025T程序.zip
5星 · 资源好评率100%
以下是一个简单的 HT32 驱动 TXRX 串口屏的代码示例:
```c
#include "ht32f5xxxx_01.h"
#include "ht32f5xxxx_usart.h"
#include "ht32f5xxxx_gpio.h"
#define USART_TX_PIN GPIO_PIN_9
#define USART_TX_GPIO_PORT HT_GPIOF
#define USART_RX_PIN GPIO_PIN_10
#define USART_RX_GPIO_PORT HT_GPIOF
void USART_Configuration(void)
{
USART_InitTypeDef USART_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
// 使能 USART 和 GPIO 时钟
CKCU_PeripClockConfig_TypeDef CKCUClock = {{0}};
CKCUClock.Bit.PA = 1;
CKCUClock.Bit.AFIO = 1;
CKCUClock.Bit.USART0 = 1;
CKCU_PeripClockConfig(CKCUClock, ENABLE);
// 配置 USART 引脚为复用功能
GPIO_InitStructure.GPIO_Pin = USART_TX_PIN;
GPIO_InitStructure.GPIO_Mode = GPIO_MODE_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_SPEED_50MHZ;
GPIO_Init(USART_TX_GPIO_PORT, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = USART_RX_PIN;
GPIO_InitStructure.GPIO_Mode = GPIO_MODE_FLOATING;
GPIO_Init(USART_RX_GPIO_PORT, &GPIO_InitStructure);
// 配置 USART 参数
USART_InitStructure.USART_BaudRate = 115200;
USART_InitStructure.USART_WordLength = USART_WORDLENGTH_8B;
USART_InitStructure.USART_StopBits = USART_STOPBITS_1;
USART_InitStructure.USART_Parity = USART_PARITY_NO;
USART_InitStructure.USART_HardwareFlowControl = USART_HARDWAREFLOWCONTROL_NONE;
USART_InitStructure.USART_Mode = USART_MODE_TX_RX;
USART_Init(HT_USART0, &USART_InitStructure);
// 使能 USART
USART_Cmd(HT_USART0, ENABLE);
}
void USART_SendString(char *str)
{
while(*str != '\0')
{
USART_SendData(HT_USART0, *str++);
while(USART_GetFlagStatus(HT_USART0, USART_FLAG_TXE) == RESET);
}
}
int main(void)
{
USART_Configuration();
USART_SendString("Hello, TXRX Screen!\r\n");
while(1);
}
```
需要注意的是,这只是一个基本的示例代码,实际情况下可能需要根据具体的 TXRX 串口屏的通信协议进行相应的修改。
阅读全文