editing putch.c has no effect

This forum handles questions and discussions concerning Microchip’s 8-bit compilers, assemblers, linkers and related tools.

editing putch.c has no effect

Postby gottliebgreg » Thu Mar 19, 2020 10:49 pm

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?
gottliebgreg
 
Posts: 1
Joined: Thu Mar 19, 2020 7:19 pm
PIC experience: Professional 2-5 years with MCHP products

Re: editing putch.c has no effect

Postby ric » Fri Mar 20, 2020 12:55 am

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.
Latest test project, an LED matrix display made from one reel of addressable LEDs. here
User avatar
ric
Verified identity
 
Posts: 528
Joined: Sat May 24, 2014 2:35 pm
Location: Melbourne, Australia
PIC experience: Professional 5+ years with MCHP products

Re: editing putch.c has no effect

Postby ric » Fri Mar 20, 2020 1:21 am

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.
Latest test project, an LED matrix display made from one reel of addressable LEDs. here
User avatar
ric
Verified identity
 
Posts: 528
Joined: Sat May 24, 2014 2:35 pm
Location: Melbourne, Australia
PIC experience: Professional 5+ years with MCHP products

Re: editing putch.c has no effect

Postby jtemples » Fri Mar 20, 2020 7:26 pm

For future reference, there are no circumstances where you should be modifying any of the compiler's files.
jtemples
Verified identity
 
Posts: 183
Joined: Sun May 25, 2014 2:23 am
Location: The 805
PIC experience: Professional 5+ years with MCHP products


Return to MPLAB XC8

Who is online

Users browsing this forum: No registered users and 1 guest

cron