Atmel CAVR-4 Manual De Usuario
![Atmel](https://files.manualsbrain.com/attachments/0369829915bda09f9c2e00fb805a7753579683b5/common/fit/150/50/8d2bf08978ec3e5bc63f4343ac5e91ce8d0e40045619fa520d910d64af8f/brand_logo.png)
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.
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:
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.
processor variant.
For information about how to include your own modified version of
putchar
and
getchar
in your project build process, see Overriding library modules, page 61.
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.
consumption, two smaller, alternative versions are also provided in the standard C
library.