#include "rs232.h" #include void eusart1_init(void) { // set Async and 8 bits frame TXSTA1bits.SYNC = 0; TXSTA1bits.TX9 = 0; // baud prescaler RCSTA1bits.SPEN = 1; SPBRG1 = 31; SPBRGH1 = 0; TXSTA1bits.BRGH = 0; BAUDCON1bits.BRG16 = 0; // set up TX / RX pins TRISCbits.TRISC7 = 1; TRISCbits.TRISC6 = 1; // enable continuous reception RCSTA1bits.CREN = 1; TXSTA1bits.TXEN = 1; } void eusart2_init(void) { // set Async and 8 bits frame TXSTA2bits.SYNC = 0; TXSTA2bits.TX9 = 0; // baud prescaler RCSTA2bits.SPEN = 1; SPBRG2 = 31; // 31250 bps //SPBRG2 = 103; // 9600 bps SPBRGH2 = 0; TXSTA2bits.BRGH = 0; BAUDCON2bits.BRG16 = 0; // set up TX / RX pins TRISDbits.TRISD7 = 1; TRISDbits.TRISD6 = 1; // enable continuous reception RCSTA2bits.CREN = 1; TXSTA2bits.TXEN = 1; } void eusart1_putch(char c) { while (!TX1IF); TX1REG = c; } void eusart2_putch(char c) { while (!TX2IF); TX2REG = c; } char eusart1_getch(void) { while (!RC1IF); return RC1REG; } char eusart1_getche(void) { char c = eusart1_getch(); eusart1_putch(c); // echo return c; }