void usart_setup(void) { // Set the port direction. TRISCbits.TRISC6 = 0; TRISCbits.TRISC7 = 1; // High baud rate select (TXSTA) TXSTAbits.BRGH = 1; // compute the divider for speed (see page 161) SPBRG = ((int)(FOSC/(16UL * BAUD) -1)); // Asynchronous mode (TXSTA) TXSTAbits.SYNC = 0; // 8 bits reception (RCSTA) RCSTAbits.RX9 = 0; // enable the receiver (RCSTA) RCSTAbits.CREN = 1; // 8 bits transmission (TXTSA) TXSTAbits.TX9 = 0; // enable transmission (TXTSA) TXSTAbits.TXEN = 1; // enable the Serial Port (RCSTA) RCSTAbits.SPEN = 1; }