// initialise UART to 2400 baud, 8 data, 1 stop bit
// U1BRG 2400 = 192, 4800 = 95, 9600 = 49, 19200=24, 38400=11 at 7.37MHz
// 2400 = 262, 56700 = 10 at 10MHz
// oscillator mode XT w/PLL 4*
// U1BRG counter = Fcy (16 * baudrate) - 1
//int U1BRGcounter = FCY/(16*2400L) - 1;
void initUART(long int baudRate)
{
// TRISD=0;
TRISFbits.TRISF2 = 0;
TRISFbits.TRISF3 = 1;
U1MODE=0x8000; // enable UART
U1STA=0; // clear status register
// calcular baud rate counter - add 0.5 to round to nearest integer
U1BRG= (int) ((FCY/(16.0*baudRate) - 1)+0.5); //U1BRGcounter; // Baudrate value
U1STA=U1STA | 0x400; // enable TX
}