📄 main.c
字号:
#include "71x_lib.h"
#define UART0_Rx_Pin (0x0001<<8) // TQFP 64: pin N?63 , TQFP 144 pin N?143
#define UART0_Tx_Pin (0x0001<<9) // TQFP 64: pin N?64 , TQFP 144 pin N?144
#define UART1_Rx_Pin (0x0001<<10) // TQFP 64: pin N?1 , TQFP 144 pin N?1
#define UART1_Tx_Pin (0x0001<<11) // TQFP 64: pin N?2 , TQFP 144 pin N?3
#define UART2_Rx_Pin (0x0001<<13) // TQFP 64: pin N?5 , TQFP 144 pin N?9
#define UART2_Tx_Pin (0x0001<<14) // TQFP 64: pin N?6 , TQFP 144 pin N?10
#define UART3_Rx_Pin (0x0001<<1) // TQFP 64: pin N?52 , TQFP 144 pin N?123
#define UART3_Tx_Pin (0x0001<<0) // TQFP 64: pin N?53 , TQFP 144 pin N?124
#define Use_UART0
//#define Use_UART1
//#define Use_UART2
//#define Use_UART3
#ifdef Use_UART0
#define UARTX UART0
#define UARTX_Rx_Pin UART0_Rx_Pin
#define UARTX_Tx_Pin UART0_Tx_Pin
#endif /* Use_UART0 */
#ifdef Use_UART1
#define UARTX UART1
#define UARTX_Rx_Pin UART1_Rx_Pin
#define UARTX_Tx_Pin UART1_Tx_Pin
#endif /* Use_UART1 */
#ifdef Use_UART2
#define UARTX UART2
#define UARTX_Rx_Pin UART2_Rx_Pin
#define UARTX_Tx_Pin UART2_Tx_Pin
#endif /* Use_UART2 */
#ifdef Use_UART3
#define UARTX UART3
#define UARTX_Rx_Pin UART3_Rx_Pin
#define UARTX_Tx_Pin UART3_Tx_Pin
#endif /* Use_UART3 */
void __main(void)
{
#ifdef DEBUG
debug();
#endif
RCCU_Div2Config(ENABLE); // Enable DIV2
RCCU_MCLKConfig(RCCU_DEFAULT); // Configure MCLK = RCLK
RCCU_FCLKConfig(RCCU_DEFAULT); // Configure FCLK = RCLK
RCCU_PCLKConfig(RCCU_DEFAULT); // Configure PCLK = RCLK
RCCU_PLL1Config(RCCU_PLL1_Mul_12, RCCU_Div_2) ; // Configure the PLL1 ( * 12 , / 2 )
while(RCCU_FlagStatus(RCCU_PLL1_LOCK) == RESET);// Wait PLL to lock
RCCU_RCLKSourceConfig(RCCU_PLL1_Output) ; // Select PLL1_Output as RCLK clock
// at this step the CKOUT signal should be equal to 48 Mhz
// Configure the GPIO pins
GPIO_Config(GPIO0, UARTX_Tx_Pin, GPIO_AF_PP);
GPIO_Config(GPIO0, UARTX_Rx_Pin, GPIO_IN_TRI_CMOS);
// Configure the UART X
UART_OnOffConfig(UARTX, ENABLE); // Turn UARTX on
UART_FifoConfig(UARTX, DISABLE); // Disable FIFOs
UART_FifoReset(UARTX, UART_RxFIFO); // Reset the UART_RxFIFO
UART_FifoReset(UARTX, UART_TxFIFO); // Reset the UART_TxFIFO
UART_LoopBackConfig(UARTX, DISABLE); // Disable Loop Back
/* Configure the UARTX as following:
- Baudrate = 57600 Bps
- No parity
- 8 data bits
- 1 stop bit */
UART_Config(UARTX, 57600, UART_NO_PARITY, UART_1_StopBits, UARTM_8D);
UART_RxConfig(UARTX, ENABLE); // Enable Rx
UART_StringSend(UARTX, (u8 *)"Hello, UART!\r\n");//sends a string to UARTX
while(1)
{
u8 ch;
while(!(UART_FlagStatus(UARTX) & UART_RxBufFull)); // If data received
UART_ByteReceive(UARTX, &ch, 0xFF); // Get the received data, set the guard time to 0xFF
//UART_ByteSend(UARTX, &ch);
if(ch == '\r')
{
ch = '\n';
};
UART_ByteSend(UARTX, &ch);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -