Может кому пригодится как пример кода.
Код: Выделить всё
#include <avr\io.h>
#include <string.h>
void UART_Init(void)
{
UBRRH = 0;
UBRRL = 51;
UCSRC = _BV(URSEL) | (3<<UCSZ0);
UCSRB = _BV(TXEN) | _BV(RXEN);
}
void UART_Write(const char *str)
{
int i;
for (i=0; str[i]; i++) {
while (!(UCSRA & _BV(UDRE)));
UDR = str[i];
}
}
void UART_Read(char *str)
{
int i = 0;
char ch;
memset(str, 0, sizeof(str));
do {
while (!(UCSRA & _BV(RXC)));
ch = UDR;
str[i] = ch;
i++;
while (!(UCSRA & _BV(UDRE)));
UDR = ch;
} while (ch != 0x0D);
}
int main(void)
{
char str[32];
asm("wdr");
WDTCR = _BV(WDCE) | _BV(WDE);
WDTCR = 0;
UART_Init();
for (;;) {
UART_Read(str);
UART_Write(str);
}
}