/* avr_uart.h Provide functions to set up uart. Copyright 2007, 2012 Henrik Björkman www.eit.se/habl This file 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. 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. If you do modify it please make a note about it in the history section below. History 2005-02-16 Modified for atmega8 and renamed. Henrik Björkman 2007-03-15 Modified for atmega88. Henrik Björkman 2012-05-14 Corrected baudrate on ATMEGA88 Henrik Björkman */ /* ------------------------------------------------------------------------- * BUGS * ------------------------------------------------------------------------- */ /* // port_or is not defined in iomacro.h (which gets included in io.h) while // __port_or has a definition. This seems to be a bug in iomacro.h #define port_or __port_or // ditto #define port_and __port_and */ /* ------------------------------------------------------------------------- * includes * ------------------------------------------------------------------------- */ #include #include #include #include "avr_cfg.h" #include "avr_uart.h" /* compatibilty macros for old style */ /* for new design instead of "sbi(DDRC,PC5);" use "DDRC|= _BV(PC5);" */ #ifndef cbi #define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit)) #endif #ifndef sbi #define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit)) #endif #ifndef outp #define outp(value,sfr) (_SFR_BYTE(sfr) = value) #endif #ifndef inp #define inp(sfr) (_SFR_BYTE(sfr)) #endif /* ------------------------------------------------------------------------- * local variables and defines * ------------------------------------------------------------------------- */ #ifdef __AVR_ATmega8__ #define UART_OUTBUF_EMPTY() (!( UCSRA & (1<>8); UBRRL = (unsigned char)ubrr_value; //Setting this bit UCSRA bit 1 (U2Xn) the baudrate is doubled, remember to adjust calculation of ubrr_value. //UCSRA |= _BV(1); /* Enable receiver and transmitter */ UCSRB = (1<>8); UBRR0L = (unsigned char)ubrr_value; // Setting this bit UCSR0A bit 1 (U2Xn) the baudrate is doubled // If used (or not used) remember to adjust ubrr calculation accordingly. //UCSR0A |= _BV(1); /* Enable receiver and transmitter */ UCSR0B = (1<