- /*---------------------------------------------------------------------------------------------------------*/
- /* */
- /* Copyright(c) 2019 Nuvoton Technology Corp. All rights reserved. */
- /* */
- /*---------------------------------------------------------------------------------------------------------*/
- //***********************************************************************************************************
- // Website: http://www.nuvoton.com
- // E-Mail : MicroC-8bit@nuvoton.com
- //***********************************************************************************************************
- #include "ML51.h"
- /**
- * [url=home.php?mod=space&uid=247401]@brief[/url] UART1 use as printf.
- * @param None
- * [url=home.php?mod=space&uid=266161]@return[/url] None
- * [url=home.php?mod=space&uid=1543424]@Details[/url] None
- */
- void main (void)
- {
- /**
- For UART1 P2.3 as TXD1 / P2.3 as RXD1 GPIO setting
- * include gpio.c in Common Setting for UART0
- */
- MFP_P23_UART1_TXD; // UART0 TXD use P0.5
- P23_QUASI_MODE; // set P0.5 and P0.6 as Quasi mode for UART0 trasnfer
- /**
- For UART1 initial setting
- * include uart.c in Common Setting for UART0
- */
- UART_Open(24000000,UART1,115200); // Open UART0 use timer1 as baudrate generate and baud rate = 115200en(24000000,UART0_Timer1,115200); // Open UART0 use timer1 as baudrate generate and baud rate = 115200
- set_S1CON_TI_1; // printf must first set TI_1 =1;
-
- /**
- UART1 loop test
- UART1 TXD1 send data received by RXD1 pin. Connect TXD1 pin and RXD1 pin check result.
- */
- while(1)
- {
- printf ("\n hello world! " );
- Timer2_Delay(24000000,128,1000,1000); //Means timer base 24MHz, divider 128, delay time 100 ms (100000us)
- }
- }
上面是官方的例子,在启用串口1作为printf的时候,使用了set_S1CON_TI_1; // printf must first set TI_1 =1;
非常难易理解,而在串口0的例子中没这么用,串口0的例子使用的是
ENABLE_UART0_PRINTF
于是查找头文件发现了问题。头文件中是有一条
ENABLE_UART1_PRINTF
的,然后使用宏替换的set_S1CON_TI_1
所以这里写例程序的程序员故意挖坑了。
|