uart/usart/main.cpp

94 lines
2.5 KiB
C++

/*
* Copyright (c) by BlackMark 2015-2018
* Date 11/08/2018
* Version 1.6
*/
#include <stdio.h>
#include "array/array.h"
#include "usart/usart.h"
#include "clock.h"
int main()
{
sei();
USART0 &cUSART = USART0::inst();
cUSART.init();
uint32_t ui32Counter = 0;
array<char, 64> arrBuffer;
cUSART << "\r\nSizes: \r\n";
sprintf( arrBuffer.data(), "%d\r\n", sizeof( char ) );
cUSART << "sizeof( char ) = " << arrBuffer.data();
sprintf( arrBuffer.data(), "%d\r\n", sizeof( unsigned char ) );
cUSART << "sizeof( unsigned char ) = " << arrBuffer.data();
sprintf( arrBuffer.data(), "%d\r\n", sizeof( short int ) );
cUSART << "sizeof( short int ) = " << arrBuffer.data();
sprintf( arrBuffer.data(), "%d\r\n", sizeof( unsigned short int ) );
cUSART << "sizeof( unsigned short int ) = " << arrBuffer.data();
sprintf( arrBuffer.data(), "%d\r\n", sizeof( int ) );
cUSART << "sizeof( int ) = " << arrBuffer.data();
sprintf( arrBuffer.data(), "%d\r\n", sizeof( unsigned int ) );
cUSART << "sizeof( unsigned int ) = " << arrBuffer.data();
sprintf( arrBuffer.data(), "%d\r\n", sizeof( long int ) );
cUSART << "sizeof( long int ) = " << arrBuffer.data();
sprintf( arrBuffer.data(), "%d\r\n", sizeof( unsigned long int ) );
cUSART << "sizeof( unsigned long int ) = " << arrBuffer.data();
sprintf( arrBuffer.data(), "%d\r\n", sizeof( long long int ) );
cUSART << "sizeof( long long int ) = " << arrBuffer.data();
sprintf( arrBuffer.data(), "%d\r\n", sizeof( unsigned long long int ) );
cUSART << "sizeof( unsigned long long int ) = " << arrBuffer.data();
sprintf( arrBuffer.data(), "%d\r\n", sizeof( float ) );
cUSART << "sizeof( float ) = " << arrBuffer.data();
sprintf( arrBuffer.data(), "%d\r\n", sizeof( double ) );
cUSART << "sizeof( double ) = " << arrBuffer.data();
sprintf( arrBuffer.data(), "%d\r\n", sizeof( long double ) );
cUSART << "sizeof( long double ) = " << arrBuffer.data();
sprintf( arrBuffer.data(), "%d\r\n\r\n", sizeof( void* ) );
cUSART << "sizeof( void* ) = " << arrBuffer.data();
while( true )
{
sprintf( arrBuffer.data(), "%lu", ui32Counter++ );
cUSART << "This has been running for \"" << arrBuffer.data() << "\" seconds!\r\n";
if( !cUSART.receiveLine( arrBuffer.data(), arrBuffer.size(), "\r" ) )
{
cUSART << "Receive error: ";
}
else
{
cUSART << "Echo: ";
}
cUSART << arrBuffer.data() << "\r\n";
uint8_t ui8Byte;
if( cUSART.receiveByte( ui8Byte, 1000 ) )
{
cUSART.transmitByte( ui8Byte );
cUSART << "\r\n";
}
}
return 0;
}