When the printf function formats the output, it calls the char putchar(char c); function. This function can be found in "stdio.h", so we need to construct such a function ourselves, that is, through the serial port putchar(), the code is as follows:
char putchar(char c) // redirect
{
Uart_SendChar(c);
return c;
}
void Uart_SendChar(unsigned char dat)
{
SBUF = dat;
while(!IF);
IF = 0;
}
Then after the serial port is initialized, include the "stdio.h" header file and you can use the printf function.
NOTE:
Using the printf function in the stdio library will increase the amount of code by about 1k, so use it with caution in a small-capacity 51 microcontroller! !
Previous article:How to use printf on MCU to make serial port output
Next article:The 51 MCU serial port prints garbled characters in both Chinese and English
Recommended ReadingLatest update time:2024-11-16 21:32
- Popular Resources
- Popular amplifiers
- MCU C language programming and Proteus simulation technology (Xu Aijun)
- Internet of Things Development Technology Based on C Language (Edited by Gao Song)
- Operating System Principles, Implementation and Practice (Li Zhijun, Liu Hongwei)
- C Language Programming Tutorial (2nd Edition) (Li Hanguang, Zheng Guansheng)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- EtherCAT: MCU Selection
- Farrow structure filter MATLAB implementation source code and simulation
- [Xianji HPM6750EVKMINI Review] 4# HPM6750 Dual-core Experience
- Goodbye 2019, hello 2020+ There is a European town in Songshan Lake
- PASS F5 Power Amplifier
- CPU card design example and program design--external authentication, card and ESAM common
- Protecting Your IP Cores - Part 1 Soft IP Cores, Chapter 3: Obfuscation of Hardware Design
- R7-4800h R7000, compiling 5.6.18 kernel linux, is make -j8 faster or -j16 faster?
- Ask someone with level 8 Chinese proficiency to explain it to me
- Oscilloscope testing applications in medical equipment