The printf() function performs two main tasks: formatting of text, and printing this formatted text to stdout. The exact location of stdout is determined by a second function called putch(), which is called by printf() to output each character.
The printf() function performs the formatting and then calls a helper function, called putch, to send each byte of the formatted text. By default the putch() function is empty. It should be customised to suit the project at hand. By customizing the putch function you can have printf send data to any peripheral or location. The printf() function is used to print to USART, but it could define stdout to output to an LCD screen or SPI. Code to initialize the intended destination must be executed before printf() is called.
Sample Code for putch configured for USART transmission on a PIC16 device:
Sample Code for putch configured for USART transmission on a PIC18 device:
Microchip Technology acquires Atmel