diff --git a/USART/USART.cpp b/USART/USART.cpp index b5cf3e8..aa47442 100644 --- a/USART/USART.cpp +++ b/USART/USART.cpp @@ -180,11 +180,7 @@ void USART0::setMode( Mode enmMode ) } ////////////////////////////////////////////////////////////////////////// -USART0::USART0() : USART0( 9600, 8, Parity::DISABLED, StopBit::ONE, Mode::ASYNCHRONOUS ) -{} - -////////////////////////////////////////////////////////////////////////// -USART0::USART0( uint32_t ui32BaudRate, uint8_t ui8DataBits, Parity enmParity, StopBit enmStopBits, Mode enmMode /* = Mode::ASYNCHRONOUS */ ) +USART0::USART0() { #ifdef USART_SHAREDIO m_vui8pUCSRA = &UCSRA; @@ -203,8 +199,6 @@ USART0::USART0( uint32_t ui32BaudRate, uint8_t ui8DataBits, Parity enmParity, St m_vui8pUBRRL = &UBRR0L; m_vui8pUDR = &UDR0; #endif - - init( ui32BaudRate, ui8DataBits, enmParity, enmStopBits, enmMode ); } ////////////////////////////////////////////////////////////////////////// @@ -212,14 +206,14 @@ USART0::~USART0() {} ////////////////////////////////////////////////////////////////////////// -void USART0::init( uint32_t ui32BaudRate, uint8_t ui8DataBits, Parity enmParity, StopBit enmStopBits, Mode enmMode /* = Mode::ASYNCHRONOUS */ ) +void USART0::init( uint32_t ui32BaudRate /* = 9600 */, uint8_t ui8DataBits /* = 8 */, Parity enmParity /* = Parity::DISABLED */, StopBit enmStopBits /* = StopBit::ONE */, Mode enmMode /* = Mode::ASYNCHRONOUS */ ) { setBaudRate( ui32BaudRate ); setDataBits( ui8DataBits ); setParity( enmParity ); setStopBits( enmStopBits ); setMode( enmMode ); - + setRXState( true ); setTXState( true ); } @@ -425,107 +419,91 @@ void USART0::transmit( char chData ) ////////////////////////////////////////////////////////////////////////// void USART0::transmit( unsigned char uchData ) { - vector vecBuffer( 4 ); - sprintf( vecBuffer.data(), "%hhu", uchData ); - transmit( vecBuffer.data() ); + sprintf( m_szConvertBuffer, "%hhu", uchData ); + transmit( m_szConvertBuffer ); } ////////////////////////////////////////////////////////////////////////// void USART0::transmit( short int shiData ) { - vector vecBuffer( 6 ); - sprintf( vecBuffer.data(), "%hd", shiData ); - transmit( vecBuffer.data() ); + sprintf( m_szConvertBuffer, "%hd", shiData ); + transmit( m_szConvertBuffer ); } ////////////////////////////////////////////////////////////////////////// void USART0::transmit( unsigned short int ushiData ) { - vector vecBuffer( 6 ); - sprintf( vecBuffer.data(), "%hu", ushiData ); - transmit( vecBuffer.data() ); + sprintf( m_szConvertBuffer, "%hu", ushiData ); + transmit( m_szConvertBuffer ); } ////////////////////////////////////////////////////////////////////////// void USART0::transmit( int iData ) { - vector vecBuffer( 6 ); - sprintf( vecBuffer.data(), "%d", iData ); - transmit( vecBuffer.data() ); + sprintf( m_szConvertBuffer, "%d", iData ); + transmit( m_szConvertBuffer ); } ////////////////////////////////////////////////////////////////////////// void USART0::transmit( unsigned int uiData ) { - vector vecBuffer( 6 ); - sprintf( vecBuffer.data(), "%u", uiData ); - transmit( vecBuffer.data() ); + sprintf( m_szConvertBuffer, "%u", uiData ); + transmit( m_szConvertBuffer ); } ////////////////////////////////////////////////////////////////////////// void USART0::transmit( long int liData ) { - vector vecBuffer( 11 ); - sprintf( vecBuffer.data(), "%ld", liData ); - transmit( vecBuffer.data() ); + sprintf( m_szConvertBuffer, "%ld", liData ); + transmit( m_szConvertBuffer ); } ////////////////////////////////////////////////////////////////////////// void USART0::transmit( unsigned long int uliData ) { - vector vecBuffer( 11 ); - sprintf( vecBuffer.data(), "%lu", uliData ); - transmit( vecBuffer.data() ); + sprintf( m_szConvertBuffer, "%lu", uliData ); + transmit( m_szConvertBuffer ); } ////////////////////////////////////////////////////////////////////////// void USART0::transmit( long long int lliData ) { - vector vecBuffer( 21 ); - sprintf( vecBuffer.data(), "%lld", lliData ); - transmit( vecBuffer.data() ); + sprintf( m_szConvertBuffer, "%lld", lliData ); + transmit( m_szConvertBuffer ); } ////////////////////////////////////////////////////////////////////////// void USART0::transmit( unsigned long long int ulliData ) { - vector vecBuffer( 21 ); - sprintf( vecBuffer.data(), "%llu", ulliData ); - transmit( vecBuffer.data() ); + sprintf( m_szConvertBuffer, "%llu", ulliData ); + transmit( m_szConvertBuffer ); } ////////////////////////////////////////////////////////////////////////// void USART0::transmit( float fData ) { - vector vecBuffer( 64 ); - sprintf( vecBuffer.data(), "%f", static_cast( fData ) ); - transmit( vecBuffer.data() ); + sprintf( m_szConvertBuffer, "%f", static_cast( fData ) ); + transmit( m_szConvertBuffer ); } ////////////////////////////////////////////////////////////////////////// void USART0::transmit( double dData ) { - vector vecBuffer( 64 ); - sprintf( vecBuffer.data(), "%f", dData ); - transmit( vecBuffer.data() ); + sprintf( m_szConvertBuffer, "%f", dData ); + transmit( m_szConvertBuffer ); } ////////////////////////////////////////////////////////////////////////// void USART0::transmit( long double ldData ) { - vector vecBuffer( 64 ); - sprintf( vecBuffer.data(), "%f", static_cast( ldData ) ); - transmit( vecBuffer.data() ); + sprintf( m_szConvertBuffer, "%f", static_cast( ldData ) ); + transmit( m_szConvertBuffer ); } #ifdef SECOND_USART ////////////////////////////////////////////////////////////////////////// -USART1::USART1() : USART1( 9600, 8, Parity::DISABLED, StopBit::ONE, Mode::ASYNCHRONOUS ) -{} - -////////////////////////////////////////////////////////////////////////// -USART1::USART1( uint32_t ui32BaudRate, uint8_t ui8DataBits, Parity enmParity, StopBit enmStopBits, Mode enmMode /* = Mode::ASYNCHRONOUS */ ) +USART1::USART1() { m_vui8pUCSRA = &UCSR1A; m_vui8pUCSRB = &UCSR1B; @@ -533,8 +511,6 @@ USART1::USART1( uint32_t ui32BaudRate, uint8_t ui8DataBits, Parity enmParity, St m_vui8pUBRRH = &UBRR1H; m_vui8pUBRRL = &UBRR1L; m_vui8pUDR = &UDR1; - - init( ui32BaudRate, ui8DataBits, enmParity, enmStopBits, enmMode ); } ////////////////////////////////////////////////////////////////////////// diff --git a/USART/USART.cppproj b/USART/USART.cppproj index d882896..c9adea3 100644 --- a/USART/USART.cppproj +++ b/USART/USART.cppproj @@ -55,123 +55,89 @@ ISP 1843200 + + + + + + + + com.atmel.avrdbg.tool.simulator + + + Simulator + - -mmcu=atmega328p -B "%24(PackRepoDir)\atmel\ATmega_DFP\1.0.106\gcc\dev\atmega328p" - True - True - True - True - True - False - True - True - - - NDEBUG - - - - - %24(PackRepoDir)\atmel\ATmega_DFP\1.0.106\include - - - Optimize for size (-Os) - True - True - True - True - True - - - NDEBUG - - - - - %24(PackRepoDir)\atmel\ATmega_DFP\1.0.106\include - - - Optimize for size (-Os) - True - True - True - True - -Wextra -std=c++11 - - - libm - - - - - %24(PackRepoDir)\atmel\ATmega_DFP\1.0.106\include - - - + -mmcu=atmega328p -B "%24(PackRepoDir)\atmel\ATmega_DFP\1.0.106\gcc\dev\atmega328p" + True + True + True + True + True + False + True + True + %24(PackRepoDir)\atmel\ATmega_DFP\1.0.106\include + True + True + True + True + True + %24(PackRepoDir)\atmel\ATmega_DFP\1.0.106\include + True + True + True + True + -Wextra -std=c++11 + True + libmlibprintf_flt + %24(PackRepoDir)\atmel\ATmega_DFP\1.0.106\include + NDEBUG + Optimize for size (-Os) + NDEBUG + Optimize for size (-Os) + echo "C:\avrdude-6.2\avrdude.exe" -v -p$(avrdevice) %%* -Uflash:w:"$(OutputDirectory)\$(Name).hex":i > "$(MSBuildProjectDirectory)\avrdude.bat" - -mmcu=atmega328p -B "%24(PackRepoDir)\atmel\ATmega_DFP\1.0.106\gcc\dev\atmega328p" - True - True - True - True - True - False - True - True - - - DEBUG - - - - - %24(PackRepoDir)\atmel\ATmega_DFP\1.0.106\include - - - Optimize (-O1) - True - True - Default (-g2) - True - True - True - - - DEBUG - - - - - %24(PackRepoDir)\atmel\ATmega_DFP\1.0.106\include - - - Optimize (-O1) - True - True - Default (-g2) - True - True - -Wextra -std=c++11 - - - libm - - - - - %24(PackRepoDir)\atmel\ATmega_DFP\1.0.106\include - - - Default (-Wa,-g) - + -mmcu=atmega328p -B "%24(PackRepoDir)\atmel\ATmega_DFP\1.0.106\gcc\dev\atmega328p" + True + True + True + True + True + False + True + True + %24(PackRepoDir)\atmel\ATmega_DFP\1.0.106\include + True + True + True + True + True + %24(PackRepoDir)\atmel\ATmega_DFP\1.0.106\include + True + True + True + True + -Wextra -std=c++11 + True + libmlibprintf_flt + %24(PackRepoDir)\atmel\ATmega_DFP\1.0.106\include + DEBUG + Optimize (-O1) + Default (-g2) + DEBUG + Optimize (-O1) + Default (-g2) + Default (-Wa,-g) + echo "C:\avrdude-6.2\avrdude.exe" -v -p$(avrdevice) %%* -Uflash:w:"$(OutputDirectory)\$(Name).hex":i > "$(MSBuildProjectDirectory)\avrdude.bat" diff --git a/USART/USART.h b/USART/USART.h index e0ba439..1e53087 100644 --- a/USART/USART.h +++ b/USART/USART.h @@ -1,7 +1,7 @@ /* * Copyright (c) by BlackMark 2015-2016 -* Date 05/01/2016 -* Version 2.2 +* Date 19/05/2016 +* Version 2.3 */ #ifndef USART_H @@ -91,6 +91,7 @@ protected: volatile uint8_t *m_vui8pUDR; private: + char m_szConvertBuffer[64]; uint8_t readUCSRC(); void setUCSRC( uint8_t ui8UCSRC ); @@ -104,10 +105,9 @@ private: public: USART0(); - USART0( uint32_t ui32BaudRate, uint8_t ui8DataBits, Parity enmParity, StopBit enmStopBits, Mode enmMode = Mode::ASYNCHRONOUS ); ~USART0(); - void init( uint32_t ui32BaudRate, uint8_t ui8DataBits, Parity enmParity, StopBit enmStopBits, Mode enmMode = Mode::ASYNCHRONOUS ); + void init( uint32_t ui32BaudRate = 9600, uint8_t ui8DataBits = 8, Parity enmParity = Parity::DISABLED, StopBit enmStopBits = StopBit::ONE, Mode enmMode = Mode::ASYNCHRONOUS ); bool receiveByte( unsigned char &chData, uint32_t ui32DelayMS ); unsigned char receiveByte(); @@ -167,7 +167,6 @@ class USART1 : public USART0 { public: USART1(); - USART1( uint32_t ui32BaudRate, uint8_t ui8DataBits, Parity enmParity, StopBit enmStopBits, Mode enmMode = Mode::ASYNCHRONOUS ); ~USART1(); }; diff --git a/USART/main.cpp b/USART/main.cpp index fd1c533..25571dc 100644 --- a/USART/main.cpp +++ b/USART/main.cpp @@ -11,7 +11,8 @@ int main() { USART0 cUSART; - + cUSART.init(); + uint32_t ui32Counter = 0; cUSART << "\r\nSizes: \r\n"; @@ -49,6 +50,9 @@ int main() cUSART >> dNumber; cUSART << "\r\nYou entered: " << dNumber << "\r\n\r\n"; + + unsigned char uchByte; + cUSART.receiveByte( uchByte, 1000 ); _delay_ms( 1000 ); }