As usual on embedded systems you have to provide your own getchar() and putchar() routines. SDCC does not know whether the system connects to a serial line with or without handshake, LCD, keyboard or other device. And whether a lf to crlf conversion within putchar() is intended. You'll find examples for serial routines f.e. in sdcc/device/lib. For the mcs51 this minimalistic polling putchar() routine might be a start:
int putchar (int c) {
while (!TI) /* assumes UART is initialized */
;
TI = 0;
SBUF = c;
return c;
}
The default printf() implementation in printf_large.c
does not support float (except on ds390),
only <NO FLOAT>
will be printed instead of the value. To enable floating point output,
recompile it with the option -DUSE_FLOATS=1
on the command line. Use --model-large
for the mcs51 port, since this uses a lot of memory. To enable float
support for the pic16 targets, see .
If you're short on code memory you might want to use printf_small()
instead of printf(). For the mcs51 there additionally
are assembly versions printf_tiny()
(subset of printf using less than 270 bytes) and printf_fast()
and printf_fast_f()
(floating-point aware version of printf_fast) which should fit the
requirements of many embedded systems (printf_fast() can be customized
by unsetting #defines to not support long variables and field
widths). Be sure to use only one of these printf options within a
project.
Feature matrix of different printf options on mcs51.
As of SDCC 2.6.2 you no longer need to call an initialization routine before using dynamic memory allocation and a default heap space of 1024 bytes is provided for malloc to allocate memory from. If you need a different heap size you need to recompile _heap.c with the required size defined in HEAP_SIZE. It is recommended to make a copy of this file into your project directory and compile it there with:
sdcc -c _heap.c -D HEAP_SIZE=2048And then link it with:
sdcc main.rel _heap.rel