aboutsummaryrefslogtreecommitdiff
path: root/examples/usartecho/echo.c
blob: 12b88f6ba5682b62e59b647123575df04eb3404c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <avr/io.h>
#include <util/delay.h>
#include <string.h>
#include "../../usart.h"

void rec(uint8_t data) {
    if (data == '\r') {
        usart_send_str("\n\r"); // Send new line character with carriage return
    } else if (data)
        usart_send(data);
}

int main() {
    DDRB = _BV(DDB1);
    usart_init_async();
    SREG |= _BV(7);
    usart_send('a');
    usart_send('b');
    usart_send('c'); // This character is not printed for some reason TODO
    usart_send('d');
    usart_send_str("\n\rHello, there is UART echo!\n\r");
    usart_receive = rec;

    while (1);
}