Is printf supported on the PIC16 family? I have searched this forum exhaustively for a solution but I am still getting the old "error: Missing definition for symbol "_printf", required by "obj\Release\src\main.o" " problem.
I have defined putchar() in main.c and added a path to just about every library directory I can see in the SDCC folder but no joy. I have added my main.c and compiler script below. The program compiles and runs fine on the PIC if I don't include the printf() function. If anyone can spot an obvious error I would be grateful.
btw the compile script mess was produced by CodeBlocks which has since been deleted from my PC in disgrace.
main.c
[#]include <stdio.h> //(why the BIG #include?!?) [#]include <pic18fregs.h>
// Configurations [#]pragma config WRTB = ON //write-protect top bootloader (0x0000 - 0x07FF) [#]pragma config OSC = INTIO7 //CLKO function on RA6, I/O on RA7, otherwise use INTIO67 for I/O on RA6 and RA7 [#]pragma config BOREN = ON [#]pragma config XINST = OFF
void putchar(char c)
{
if (c == '\n')
{
while (!PIR1bits.TXIF);
PIR1bits.TXIF = 0;
TXREG = 0x0d;
}
while (!PIR1bits.TXIF);
PIR1bits.TXIF = 0;
TXREG = c;
}
void delay_ms(int ms)
{
int i;
while (ms--)
for (i=0; i < 10; i++)
;
}
void main() {
//set up internal oscillator = 4MHz
OSCCON |= 0b01100010;
OSCTUNEbits.PLLEN = 0;
// Initializing ports
PORTB = 0;
// Set RB3-RB0 as output
TRISB &= 0xF0;
// Set value 0x0A to PORTB
PORTB = 0x0A;
// Flash LED on PORTB.0
while(1)
{
PORTBbits.RB0 = 1;
delay_ms(1000);
PORTBbits.RB0 = 0;
delay_ms(1000);
printf("Hello test");
}
OK, forget it. I moved all my files into the project root folder, changed "void putchar(char c)" to "PUTCHAR (c)" and ran this much simpler compile script:
Is printf supported on the PIC16 family? I have searched this forum exhaustively for a solution but I am still getting the old "error: Missing definition for symbol "_printf", required by "obj\Release\src\main.o" " problem.
I have defined putchar() in main.c and added a path to just about every library directory I can see in the SDCC folder but no joy. I have added my main.c and compiler script below. The program compiles and runs fine on the PIC if I don't include the printf() function. If anyone can spot an obvious error I would be grateful.
btw the compile script mess was produced by CodeBlocks which has since been deleted from my PC in disgrace.
main.c
[#]include <stdio.h> //(why the BIG #include?!?)
[#]include <pic18fregs.h>
// Configurations
[#]pragma config WRTB = ON //write-protect top bootloader (0x0000 - 0x07FF)
[#]pragma config OSC = INTIO7 //CLKO function on RA6, I/O on RA7, otherwise use INTIO67 for I/O on RA6 and RA7
[#]pragma config BOREN = ON
[#]pragma config XINST = OFF
void putchar(char c)
{
if (c == '\n')
{
while (!PIR1bits.TXIF);
PIR1bits.TXIF = 0;
TXREG = 0x0d;
}
while (!PIR1bits.TXIF);
PIR1bits.TXIF = 0;
TXREG = c;
}
void delay_ms(int ms)
{
int i;
}
void main() {
}
compile script:
@echo off
::--------------------------------------------------------------------
sdcc.exe^
-mpic16^
--opt-code-size^
-p18f2520^
--use-non-free^
-I"C:\Program Files\SDCC\include"^
-I"C:\Program Files\SDCC\non-free\include"^
-I"C:\Program Files\SDCC\lib"^
-I"C:\Program Files\SDCC\non-free\lib"^
-c src\main.c^
-o obj\Release\src\main.o^
IF %ERRORLEVEL% NEQ 0 (
echo Compiler error: %ERRORLEVEL%
exit /B
) else (
echo Compiler OK
)
::--------------------------------------------------------------------
sdcpp.exe^
-nostdinc^
-Wall^
-std=c11^
-I"C:\Program Files\SDCC\include"^
-I"C:\Program Files\SDCC\non-free\include"^
-I"C:\Program Files\SDCC\lib"^
-I"C:\Program Files\SDCC\lib\pic16"^
-I"C:\Program Files\SDCC\non-free\lib"^
-D18f2520^
-DSDCC_PIC18F2520^
-DSTACK_MODEL_SMALL^
-obj-ext=.o^
-DSDCC_CHAR_UNSIGNED^
-DSDCC_USE_NON_FREE^
-DSDCC_ALL_CALLEE_SAVES^
-DSDCC=3_6_0^
-DSDCC_VERSION_MAJOR=3^
-DSDCC_VERSION_MINOR=6^
-DSDCC_VERSION_PATCH=0^
-DSDCC=360^
-DSDCC_REVISION=9615^
-DSDCC_pic16^
-DSTDC_NO_COMPLEX=1^
-DSTDC_NO_THREADS=1^
-DSTDC_NO_ATOMICS=1^
-DSTDC_NO_VLA=1^
-DSTDC_ISO_10646=201409L^
-DSTDC_UTF_16=1^
-DSTDC_UTF_32=1^
-isystem "C:\Program Files\SDCC\bin..\include\pic16"^
-isystem "C:\Program Files\SDCC\bin..\include"^
-isystem "C:\Program Files\SDCC\bin..\non-free\include\pic16"^
-isystem "C:\Program Files\SDCC\bin..\non-free\include"^
"src\main.c"^
IF %ERRORLEVEL% NEQ 0 (
echo Preprocessor error: %ERRORLEVEL%
exit /B
) else (
echo Preprocessor OK
)
::--------------------------------------------------------------------
gpasm.exe^
-D__STACK_MODEL_SMALL^
-o "obj\Release\src\main.o"^
-c "obj\Release\src\main".asm^
IF %ERRORLEVEL% NEQ 0 (
echo gpasm error: %ERRORLEVEL%
exit /B
) else (
echo Assembler OK
)
::--------------------------------------------------------------------
sdcc.exe^
-L"C:\Program Files\sdcc\lib","C:\Program Files\sdcc\lib\pic16\libc\stdio","C:\Program Files\SDCC\non-free\lib\pic16"^
-o bin\Release\API_expt.exe^
-mpic16^
--opt-code-size^
-p18f2520^
--use-non-free^
-Wl,--no-cinit-warnings,--map,-S2^
obj\Release\src\main.o
::>nul
IF %ERRORLEVEL% NEQ 0 (
echo Linker error: %ERRORLEVEL%
exit /B
) else (
echo Linker OK
)
::--------------------------------------------------------------------
echo Compile successful
Last edit: Steve Rouse 2016-09-30
OK, forget it. I moved all my files into the project root folder, changed "void putchar(char c)" to "PUTCHAR (c)" and ran this much simpler compile script:
sdcc^
--use-non-free^
-mpic16^
-p18f2520^
-Wl,--no-cinit-warnings,-S2 main.c
It now all compiles fine although I haven't tested it on the device yet.
Stupid CodeBlocks.
Thanks anyway.
See https://sourceforge.net/p/forge/documentation/markdown_syntax/