42 lines
913 B
C
42 lines
913 B
C
/*
|
|
* uart.h
|
|
*
|
|
*/
|
|
|
|
#include <avr/io.h>
|
|
#include <stdlib.h>
|
|
|
|
#ifndef UART_H_
|
|
#define UART_H_
|
|
|
|
#define UART_RECV_BUFFER_SIZE 33 // max 32 chars + '\0'
|
|
|
|
//#define BAUD 19200UL // Baudrate
|
|
#define BAUD 9600UL // Baudrate
|
|
|
|
// Berechnungen
|
|
//#define UBRR_VAL F_CPU/16/BAUD-1
|
|
#define UBRR_VAL ((F_CPU+BAUD*8UL)/(BAUD*16UL)-1UL) // clever runden
|
|
#define BAUD_REAL (F_CPU/(16UL*(UBRR_VAL+1UL))) // Reale Baudrate
|
|
#define BAUD_ERROR ((BAUD_REAL*1000)/BAUD) // Fehler in Promille, 1000 = kein Fehler.
|
|
|
|
#if ((BAUD_ERROR<990) || (BAUD_ERROR>1010))
|
|
#error Baud rate error greater than 1% - too high!
|
|
#endif
|
|
|
|
|
|
void uart_init();
|
|
|
|
void uart_sendChar(char c);
|
|
void uart_sendString (char *s);
|
|
void uart_sendBinary(int c);
|
|
void uart_sendInt(int c);
|
|
void uart_sendHex(int c);
|
|
void uart_sendLF();
|
|
|
|
|
|
char uart_receiveChar();
|
|
char* uart_receiveString();
|
|
|
|
#endif /* UART_H_ */
|