Keil Logo

GENERAL: PRINTF OUTPUT TO MULTIPLE DEVICES


Information in this article applies to:

  • C166 All Versions
  • C251 All Versions
  • C51 All Versions

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 \KEIL\TOOLSET\LIB 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\n");

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

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

SEE ALSO

FORUM THREADS

The following Discussion Forum threads may provide information related to this topic.

Last Reviewed: Sunday, May 23, 2004


Did this article provide the answer you needed?
 
Yes
No
Not Sure
 
  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.