How to use printf in CodeWarrior v5.x/MC9S12(X)

Publisher:灵感发电站Latest update time:2021-07-15 Source: eefocusKeywords:CodeWarrior  printf Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

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       /* common defines and macros */

#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.

Keywords:CodeWarrior  printf Reference address:How to use printf in CodeWarrior v5.x/MC9S12(X)

Previous article:MC9S12XE bootloader development
Next article:MC9S12XE Memory Allocation

Recommended ReadingLatest update time:2024-11-16 18:03

OPPO Find X3 has been connected to the network, and its ID photo has been exposed
According to Jiwei.com on February 19, OPPO Find X3 has been connected to the network. The exposed ID photos show that the front of the phone uses a dual-curved hole-punch screen with a small curvature, which is a micro-curved design. The back is made of plain leather and the camera module has a rectangular layout.   
[Mobile phone portable]
Shen Yiren: OPPO Find X2 has optimized touch screen performance
      This morning, OPPO Vice President Shen Yiren said on Weibo that OPPO Find X2 has now optimized the touch screen performance and updated the WLAN firmware to improve the smoothness of use and network stability.   IT Home learned that the OPPO Find X2 series is equipped with a Snapdragon 865 processor, adopts a
[Mobile phone portable]
Nidec Shinpo and GBS jointly release a new powered suit "Cray X"
  German Bionic Systems (GBS) will exhibit its new powered suit "Cray X" equipped with ultra-flat actuators produced by Nidec Shinpo Corporation (Nidec Shinpo) at the INTERNATIONAL ROBOT EXHIBITION 2019 (iREX2019), an international exhibition for industrial service robots and related equipment to be held at Tokyo Big
[Embedded]
Nidec Shinpo and GBS jointly release a new powered suit
ATMEL AT91SAM9X25 platform development process
prepare materials: 1. Cross-compilation toolchain  2.u-boot 3. Linux kernel  4. File System Note: Unzip the above codes and put these four folders in the same directory 1. Compilation of u-boot (1) Enter the u-boot directory and modify the Makefile file CROSS_COMPILE = $(shell pwd)/../arm-2007q1/bin/arm-no
[Microcontroller]
MDK hardware debugging_Display print information in the Debug printf Viewer window_ITM
When debugging code, everyone likes to use the printf function to output some print information to prompt the execution status of their own code. When I first came into contact with this debugging method, the way I used was to waste a serial port of a chip, and then use the TTL to USB module to print prompt informatio
[Microcontroller]
MDK hardware debugging_Display print information in the Debug printf Viewer window_ITM
[ANT+][nrf51422][s210] Bicycle Light General Page 70 (0x46): Request Data Page
Generic Data Page 70 allows an ANT+ device to request a specific data page from another ANT+ device. In this device profile: • Page 70 allows the controller to request a specific data page from an ANT+ bike light. The requested data page shall be sent using a recognized MES DROP by the ANT+ controller and shall be for
[Microcontroller]
[ANT+][nrf51422][s210] Bicycle Light General Page 70 (0x46): Request Data Page
C-V2X Internet of Vehicles White Paper and Think Tank Results Released
From December 10th to 11th, 2022, the 3rd China International Internet of Vehicles Technology Conference with the theme of "Intelligent Connectivity, Trust and Creation of the Future" was successfully held in Chengdu. This conference is hosted by the China Communications Society and the Sichuan Provincial Department o
[Automotive Electronics]
C-V2X Internet of Vehicles White Paper and Think Tank Results Released
Principle and software design of real-time clock device X1226
X1226 has the functions of clock and calendar. The clock relies on hour, minute and second registers to track, and the calendar relies on date, week, month and year registers to track. The calendar can correctly pass 2099 and has automatic leap year correction. It has a powerful dual alarm function that can be
[Analog Electronics]
Principle and software design of real-time clock device X1226
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号