#include "gd32f4xx.h"
#include "gd32f450z_eval.h"
#include<stdio.h>
void uart_init(void);
void uart_send_data(uint8_t data);
uint8_t uart_receive_data(void);
int main(void)
{
uint8_t data;
gd_eval_led_init(LED2);
uart_init();
while (1)
{
data = uart_receive_data();
if (data != 0)
{
uart_send_data(data);
gd_eval_led_toggle(LED2);
}
}
}
void uart_init(void)
{
gd_eval_com_init(EVAL_COM1, 115200);
}
void uart_send_data(uint8_t data)
{
usart_data_transmit(EVAL_COM1, data);
while (usart_flag_get(EVAL_COM1, USART_FLAG_TC) == RESET);
}
uint8_t uart_receive_data(void)
{
if (usart_flag_get(EVAL_COM1, USART_FLAG_RBNE) != RESET)
{
return usart_data_receive(EVAL_COM1);
}
return 0;
} |