#include <htc.h>
#include <stdio.h>
#include "usart.h"

// output one byte
void putch(unsigned char byte) {

    while(!TXIF)	// set when register is empty
        continue;
    TXREG = byte;
}


// retrieve one byte
unsigned char getch() {

    while(!RCIF)	// set when register has a byte
        if(OERR | FERR) {   // if overrun or framing error
            CREN = 0;       // reset receiver
            CREN = 1;
        };
    return RCREG;
}


// retrieve one byte and echo it
unsigned char getche(void) {

    unsigned char c;
    putch(c = getch());
    return c;
}

