Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"printf" in microcontroller, what is it for?

I see "printf" instruction in sample codes of c language for microcontroller particularly in 8051. Since microcontrollers has no fixed output display what is the use of the "printf" instruction?

like image 484
LEMUEL ADANE Avatar asked Jan 11 '11 04:01

LEMUEL ADANE


2 Answers

More likely than not, so you can attach a debugging console, either through an RS232 port, or as virtual output from an in-circuit emulator.

like image 169
Raph Levien Avatar answered Oct 02 '22 23:10

Raph Levien


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

Some development environments implement "semi-hosting" where stdio, stdin, and stderr, and even in some cases a filesystem are provided by the development host through the debugger interface (JTAG, ICE, SWD etc).

Generally your compiler's library will provide you with hooks or stubs so that you can implement drivers for alternative stream I/O devices, so for example you could implement one so that printf will output to an LCD display if your device has one. This is called "retargetting".

like image 29
Clifford Avatar answered Oct 02 '22 23:10

Clifford