// interrupt.c // Author: Allen Porter // // Interrupt driven serial I/O, dumps the receive buffer every second. The // delay is mostly to show that the buffering is working. // // Written with help from lots of random snippets around #include #include #include #include #include #include #define BAUD 2400 #define BUFSIZ 255 char receive[BUFSIZ]; uint8_t receive_head = 0; uint8_t receive_tail = 0; char transmit[BUFSIZ]; uint8_t transmit_head = 0; uint8_t transmit_tail = 0; #define BUFFER_LENGTH(name) \ ((name##_tail > name##_head) ? name##_tail - name##_head \ : name##_head - name##_tail) #define ADVANCE(name) name = (name + 1) % BUFSIZ; void init(unsigned int baud) { unsigned int ubrr = (F_CPU / (16 * baud)) - 1; UBRRH = (unsigned char)(ubrr >> 8); UBRRL = (unsigned char)ubrr; UCSRB = _BV(RXEN) | _BV(TXEN) | _BV(RXCIE); UCSRC = _BV(URSEL) | (0<