00001
00007
00008
00009
00010
00011
00012
00013
00014
00015 #ifndef __UTIL_H__
00016 #define __UTIL_H__
00017
00018 #include <avr/io.h>
00019 #include <stdlib.h>
00020 #include <inttypes.h>
00021 #include <avr/delay.h>
00022 #include <avr/pgmspace.h>
00023
00024
00025
00026 #define ASYNC_MODE (0<<UMSEL) // asynchronous mode
00027 #define SYNC_MODE (1<<UMSEL) // synchronous mode
00028
00029 #define PARITY_DISABLE (0<<UPM1 | 0<<UPM0)
00030 #define PARITY_EVEN (1<<UPM1 | 0<<UPM0)
00031 #define PARITY_ODD (1<<UPM1 | 1<<UPM0)
00032
00033 #define STOP_BITS1 (0<<USBS) // 1 stop bit
00034 #define STOP_BITS2 (1<<USBS) // 2 stop bits
00035
00036 #define DATA_SIZE8 (0<<UCSZ2 | 1<<UCSZ1 | 1<<UCSZ0) // 8 bits
00037 #define DATA_SIZE9 (1<<UCSZ2 | 1<<UCSZ1 | 1<<UCSZ0) // 9 bits
00038
00039 void USART_Init(unsigned int uiBaud, unsigned char ucConf);
00040
00041
00042
00043
00044 #define TxStr_P( _PSTR_ ) _TxStr_P( PSTR(_PSTR_) )
00045 void _TxStr_P(const char *str_flash);
00046
00047 void TxChar( unsigned char ucData);
00048 void TxStr(const char * strBuff);
00049 void TxUint(uint16_t number);
00050 void TxEol(void);
00051 void TxHex(unsigned char ucData);
00052
00053 unsigned char RxChar( void );
00054
00055
00056 void delay(uint16_t d);
00057
00058 void delay_u(uint16_t d);
00059
00060
00061
00062
00063
00064 #ifdef DEBUG
00065
00066 #define TxStrk(_str_) TxStr(_str_)
00067 #define TxStrk_P(_str_) TxStr_P(_str_)
00068 #define TxUintk(_uint_) TxUint(_uint_)
00069 #define TxEolk() TxEol()
00070 #define TxHexk(_uint_) TxHex(_uint_)
00071 #define TxChark(_char_) TxChar(_char_)
00072
00073 #else
00074
00075 #define TxStrk(_str_)
00076 #define TxStrk_P(_str_)
00077 #define TxUintk(_uint_)
00078 #define TxEolk()
00079 #define TxHexk(_uint_)
00080 #define TxChark(_char_)
00081
00082 #endif
00083
00084 #endif