|
#include // part specific constants and macros
#include "PSoCAPI.h" // PSoC API definitions for all User Modules
#define REPL_BUF_LEN 6
BYTE repl_buffer[REPL_BUF_LEN];
BYTE bRxData;
BOOL fWaitToReceiveByte(void);
void TxZeroTerminatedRamString( BYTE * pbStrPtr );
void main()
{
str:
TX8_1_Start(TX8_1_PARITY_NONE);
RX8_1_Start(RX8_1_PARITY_NONE);
if ( fWaitToReceiveByte() )
{
repl_buffer[0] = bRxData;
TxZeroTerminatedRamString(repl_buffer);
}
TX8_1_Stop();
RX8_1_Stop();
goto str;
}
BOOL fWaitToReceiveByte(void)
{
BYTE bRxStatus;
/* Wait to receive full byte*/
while ( !( bRxStatus=RX8_1_bReadRxStatus() & RX8_1_RX_COMPLETE ) )
{
/* might want to sleep or keep track of time */
}
/* data received, now check for errors */
if (( bRxStatus & RX8_1_RX_NO_ERROR ) == 0 )
{
/* no error detected */
bRxData = RX8_1_bReadRxData();
return( TRUE );
}
else
{
/* error detected */
bRxData = bRxStatus;
return( FALSE );
}
}
//
// TX8_1_Start() should be called prior to calling this function.
//
void TxZeroTerminatedRamString( BYTE * pbStrPtr )
{
/* check for the end condition, before sending the next byte */
while( *pbStrPtr != 0 )
{
/* send the next byte */
TX8_1_SendData( *pbStrPtr );
/* Wait for the data to start transmitting */
while( !( TX8_1_bReadTxStatus() & TX8_1_TX_BUFFER_EMPTY ) );
pbStrPtr++;
}
}
E-mail: info@telesys.ru