00001
00017 #ifndef _AVR_USART_H
00018 #define _AVR_USART_H
00021
00022
00023
00024
00025
00026
00027 #include <avr\io.h>
00028 #include <avr\interrupt.h>
00029
00030
00031
00032 #ifndef F_CPU
00033 #error " _AVR_USART_H: F_CPU has not been defined -> please check your project-settings"
00034 #endif
00035 #ifndef _XTAL
00036 #define _XTAL F_CPU+'UL'
00037
00038
00039 #endif
00040
00041
00042
00045 #define _AVR_USART_UBRR_CALC(_BAUD) (((_XTAL)/((_BAUD)*16UL))-1)
00046
00049 #define _AVR_USART_ENABLE_TRANSMIT() UCSRB |= ( 1 << TXEN )
00050 #define _AVR_USART_DISABLE_TRANSMIT() UCSRB &= ~( 1 << TXEN )
00051
00054 #define _AVR_USART_ENABLE_RECEIVE() UCSRB |= ( 1 << RXEN )
00055 #define _AVR_USART_DISABLE_RECEIVE() UCSRB &= ~( 1 << RXEN )
00056
00059 #define _AVR_USART_ENABLE_RECV_IRQ() UCSRB |= ( 1 << RXCIE )
00060 #define _AVR_USART_DISABLE_RECV_IRQ() UCSRB &= ~( 1 << RXCIE )
00061
00064 #define _AVR_USART_ENABLE_TRANS_IRQ() UCSRB |= ( 1 << TXCIE )
00065 #define _AVR_USART_DISABLE_TRANS_IRQ() UCSRB &= ~( 1 << TXCIE )
00066
00073 #define _AVR_USART_MODE_SYNCHRONOUS() UCSRC |= ( 1<<UMSEL)
00074 #define _AVR_USART_MODE_ASYNCHRONOUS() UCSRC &= ~( 1<<UMSEL)
00075
00078 #define _AVR_USART_SET_PARITY_NONE() UCSRC &= ~((1<<UPM0)|(1<<UPM1))
00079 #define _AVR_USART_SET_PARITY_EVEN() _AVR_USART_SET_PARITY_NONE(); UCSRC |= ( 1<<UMSEL)
00080 #define _AVR_USART_SET_PARITY_ODD() _AVR_USART_SET_PARITY_NONE(); UCSRC &= ~( 1<<UMSEL)
00081
00090 #define _AVR_USART_SET_DATABITS_TO_5() UCSRB &= ~(1<<UCSZ2); UCSRC &= ~(1<<UCSZ1)|(1<<UCSZ0)
00091 #define _AVR_USART_SET_DATABITS_TO_6() _AVR_USART_SET_DATABITS_TO_5(); UCSRB|= (0<<UCSZ2); UCSRC |= (0<<UCSZ1)|(1<<UCSZ0)
00092 #define _AVR_USART_SET_DATABITS_TO_7() _AVR_USART_SET_DATABITS_TO_5(); UCSRB|= (0<<UCSZ2); UCSRC |= (1<<UCSZ1)|(0<<UCSZ0)
00093 #define _AVR_USART_SET_DATABITS_TO_8() _AVR_USART_SET_DATABITS_TO_5(); UCSRB|= (0<<UCSZ2); UCSRC |= (1<<UCSZ1)|(1<<UCSZ0)
00094 #define _AVR_USART_SET_DATABITS_TO_9() _AVR_USART_SET_DATABITS_TO_5(); UCSRB|= (1<<UCSZ2); UCSRC |= (1<<UCSZ1)|(1<<UCSZ0)
00095
00099 #define _AVR_USART_SET_STOPPBITS_1() UCSRC &= ~(1<<USBS)
00100 #define _AVR_USART_SET_STOPPBITS_2() UCSRC |= (1<<USBS)
00101
00104 #define _AVR_USART_SAMPLE_AT_POS_EDGE() UCSRC &= ~(1<<UCPOL)
00105 #define _AVR_USART_SAMPLE_AT_NEG_EDGE() UCSRC |= (1<<UCPOL)
00106
00107
00108
00109
00110
00111
00112
00113
00114 void avr_usart_init_9600_8_1_N_Asyn (void);
00115 void avr_usart_putc (uint8_t data);
00116 void avr_usart_puts (char *s);
00117 uint8_t avr_usart_getc_wait (void);
00118 uint8_t avr_usart_getc (void);
00119 uint8_t avr_usart_getc_isr (void);
00120
00121 #endif
00122
00123