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:

Information contained on this site regarding device applications and the like is provided only for your convenience and may be superseded by updates. It is your responsibility to ensure that your application meets with your specifications. MICROCHIP MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND WHETHER EXPRESS OR IMPLIED, WRITTEN OR ORAL, STATUTORY OR OTHERWISE, RELATED TO THE INFORMATION, INCLUDING BUT NOT LIMITED TO ITS CONDITION, QUALITY, PERFORMANCE, MERCHANTABILITY OR FITNESS FOR PURPOSE. Microchip disclaims all liability arising from this information and its use. Use of Microchip devices in life support and/or safety applications is entirely at the buyer's risk, and the buyer agrees to defend, indemnify and hold harmless Microchip from any and all damages, claims, suits, or expenses resulting from such use. No licenses are conveyed, implicitly or otherwise, under any Microchip intellectual property rights.

Click here to edit contents of this page.

Click here to toggle editing of individual sections of the page (if possible). Watch headings for an "edit" link when available.

Append content without editing the whole page source.

Check out how this page has evolved in the past.

If you want to discuss contents of this page - this is the easiest way to do it.

View and manage file attachments for this page.

A few useful tools to manage this Site.

See pages that link to and include this page.

Change the name (also URL address, possibly the category) of the page.