OpenUSART (USART_TX_INT_OFF &
USART_RX_INT_OFF &
USART_ASYNCH_MODE &
USART_EIGHT_BIT &
USART_CONT_RX &
USART_BRGH_HIGH, 131);
static unsigned char send_dummy[4];
static unsigned char recv_dummy[4];
int n_recv = 0;
int n_send = 0;
int send_bytes( unsigned char* bytes, int len)
{
int i = 0;
int n = 0;
for ( i = 0; i < len; i++)
{
while(BusyUSART());
WriteUSART( bytes[i] ); // send byte
DELAY_US_130
n++;
}
return n;
}
int recv_bytes( unsigned char *bytes, int len)
{
int i = 0;
int n = 0;
for ( i = 0; i < len; i++)
{
if ( DataRdyUSART() ) // is data aviliable in buffer?
{
bytes[i] = ReadUSART();
n++;
}else
{
// no data left return
return n;
}
}
return n;
}
// send load table
void send_lt(void)
{
/* test values */
send_dummy[0] = 0xD1;
send_dummy[1] = 0xD2;
send_dummy[2] = 0xD3;
send_dummy[3] = 0xD4;
n_send = send_bytes( send_dummy, sizeof(send_dummy));
}
void recv_lt(void)
{
memset( recv_dummy, 0, sizeof( recv_dummy));
n_recv = recv_bytes( recv_dummy, sizeof( recv_dummy));
....
}