Created
December 24, 2012 01:21
-
-
Save ricardas/4367019 to your computer and use it in GitHub Desktop.
Atmega328: USART
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
#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); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
why you delay in USART_transmit_string() ?