summaryrefslogtreecommitdiff
path: root/floppyMusic/uart.c
blob: aed8acd6a1ddb078e93042e77acc69bbc6c2eb46 (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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/*
 * uart.c
 *
 * Created: 02.05.2017 20:48:26
 *  Author: Jonas
 */ 

 #include "uart.h"

 void uart_init(uint32_t _baud)
 {
	 unsigned int ubrr = _GET_UBBR(_baud);

	 UBRRH = (ubrr<<8);
	 UBRRL = ubrr;

	 /* Enable receiver and transmitter */
	 UCSRB = (1<<RXEN)|(1<<TXEN);

	 /* Set frame format: 8data, 2stop bit */
	 UCSRC = (1<<URSEL)|(1<<USBS)|(3<<UCSZ0);
 }

 void uart_send(char _data)
 {
	 while(!(UCSRA & (1<<UDRE)));
	 UDR = _data;
 }

 void uart_send_string(char *_data)
 {
	 char *data = _data;

	 while(*data != '\0')
	 {
		 uart_send(*data);
		 data++;
	 }
 }

 char uart_recieve()
 {
	 while(!(UCSRA & (1<<RXC)));

	 return UDR;
 }