ARM Technical Support Knowledge Articles

PRINTF OUTPUT TO MULTIPLE DEVICES

Applies to: General Topics

Answer


Information in this article applies to:


QUESTION

How can I modify printf to output its results to either the serial port or to an LCD panel?

ANSWER

Yes. The printf function uses putchar to output characters. You should start by referencing the source for the putchar function which is found in the PUTCHAR.C file in the KEILTOOLSETLIB folder.

You may modify the putchar routine to output characters to any number of different targets. For example:

#define PUTCHAR_SERIAL 0
#define PUTCHAR_LCD    1

unsigned char putchar_target = PUTCHAR_SERIAL;

char putchar (char k)
{
switch (putchar_target)
  {
  default:
  case PUTCHAR_SERIAL:
    /*** Code here for output to serial port ***/
    break;

  case PUTCHAR_LCD:
    /*** Code here for output to LCD ***/
    break;
  }
}

In this template, you must insert the code necessary to output to the serial port as well as the code necessary to output to the LCD. You may, of course, add more output targets as required by your hardware.

In your code, call printf as follows:

putchar_target = PUTCHAR_SERIAL;
printf ("Hello World
");

putchar_target = PUTCHAR_LCD;
printf ("Hello World
");

Make sure that you set the target before each call to printf.

SEE ALSO

Article last edited on: 2004-05-23 13:06:54

Rate this article

[Bad]
|
|
[Good]
Disagree? Move your mouse over the bar and click

Did you find this article helpful? Yes No

How can we improve this article?

Link to this article
Copyright © 2011 ARM Limited. All rights reserved. External (Open), Non-Confidential