"printf" in the microcontroller, what is it for?

I see the “printf” instruction in the examples of c language codes for the microcontroller, in particular, in 8051. Since the microcontrollers do not have a fixed output display, what is the use of the “printf” instruction?

+8
c embedded microcontroller firmware 8051
source share
4 answers

Most likely, you can connect the debug console through the RS232 port or as a virtual output from the built-in emulator.

+16
source share

printf is defined for output to stdout not "output", stdout can be any stream device. Typically, in a system without a display, it is displayed on a serial interface (UART), so that a terminal or terminal emulator (for example, HyperTerminal or TeraTerm) can be used as a display device.

In some development environments, "semi-hosting" is implemented, where stdio, stdin and stderr, and even in some cases the file system is provided by the development host via the debugger interface (JTAG, ICE, SWD, etc.).

Typically, your compiler library will provide you with hooks or stubs so that you can implement drivers for alternative stream input / output devices, so for example, you could implement them so that printf displays on the LCD if your device has one. This is called a "retargeting."

+11
source share

You can connect the microcontroller to the PC serial port and control the data that you

Printf

using hyperterminal. You can also use it for diagnostic purposes.

+7
source share

Some development tools allow you to use printf when implementing putchar or putch . In such tools, since you have this feature of sending characters to a device, printf will display messages on that device.

You just need to properly initialize the device, implement putchar, putch or such (check your compilers / lib docs) and voilá! Your printf will behave as you expect.

PS: Some compilers / libraries do not implement all printf format specifiers. Again, check your documents.

+4
source share

Source: https://habr.com/ru/post/650912/


All Articles