/* flaneth - flash and ethernet - dartboard mod
* version 0.1 date 2008-11-09
* Copyright (C) 2007-2008 Stefan Schuermans <stefan@schuermans.info>
* Copyleft: GNU public license V2 - http://www.gnu.org/copyleft/gpl.html
* a BlinkenArea project - http://www.blinkenarea.org/
*/
#include <stdio.h>
#include <avr/io.h>
#include <avr/wdt.h>
#include "macros.h"
#include "uart.h"
#define BAUD_RATE 38400
// initialize
void UartInit( void ) // (extern)
{
// enable transmission
UCSR0B = 1<<TXEN;
// set baudrate (16MHz crystal)
UBRR0L = 16000000 / (BAUD_RATE * 16L) - 1;
// set STDOUT to use UartPutchar
fdevopen( UartPutchar, NULL );
}
// write a character
int UartPutchar( char c, FILE * file ) // (extern)
{
// wait until last character was sent
while( bit_is_clear( UCSR0A, UDRE ) )
wdt_reset( );
// send character
UDR0 = c;
return 0;
file = NULL; // keep compiler happy
}