The Usart Bla bla bla: Using the Standard IO facilities #16
Using the Standard IO facilities of the avr-libc
The avr-libc gives some facilities of the standard I/O. Only a limited subset of the standard IO is implemented (refer to the <stdio.h>: Standard IO facilities section of the avr-libc manual.). The uart.c source code could be used to interface the uart device with the Standard IO. The following example from the stdio man page of avr-libc illustrates the usage of the uart library.
#include <stdio.h>
#include “uart.h”
static int uart_putchar4IO(char ucData , FILE *stream);
static FILE mystdout = FDEV_SETUP_STREAM(uart_putchar4IO, NULL,
_FDEV_SETUP_WRITE);
static int uart_putchar4IO(char ucData , FILE *stream)
{
uart_putc(ucData);
return 0;
}
int main(void)
{
uart_init(9600, UART_NO_PARITY, UART_EIGHT_DATA_BIT, UART_ONE_STOP_BIT);
stdout = &mystdout;
printf("Hello, world!\n");
return 0;
}
(to be continued…)

