Reading a value from input pin using STC15w

I have set up Port 1.5 as an input pin and have attached a 10K resister pullup to vcc and a 10k Pot to gnd. and can read the value in PlatformIO which lights an led at a certain level. BUT I am trying to display the value on the serial port so I know what value it is and I just can’t find a way to do this. (using Arduino I use serial.begin…serial.print and open the serial monitor). I have tried printf(“%d”,lightval); but get an error :

`Compiling .pio\build\stc15w408as\src\main.rel
Linking .pio\build\stc15w408as\firmware.hex

?ASlink-Warning-Undefined Global ‘_putchar’ referenced by module ‘vprintf’
*** [.pio\build\stc15w408as\firmware.hex] Error 1`

I am sure it must be easy, but I just don’t know, any help would be useful.

Most C library impelmentations do not “just know” about a microcontroller’s UART pins and require the user to implement the underlying basic input or output functions. So for printf to work, there needs to be a symbol called _putchar, often generated by a C function called putchar. The function receives the character to print, and it’s the function’s job to transfer that into the right UART data register and wait for the transmission of the character to be over (otherwise you might be overwriting the UART data register while the character is still being transmitted, corrupting the transmission).

You can see an example for STM8S chip at

You need to figure out what the right UART data register (and surrounding UART register setup for baud rate, clock, baud rate, etc) is for your chip.

You might find some answers for that in and of course the chip’s datasheet and the .h file for it in SDCC.

Many thanks for your direction…