-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathUSART.h
51 lines (46 loc) · 1.42 KB
/
USART.h
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
49
50
51
#ifndef __USART_H__
#define __USART_H__
/* Includes: */
#include <avr/io.h>
/* Macros: */
#define USART_BAUDRATE 38400
#define BAUD_PRESCALE (((F_CPU / (USART_BAUDRATE * 16UL))) - 1)
#if defined(__AVR_ATmega88__)
#define UCSRA UCSR0A
#define UCSRB UCSR0B
#define UCSRC UCSR0C
#define RXEN RXEN0
#define TXEN TXEN0
#define UBRRH UBRR0H
#define UBRRL UBRR0L
#define UDR UDR0
#define RXC RXC0
#define RXCIE RXCIE0
#define UDRE UDRE0
#define UCSZ0 UCSZ00
#define UCSZ1 UCSZ01
#define UDDR DDRD
#define UDDX DDD1
#elif defined(__AVR_ATmega32U4__)
#define UCSRA UCSR1A
#define UCSRB UCSR1B
#define UCSRC UCSR1C
#define RXEN RXEN1
#define TXEN TXEN1
#define UBRRH UBRR1H
#define UBRRL UBRR1L
#define UDR UDR1
#define RXC RXC1
#define RXCIE RXCIE1
#define UDRE UDRE1
#define UCSZ0 UCSZ10
#define UCSZ1 UCSZ11
#define UDDR DDRD
#define UDDX DDD3
#endif
/* Function Prototypes: */
void USART_Init(void);
uint8_t USART_HasByte(void);
uint8_t USART_ReceiveByte(void);
void USART_SendByte(uint8_t byte);
#endif