#include #define BRATE 25 //38.4K #define U_ENABLE 0x8000 // enable the UART peripheral #define U_TX 0x0400 // enable transmission void initU2( void) { PADCFG1 = 0x00FC; AD1PCFG =0xffff; __builtin_write_OSCCONL(OSCCON & 0xbf) ; RPINR19bits.U2RXR = 13; // make pin RP13 U2RX RPOR7bits.RP15R =5; //make RP15 U2TX __builtin_write_OSCCONL(OSCCON | 0x40) ; _BRGH =0; U2BRG = BRATE; U2MODE = U_ENABLE; U2STA = U_TX; } int putU2( int c) { while ( U2STAbits.UTXBF); U2TXREG = c; return c; } char getU2( void) { while ( !U2STAbits.URXDA); return U2RXREG; } main() { char c; LATB = 0; TRISB = 0; TRISBbits.TRISB13 = 1; TRISBbits.TRISB15 = 0; initU2(); while (1) { c = getU2(); if(c == 65){ LATBbits.LATB3 = 1; } else{ LATBbits.LATB3 = 0; } putU2(65); } }