Skip to content

Instantly share code, notes, and snippets.

@ricardas
Created December 24, 2012 01:21
Show Gist options
  • Save ricardas/4367019 to your computer and use it in GitHub Desktop.
Save ricardas/4367019 to your computer and use it in GitHub Desktop.
Atmega328: USART
#ifndef F_CPU
#define F_CPU 16000000
#endif
#include <avr/io.h>
#include <util/delay.h>
#define BAUD 9600
#define MYUBRR F_CPU/16/BAUD-1
void USART_init(unsigned int ubrr) {
UBRR0H = (unsigned char)(ubrr >> 8);
UBRR0L = (unsigned char)ubrr;
UCSR0B = 1 << RXEN0 | 1 << TXEN0;
UCSR0C = 0 << USBS0 | 3 << UCSZ00;
}
void USART_transmit( unsigned char data ) {
while(!(UCSR0A & (1 << UDRE0)));
UDR0 = data;
}
void USART_transmit_string(const char *data) {
unsigned char c;
while(( c = *data++ )) {
USART_transmit(c);
_delay_ms(10);
}
}
@Menginventor
Copy link

why you delay in USART_transmit_string() ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment