//Note: There should be a short delay after a packet transmission to avoid the transmit buffer overflow
// The short delay should be inserted after the buffer is close to be full 
char Com_putchar(unsigned char c)	//For use with the serial interrupt enabled, i.e., ES = 1; 
{
	//If the buffer is full, return an error value.
	if (Com_tbuflen () >= TBUF_SIZE)
	  return (-1);
	
	//Add the data to the transmit buffer. If the transmit interrupt is disabled, then enable it.
	tbuf [t_in & (TBUF_SIZE - 1)] = c;
	t_in++;

	return (0);
}

unsigned char Com_tbuflen (void)
{
	if (t_in - t_out >= 0)
    	return (t_in - t_out);
	else 
		return (t_in - t_out + 256);
}
