Created
April 21, 2018 15:37
-
-
Save rubberduck203/0233adb39ab20fd013918c88ebcb85b1 to your computer and use it in GitHub Desktop.
AVR UART
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <avr/io.h> | |
#include <util/delay.h> | |
/* 9600 8n1 com */ | |
#define BAUD 9600 | |
#define BAUDRATE ((F_CPU)/(BAUD*16UL)-1) | |
int main(void) | |
{ | |
/*Set baud rate */ | |
UBRR0H = (unsigned char)(BAUDRATE>>8); | |
UBRR0L = (unsigned char)BAUDRATE; | |
/* Enable receiver and transmitter */ | |
UCSR0B = (1<<RXEN0)|(1<<TXEN0); | |
/* Set frame format: 8data, 1stop bit */ | |
UCSR0C = (1<<USBS0)|(3<<UCSZ00); | |
for(;;) { | |
/* Wait for empty transmit buffer */ | |
while ( !( UCSR0A & (1<<UDRE0)) ) | |
; | |
/* Put data into buffer, sends the data */ | |
UDR0 = 'u'; | |
/* wait half a sec before sending again*/ | |
_delay_ms(500); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment