Example code for 8-bit AVR MCUs

The UART IO feature in the MPLAB X IDE allows you to view output from the stdout stream. Once properly configured, the output of printf() and other functions can then be viewed from the IDE when the program is run in the simulator.

This feature is enabled from Project properties > Simulator > USARTx IO Options. You might have a choice of USARTs. Choose the USART that your code will write to. Output can be displayed in a window in the IDE or sent to a file on your host machine, based on the selections you make in the dialog.

Figure 1. Enabling the USART IO feature in the MPLAB X IDE

The USART initialization and print-byte function generated by the MCC will allow printf() to work in the simulator. If you enable the Printf support checkbox in the USART dialog, MCC will generate the necessary mapping via the FDEV_SETUP_STREAM() macro to ensure that printf() calls the correct print-byte function. The default communication settings should work in the simulator, but these may need to be changed if the USART is to be used on hardware.

Figure 2. Initializing the USART using MCC