1 | #include <avr/io.h> // Deklaration
|
2 | #include <avr/signal.h>
|
3 | #include <avr/interrupt.h>
|
4 |
|
5 | #define TAKT 8000000UL // Controllertakt 8 Mhz
|
6 | #define BAUD 9600UL // Baudrate
|
7 |
|
8 |
|
9 | #define TEILER (TAKT+BAUD*8)/(BAUD*16)-1 // clever runden
|
10 | #define BAUD_REAL TAKT/(16*(TEILER+1)) // Reale Baudrate
|
11 | #define BAUD_ERROR (BAUD_REAL*1000)/BAUD // Fehler in Promille, 1000 = kein Fehler.
|
12 |
|
13 | #if ((BAUD_ERROR<990) || (BAUD_ERROR>1010))
|
14 | #error Systematischer Fehler der Baudrate grösser 1% und damit zu hoch!
|
15 | #endif
|
16 |
|
17 |
|
18 | SIGNAL(SIG_UART_DATA) // Sendedatenregister Interrupt Funktion
|
19 | {
|
20 | UDR = 'i';
|
21 | }
|
22 |
|
23 |
|
24 | int main(void)
|
25 | {
|
26 | UBRRL = TEILER;
|
27 | UCSRB |= (1 << TXEN); // Sender an
|
28 | UCSRC |= (1 << URSEL) | (1 << UCSZ1) | (1 << UCSZ0); // asyn. 8 bit
|
29 |
|
30 | sbi(UCSRB, UDRIE); // Sendedaten-Interrupt ein
|
31 | sei(); // glob. Interrupt ein
|
32 |
|
33 |
|
34 | while (1);
|
35 |
|
36 | }
|