Author Topic: [SOLVED]MPLAB X IDE Console/File output  (Read 332 times)

0 Members and 1 Guest are viewing this topic.

Offline NightMothTopic starter

  • Contributor
  • Posts: 21
  • Country: cn
[SOLVED]MPLAB X IDE Console/File output
« on: April 07, 2025, 08:05:28 am »
Hello all

I'm using:
- MPLAB X IDE v5.50
- xc8 v3.00 compiller (c99, Uart1 IO enabled in project properties)

For debugging and for testing logic of my code, I want some output to be displayed on some console of MPLAB IDE or to be written into file.
(I don't plan use microcontroller to output this data, just want to see what my code do. I will remove from code all output related routines before making hex file)

I found this microchip article that described how do do it with fprint() function:
https://developerhelp.microchip.com/xwiki/bin/view/software-tools/xc8/simulator-console

I copypasted code from anove article, but can't compille it.
Here is the code and error message:

Code
Code: [Select]
#include <xc.h>
#include <stdio.h>

void putch(unsigned char data)
{
    while( ! PIR1bits.TXIF)          // wait until the transmitter is ready
        continue;
    TXREG = data;                     // send one character
}

void init_uart(void) {
    TXSTAbits.TXEN = 1;               // enable transmitter
    RCSTAbits.SPEN = 1;               // enable serial port
}

void main(void) {
    init_uart();
    printf("Hello world\ntest value is %04d\n", 23);
    while(1)
        continue;
}


Error messages:
CLEAN SUCCESSFUL (total time: 34ms)
make -f nbproject/Makefile-default.mk SUBPROJECTS= .build-conf
make[1]: Entering directory 'F:/MY_ELECTRONIC_PROJECTS/PIC_Projects/TestProject_01.X'
make  -f nbproject/Makefile-default.mk dist/default/production/TestProject_01.X.production.hex
make[2]: Entering directory 'F:/MY_ELECTRONIC_PROJECTS/PIC_Projects/TestProject_01.X'
"C:\Program Files\Microchip\xc8\v3.00\bin\xc8-cc.exe"  -mcpu=16F877A -c   -mdfp="C:/Program Files/Microchip/MPLABX/v5.50/packs/Microchip/PIC16Fxxx_DFP/1.2.33/xc8"  -fno-short-double -fno-short-float -O0 -fasmfile -maddrqual=ignore -xassembler-with-cpp -mwarn=-3 -Wa,-a -DXPRJ_default=default  -msummary=-psect,-class,+mem,-hex,-file  -ginhx32 -Wl,--data-init -mno-keep-startup -mno-osccal -mno-resetbits -mno-save-resetbits -mno-download -mno-stackcall   -std=c99 -gdwarf-3 -mstack=compiled:auto:auto     -o build/default/production/TestProject_01.p1 TestProject_01.c
TestProject_01.c:12:6: error: conflicting types for 'putch'
   12 | void putch(unsigned char data)
      |      ^
C:\Program Files\Microchip\xc8\v3.00\pic\include\c99/stdio.h:106:6: note: previous declaration is here
  106 | void putch(char);
      |      ^
1 error generated.
nbproject/Makefile-default.mk:107: recipe for target 'build/default/production/TestProject_01.p1' failed
make[2]: Leaving directory 'F:/MY_ELECTRONIC_PROJECTS/PIC_Projects/TestProject_01.X'
nbproject/Makefile-default.mk:91: recipe for target '.build-conf' failed
make[1]: Leaving directory 'F:/MY_ELECTRONIC_PROJECTS/PIC_Projects/TestProject_01.X'
nbproject/Makefile-impl.mk:39: recipe for target '.build-impl' failed
make[2]: *** [build/default/production/TestProject_01.p1] Error 1
make[1]: *** [.build-conf] Error 2
make: *** [.build-impl] Error 2

BUILD FAILED (exit value 2, total time: 968ms)


Am I putting putch() function into wrong place?

I will very appreciate if somebody advice how I can make program output displayed with MPLAB IDE (or written into file).

I don't want to use last version of MPLAB IDE, because it doesn't support PicKit3.5+ I own.
« Last Edit: April 08, 2025, 10:53:12 am by NightMoth »
 

Offline westfw

  • Super Contributor
  • ***
  • Posts: 4413
  • Country: us
Re: MPLAB X IDE Console/File output
« Reply #1 on: April 07, 2025, 07:37:41 pm »
What happens if you get rid of the "unsigned" in your function declaration?
 
The following users thanked this post: NightMoth

Offline NightMothTopic starter

  • Contributor
  • Posts: 21
  • Country: cn
Re: MPLAB X IDE Console/File output
« Reply #2 on: April 08, 2025, 12:00:02 am »
What happens if you get rid of the "unsigned" in your function declaration?

Thank you! It works now.
I should have checked xc8 manual first. In the manual they indeed use "char" as input to putch(), not "unsigned char".
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf