Atmel CAVR-4 Manual De Usuario

Descargar
Página de 323
CAVR-4
Part1. Using the compiler
The CLIB runtime environment
87
Input and output
You can customize:
The functions related to character-based I/O
The formatters used by 
printf
/
sprintf
 and 
scanf
/
sscanf
.
CHARACTER-BASED I/O
The functions 
putchar
 and 
getchar
 are the fundamental functions through which C 
performs all character-based I/O. For any character-based I/O to be available, you must 
provide definitions for these two functions, using whatever facilities the hardware 
environment provides.
The creation of new I/O routines is based on the following files:
putchar.c
, which serves as the low-level part of functions such as 
printf
 
getchar.c
, which serves as the low-level part of functions such as 
scanf
The code example below shows how memory-mapped I/O could be used to write to a 
memory-mapped I/O device:
_ _no_init volatile unsigned char DEV_IO @ address;
  int putchar(int outchar)
  {
    DEV_IO = outchar;
    return outchar;
  }
The exact address is a design decision. For example, it can depend on the selected 
processor variant.
For information about how to include your own modified version of 
putchar
 and 
getchar
FORMATTERS USED BY PRINTF AND SPRINTF
The 
printf
 and 
sprintf
 functions use a common formatter, called 
_formatted_write
. The full version of 
_formatted_write
 is very large, and 
provides facilities not required in many embedded applications. To reduce the memory 
consumption, two smaller, alternative versions are also provided in the standard C 
library.