6.18.1.1 Customizing Helper Functions for 8-bit PIC Devices
When using the MPLAB XC8 Compiler for PIC MCUs, the putch()
and
getch()
functions need to be completed to define the
stdout
and stdin
streams used by
printf()
and scanf()
functions, respectively.
Printing using printf()
will not work as expected until the
putch()
stub (found in the
pic/sources/c99/common/putch.c of your compiler distribution)
is completed. The putch
function is called repetitively by
printf()
to send each byte of the formatted output. The
putch()
function should send the byte passed in as an argument to
the required destination, for example a UART. See Example code for 8-bit PIC MCUs for information on
defining putch()
so that printed text appears in an MPLAB X IDE
simulator window.
Reading input using scanf()
will not work as expected until the
getch()
stub (found in the
pic/sources/c99/common/getch.c of your compiler distribution)
is completed. The getch()
function is called repetitively to obtain
each bye of the input. The getch()
function should return one byte read
from required source, for example a UART. See Example code for 8-bit PIC MCUs for information on
defining getch()
so that it can read text from a file when you are
using the MPLAB X IDE simulator.
Once completed, the source files for getch()
and
putch()
should be built with your other source files in the usual
way.