/*************************************************************************** * Copyright (C) 2006 - 2020 by Olaf Rempel * * razzor AT kopf MINUS tisch DOT de * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; version 2 of the License, * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #include #include "target.h" #include "uart.h" #define UART_CALC_BAUDRATE(baudRate) (((uint32_t)F_CPU) / (((uint32_t)baudRate)*16) -1) /* *********************************************************************** * uart_send * *********************************************************************** */ void uart_send(uint8_t data) { #if defined(__AVR_ATmega16__) loop_until_bit_is_set(UCSRA, UDRE); UDR = data; #elif defined(__AVR_ATmega328P__) loop_until_bit_is_set(UCSR0A, UDRE0); UDR0 = data; #endif } /* uart_send */ /* *********************************************************************** * uart_recv * *********************************************************************** */ uint8_t uart_recv(void) { #if defined(__AVR_ATmega16__) loop_until_bit_is_set(UCSRA, RXC); return UDR; #elif defined(__AVR_ATmega328P__) loop_until_bit_is_set(UCSR0A, RXC0); return UDR0; #endif } /* uart_recv */ /* *********************************************************************** * uart_rx_ready * *********************************************************************** */ uint8_t uart_rx_ready(void) { #if defined(__AVR_ATmega16__) return ((UCSRA & (1<>8) & 0xFF; UBRRL = (UART_CALC_BAUDRATE(BAUDRATE) & 0xFF); /* enable usart with 8n1 */ UCSRB = (1<>8) & 0xFF; UBRR0L = (UART_CALC_BAUDRATE(BAUDRATE) & 0xFF); /* enable usart with 8n1 */ UCSR0B = (1<