Skip to content

Instantly share code, notes, and snippets.

@ibanezmatt13
Created July 9, 2015 20:17
Show Gist options
  • Save ibanezmatt13/2eb55f5be3d013146d44 to your computer and use it in GitHub Desktop.
Save ibanezmatt13/2eb55f5be3d013146d44 to your computer and use it in GitHub Desktop.
#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