/* USART Interrupt */
interrupt [0x23] using [3] void SERIALISR(void)
{
/*
** This interrupt could be either the Receiver or the Transmitter
** TDRE is a GLOBAL bit which means a Transmit Interrupt occurred
** and there were no more characters left to transmit.
*/
if(RI == 1) /* Receiver Interrupt Flag -- SBUF has character */
{
RI = 0 ; /* Clear the Receive Interrupt Flag */
SDE = 0 ; /* Clear the Error Flag */
if( FE == 1 ) /* Check for Framing Error */
{
FE = 0 ; /* Clear Framing Error */
++g_RxFramingError ; /* Bump Error Counter */
LSDE = SDE = 1 ; /* Set Flags */
}
else if( g_nRx > 0) /* Overrun Error */
{
g_OverrunCharacter = SBUF ; /* Unload Character Register */
++g_RxDataOverrun ;
LSDE = SDE = 1 ;
}
else
{
g_RxChar = SBUF ; /* Unload the Character Register */
++g_nRx ; /* Bump the Receive Count */
}
/* Restart Link Timer */
g_linkTimer.w = g_linkTimerReload.w ;
LTF = 0 ;
}
if(TI == 1) /* Transmitter is Ready */
{
TI = 0 ; /* Clear the Transmit Interrupt Flag */
if(g_nTx > 0) /* Characters are ready to go */
{ TDRE = 0 ; /* Software Bit -- means Tx Busy */
/* In an 11-Bit Frame TB8 is the first of two STOP Bits */
/* In a 10-Bit Frame TB8 is a don't care */
TB8 = 1 ; SBUF = g_TxChar ;
g_TxChar = TxBuffer.d[TxBuffer.cp++] ; /* Take Next Character */
--g_nTx ; /* Decrement the Count */
}
else /* Transmitter is ready - but we are out of characters */
{ TDRE = 1 ; /* Tx Done and No more characters */
}
}
}