How to change the destination of printf to a UART?

Question:

I am using the CC-RL compiler for RL78 devices. How do I change the destination of printf to a UART?

Answer:

The printf function of CC-RL produces output by calling the putchar function. Create a new putchar function to change the destination of output by printf. In the default putchar function, the letters defined as arguments are output to the SFR with the symbol P0 (port 0) after being converted to the unsigned char type. Create a putchar function in which this processing is changed to transmission through a UART.