Serial Musical Organ 1.0
Buzzer controller and musical organ
Loading...
Searching...
No Matches
USART.c
Go to the documentation of this file.
1
16#include "includes/CPU.h"
17#include <avr/io.h>
18#include "includes/USART.h"
19#include <util/setbaud.h>
20
34void initUSART(void)
35{
36#ifdef BAUD
37#warning "BAUD IS DEFINED"
38#else
39#warning "BAUD ISNT DEFINED"
40#endif
41
42 /* Set baud rate registers */
43 UBRR0H = UBRRH_VALUE;
44 UBRR0L = UBRRL_VALUE;
45
46 /* Configure double speed mode if necessary */
47#if USE_2X
48 UCSR0A |= (1 << U2X0);
49#else
50 UCSR0A &= ~(1 << U2X0);
51#endif
52
53 /* Enable transmitter and receiver */
54 UCSR0B = (1 << TXEN0) | (1 << RXEN0);
55
56 /* Set frame format: 8 data bits, 1 stop bit, no parity */
57 UCSR0C = (1 << UCSZ01) | (1 << UCSZ00);
58}
59
71void transmitByte(uint8_t data)
72{
73 loop_until_bit_is_set(UCSR0A, UDRE0);
74 UDR0 = data;
75}
76
88uint8_t receiveByte(void)
89{
90 loop_until_bit_is_set(UCSR0A, RXC0);
91 return UDR0;
92}
93
105void printString(const char *String)
106{
107 while (*String)
108 transmitByte(*String++);
109}
CPU configuration and definitions for ATmega168.
void printString(const char *String)
Sends a null-terminated string over USART.
Definition USART.c:105
void initUSART(void)
Initializes the USART peripheral.
Definition USART.c:34
uint8_t receiveByte(void)
Receives a single byte from USART.
Definition USART.c:88
void transmitByte(uint8_t data)
Transmits a single byte over USART.
Definition USART.c:71
USART serial communication interface.