|
#include {avr/io.h}
#include {avr/signal.h}
#include {avr/interrupt.h}
volatile unsigned char uart_flag;
register unsigned char tmp asm("r6");
INTERRUPT( SIG_UART_RECV )
{
tmp = UDR;
uart_flag = 1;
}
void uart_putchar(char c)
{
loop_until_bit_is_set(UCSRA, UDRE);
UDR = c;
}
int main(void)
{
uart_flag = 0;
tmp = 0;
// init UART
UBRRL = 51; /* 9600 Bd at 8MHz */
UCSRB = _BV(TXEN)|_BV(RXEN)|_BV(RXCIE);
// init LED
DDRB |= _BV(PB1); // LED
sei();
uart_putchar('A');
while(1)
{
if( uart_flag == 1)
{
uart_flag = 0;
uart_putchar(tmp);
PORTB ^= _BV(PB1); // inverse LED
}
}
return 0;
}
E-mail: info@telesys.ru