Created
July 9, 2015 20:17
-
-
Save ibanezmatt13/2eb55f5be3d013146d44 to your computer and use it in GitHub Desktop.
This file contains 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 <avr/interrupt.h> | |
#define USART_BAUDRATE 9600 | |
//#define BAUD_PRESCALE ((((F_CPU / 16) + (USART_BAUDRATE / 2) / (USART_BAUDRATE))-1) | |
#define BAUD_PRESCALE 104 | |
void initialise_UART(void) | |
{ | |
UCSR0B = ((1 << RXEN0) | (1 << TXEN0)); // enable TX and RX lines | |
UCSR0C = (1 << USBS0) | (3 << UCSZ00); // set 8 data bits, 2 stop bits | |
// set higher and lower parts of 16 bit register for setting baud rate | |
UBRR0H = (BAUD_PRESCALE >> 8); | |
UBRR0L = BAUD_PRESCALE; | |
UCSR0B |= (1 << RXCIE0); | |
sei(); | |
} | |
int main(void) | |
{ | |
unsigned int PIN = 5; | |
TCCR1B |= ((1 << CS10) | (1 << CS12)); | |
DDRB |= (1 << PIN); // enable LED pin in DDRB register | |
for (;;){ | |
if (TCNT1 >= 7812){ | |
PORTB ^= (1 << PIN); | |
TCNT1 = 0; | |
} | |
} | |
} | |
ISR(USART0_RXC_vect) | |
{ | |
char byte_received = UDR0; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment