/***** * Software Half-duplex UART Driver * Henry Chan (hc352 @cornell.edu) * Based on AVR304 * * Sample Usage: * RECEIVING * sw_uart_receive_byte(); * // Other instructions while receiving * if (sw_uart_state == IDLE) { * x = sw_uart_rxdata; * } * * TRANSMITTING * sw_uart_send_byte(c); * // Other instructions while transmitting * if (sw_uart_state == IDLE) { * //Stuff when transmission done * } ****/ #include "softuart.h" #include "portdeclarations.h" /**** * sw_uart_states: * IDLE -- Neither transmitting or receiving * TX -- Transmitting a byte * RX -- Receiving a byte ****/ volatile char sw_uart_state; volatile char sw_uart_rxdata; // Received byte char sw_uart_txdata; // Byte to transmit volatile char bitcount; // Bits received or transmitted void sw_uart_init() { // Set pin directions SWUART_DDRD |= (1<= 8) { // Disable timer TCCR0B &= ~((1<> SWUART_RXPIN )< 8) { // If byte+1bit (stop bit) transmitted TCCR0B &= ~((1<