diff options
author | Jonas Gunz <himself@jonasgunz.de> | 2017-06-16 00:22:47 +0200 |
---|---|---|
committer | Jonas Gunz <himself@jonasgunz.de> | 2017-06-16 00:22:47 +0200 |
commit | f9357256249657af2374e3c334b9180e63dc5a30 (patch) | |
tree | 32b4b0990d77467a17eb77a52186060460b82fdd /floppyMusic/uart.c | |
parent | a5ae30562fc5adbabaf46763b8826ac4d843c26e (diff) | |
download | avrFloppy-f9357256249657af2374e3c334b9180e63dc5a30.tar.gz |
Split in different files
Diffstat (limited to 'floppyMusic/uart.c')
-rw-r--r-- | floppyMusic/uart.c | 15 |
1 files changed, 6 insertions, 9 deletions
diff --git a/floppyMusic/uart.c b/floppyMusic/uart.c index aed8acd..3aac221 100644 --- a/floppyMusic/uart.c +++ b/floppyMusic/uart.c @@ -7,23 +7,20 @@ #include "uart.h" - void uart_init(uint32_t _baud) + void uart_init(unsigned int _baud) { - unsigned int ubrr = _GET_UBBR(_baud); + unsigned int ubrr = (F_CPU / (16 * _baud)) - 1; - UBRRH = (ubrr<<8); - UBRRL = ubrr; + UBRRH = (unsigned char)(ubrr>>8) & 0xff; + UBRRL = (unsigned char)ubrr & 0xff; - /* 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))); + while(!(UCSRA & (1<<UDRE))); //Wait for previous data to be sent UDR = _data; } @@ -40,7 +37,7 @@ char uart_recieve() { - while(!(UCSRA & (1<<RXC))); + while(!(UCSRA & (1<<RXC))); //Wait for data return UDR; } |