diff options
author | Nao Pross <naopross@thearcway.org> | 2018-01-18 10:28:49 +0100 |
---|---|---|
committer | Nao Pross <naopross@thearcway.org> | 2018-01-18 10:28:49 +0100 |
commit | 65a4baa17b439e1bdf42b6c0150a52e032562bb5 (patch) | |
tree | dbb74fa26a368ada952bb19db727f96c14500cee /src/rs232.c | |
download | Xilofono-65a4baa17b439e1bdf42b6c0150a52e032562bb5.tar.gz Xilofono-65a4baa17b439e1bdf42b6c0150a52e032562bb5.zip |
Move to version control
Diffstat (limited to 'src/rs232.c')
-rw-r--r-- | src/rs232.c | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/src/rs232.c b/src/rs232.c new file mode 100644 index 0000000..f4cf404 --- /dev/null +++ b/src/rs232.c @@ -0,0 +1,40 @@ +#include "rs232.h" +#include <xc.h> + +void eusart_init(void) { + + // set Async and 8 bits frame + TXSTAbits.SYNC = 0; + TXSTAbits.TX9 = 0; + + // 9600 baud prescaler + RCSTAbits.SPEN = 1; + SPBRG = 129; + TXSTAbits.BRGH = 1; + BAUDCONbits.BRG16 = 0; + + // set up TX / RX pins + TRISC7 = 1; + TRISC6 = 1; + RCSTAbits.CREN = 1; // enable continuous reception + TXSTAbits.TXEN = 1; +} + +void putch(char c) { + + while (!TXIF); + TXREG = c; +} + +char getch(void) { + + while (!RCIF); + return RCREG; +} + +char getche(void) { + char c = getch(); + putch(c); // echo + + return c; +} |