How to use standard input and output in CodeWarrior v5.x/MC9S12(X)
It is not possible to use standard input and output directly under CodeWarrior. The reason is probably very simple. The microcontroller does not have a console, and different microcontrollers have different ports. How does the compiler know where to printf, getchar, putchar...
To solve this problem, the standard input and output in the standard library implementation provided by CodeWarrior actually call the two functions TERMIO_GetChar and TERMIO_PutChar respectively. These two functions require users to implement them. The function prototypes are as follows:
// Receive a character from the terminal channel
// Return: characters received from the terminal channel
char TERMIO_GetChar(void);
// Send a character to the terminal channel
// Parameter: ch character to be sent to the terminal channel
void TERMIO_PutChar(char ch);
So in order to use the functions that we had fun using when learning C language, we have to implement these two functions ourselves as needed.
The example uses the SCI module I wrote myself and uses SCI0 as the terminal channel:
#include #include "derivative.h" /* derivative-specific definitions */ #include #include "SCI_def.h" void TERMIO_PutChar(char ch){ SCI_PutChar(SCI0,(unsigned char)ch); } char TERMIO_GetChar(void){ return SCI_GetChar(SCI0); } void main(void) { int c; // Enable SCI0 SCI_Init(SCI0); SCI_EnableTrans(SCI0); SCI_EnableRecv(SCI0); printf("type something:r"); for(;;) { // Receive characters and echo them c = getchar(); putchar(c); } } The reason why SCI0 is used is because the terminal window in the simulation uses SCI0, which is more convenient for demonstration hhh ps: Actually, I didn't use standard input and output when programming embedded systems, but some libraries use standard output by default, so I did some research.
Previous article:MC9S12XE bootloader development
Next article:MC9S12XE Memory Allocation
Recommended ReadingLatest update time:2024-11-16 18:03
- Popular Resources
- Popular amplifiers
- Siemens S7-1200-PLC Programming and Application Tutorial (3rd Edition) (Edited by Shi Shouyong)
- 西门子S7-12001500 PLC SCL语言编程从入门到精通 (北岛李工)
- Siemens Motion Control Technology and Engineering Applications (Tongxue, edited by Wu Xiaojun)
- Virtualization Technology Practice Guide - High-efficiency and low-cost solutions for small and medium-sized enterprises (Wang Chunhai)
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
- Please teach me a resistance measurement circuit
- Why does the STACK MODE of almost all pads in ALTIUM DESIGNER change to FULL STACK?
- 【STM32WB55 Review】——by Beifang
- 8 principles to follow in PCB stackup design
- [Gizwits Gokit3 Review] + AirLink configuration (Arduino)
- Node voltage calculation
- Showing goods + artificial intelligence first board dog bone AI
- [TI mmWave Radar Evaluation]_5_AWR1843BOOST Corridor Ranging Corner Reflector Test
- pyESP32 board design draft and BOM list
- ARM working mode