#include <p18cxxx.h>
#include <usart.h>


/********************************************************************
*    Function Name:  WriteUSART                                     *
*    Return Value:   none                                           *
*    Parameters:     data: data to transmit                         *
*    Description:    This routine transmits a byte out the USART.   *
********************************************************************/

void WriteUSART(char data)
{
  if(TXSTAbits.TX9)  // 9-bit mode?
  {
    TXSTAbits.TX9D = 0;       // Set the TX9D bit according to the
    if(USART_Status.TX_NINE)  // USART Tx 9th bit in status reg
      TXSTAbits.TX9D = 1;
  }

  TXREG = data;      // Write the data byte to the USART
}


/***********************************************************************************
Macro       : BusyUSART()

Include     : usart.h

Description : Macro returns if the usart transmitting or not
 
Arguments   : None
 
Returns     : Returns a value indicating if the usart transmitter is currently busy. 
		This Macro should be used prior to commencing a new transmission
***********************************************************************************/
#define BusyUSART( ) (!TXSTAbits.TRMT)


/**************************************************************************
Macro       : putcUSART

Description : macro is identical to WriteUSART, #define to WriteUSART in usart.h
 
Arguments   : None
 
Remarks     : None 
***************************************************************************/
#define putcUSART WriteUSART



/**********************************************************************
*    Function Name:  putsUSART                                        *
*    Return Value:   void                                             *
*    Parameters:     data: pointer to string of data                  *
*    Description:    This routine transmits a string of characters    *
*                    to the USART including the null.                 *
**********************************************************************/


void putsUSART( char *data)
{
  do
  {  // Transmit a byte
    while(BusyUSART());
    putcUSART(*data);
  } while( *data++ );
}


