The printf() function
performs two main tasks: formatting of text, and printing this formatted text
to stdout. The exact location of stdout is determined by a second function
called putch(), which is called by printf() to output
each character.
The printf() function performs the formatting and then
calls a helper function, called putch, to send each byte of the
formatted text. By default the putch() function is empty. It should be customised to
suit the project at hand. By customizing the putch function you can have printf send data
to any peripheral or location. The printf() function is used to print to USART, but it
could define stdout to output to an LCD screen or SPI. Code to
initialize the intended destination must be executed before printf() is
called. [1]
Mengikut
wikidot.com, kita boleh guna function printf() bagi menghantar mesej melalui
UART.
Berikut
adalah caranya:
1. Masukkan
header file berikut ke dalam program:
2.
Initialize UART dengan setting berikut:
Baud Rate = 9600bps
Data bit = 8
Dll
Contoh:
3. Tambah
function dibawah ini tanpa perlu prototype function.
4. Seterusnya
function printf() sudah tersedia untuk digunakan bersama dengan UART. Contoh aturcara
klik disini
References
[1]
|
Microchip, "Wikidot.com," 17 April 2014.
[Online]. Available: http://microchip.wikidot.com/faq:29. [Accessed 16
September 2015].
|
[2]
|
Microchip, "Microchip Technology Inc," 5 Aug
2012. [Online]. Available:
ww1.microchip.com/downloads/en/DeviceDoc/52053B.pdf. [Accessed 19 Sep
2015].
|