// Configure USART
TXSTA = 0x20;
RCSTA = 0x90;
// See if we can use the high baud rate setting
#if ((GetPeripheralClock()+2*BAUD_RATE)/BAUD_RATE/4 - 1) <= 255
SPBRG = (GetPeripheralClock()+2*BAUD_RATE)/BAUD_RATE/4 - 1;
TXSTAbits.BRGH = 1;
#else // Use the low baud rate setting
SPBRG = (GetPeripheralClock()+8*BAUD_RATE)/BAUD_RATE/16 - 1;
#endif
// Enable Interrupts
RCONbits.IPEN = 1; // Enable interrupt priorities
INTCONbits.GIEH = 1;
INTCONbits.GIEL = 1;
INTCONbits.PEIE = 1; // enable peripheral interrupts.
PIE1bits.RCIE = 1; // enable USART receive interrupt
IPR1bits.RCIP=0; // EUSART Receive Interrupt Priority 0 = Low priority