#define TX_INCR(a, b) (((a) + (b)) & (RB_SIZE - 1)) #define UART_TX_OK (UCSRA & _BV(UDRE)) #define TX_FREE (!(TX_INCR(tx_wr, 1) == tx_rd)) SIGNAL(SIG_UART_TRANS) { PORTD ^= _BV(6); if (tx_rd != tx_wr) { UDR = tx_buf[tx_rd]; tx_rd = TX_INCR(tx_rd, 1); } } void uart_putc(char c) { if (UART_TX_OK && (tx_wr == tx_rd)) { UDR = c; } else { while (TX_INCR(tx_wr, 1) == tx_rd) ; tx_buf[tx_wr] = c; tx_wr = TX_INCR(tx_wr, 1); } } void uart_init(void) { tx_wr = tx_rd = 0; /* set baudrate */ //UBRRL = (((F_CPU) / (16 * MIDI_BAUD)) - 1); //UBRRL = 51; // 9600 @ 8mhz UBRRL = 15; // 31250kbps @ 8mhz /* enable TX, interrupts */ UCSRB = _BV(TXEN) | _BV(TXCIE); /* enable 2x mode */ //UCSRA = _BV(U2X); sei(); }