Page 1 of 1

editing putch.c has no effect

PostPosted: Thu Mar 19, 2020 10:49 pm
by gottliebgreg
I am using a PIC16F15323 and am trying to use the printf statement. MPLABX 5.35 and XC8 2.10. I followed the instructions in the compiler guide and wrote my own putch.c to use the USART, which does work. The problem arises when I use printf which calls putch. The weak implementation is always called, even when I have edited it. I'm editing putch.c in the C99/common library. It's not a hardware problem or even code problem, as my code never executes, the compiler never attempts to compile the modified putch.c. But the project will successfully build and step through the code, it just steps through the code that 'used to be there'. Anybody have any thoughts?

Re: editing putch.c has no effect

PostPosted: Fri Mar 20, 2020 12:55 am
by ric
Don't edit putch.c in the library.
Just put your custom putch() implementation into one of your own C files, or put your custom putch.c file in the same folder as your other C files and add it to your project.

Re: editing putch.c has no effect

PostPosted: Fri Mar 20, 2020 1:21 am
by ric
n.b. the text in the User Guide is:
A stub for the putch function can be found in the compiler’s sources directory. Copy
it into your project
then modify it to send the single byte parameter passed to it to the
required destination. Before you can use printf, peripherals that you use will need to
be initialized in the usual way. Here is an example of putch for a USART on a mid-range
device.

I think you skipped the bit I put in bold.

Re: editing putch.c has no effect

PostPosted: Fri Mar 20, 2020 7:26 pm
by jtemples
For future reference, there are no circumstances where you should be modifying any of the compiler's files.