Home > other >  Huada HC32L13X MCU chip, how to use printf output
Huada HC32L13X MCU chip, how to use printf output

Time:10-18

Huada microcontroller HC32L13X default PA09 series MCU to UART0 TXD pin function, we can in DDL. C to a serial port initialization Settings, the code is as follows:
Void Debug_UartInit (void)//serial port initialization
{
# ifdef __DEBUG

M0P_GPIO - & gt; PA09_SEL_f. SEL=1;
M0P_GPIO - & gt; PADIR_f. PA09=0;

M0P_UART0 - & gt; SCNT=52;//9600 baud rate
M0P_UART0 - & gt; SCON_f. OVER=1;
M0P_UART0 - & gt; SCON_f. SM=1;


# endif
}



Void Debug_Output (uint8_t u8Data)//send a byte
{
M0P_UART0 - & gt; SCON_f. REN=0;
M0P_UART0 - & gt; SBUF=u8Data;
While (TRUE!=M0P_UART0 - & gt; ISR_f. TC)
{
;
}
M0P_UART0 - & gt; ICR_f. TCCF=0;

}



Int fputc (int ch, FILE * f)
{

If (((uint8_t) ch)=='\ n')
{
Debug_Output (' \ r ');
}
Debug_Output (ch);

return ch;
}

In the main program code is as follows:
# define the DEBUG
# include "DDL. H"
# include "uart. H"
# include "gpio. H"
# include "sysctrl. H"

Int main ()
{

Sysctrl_SetPeripheralGate (SysctrlPeripheralGpio, TRUE);
Sysctrl_SetPeripheralGate (SysctrlPeripheralUart0, TRUE);
# ifdef DEBUG
Debug_UartInit ();//debug serial port initialization
# endif

# ifdef DEBUG
Printf (" This is a UART Test!" );//output debugging content
# endif
While (1)
{
;
}
}






After the program compiled by electricity run results are as follows:

The above code has been packaged in the attachment, you can download the test,
  • Related