blob: f4cf4047e8a609ed741ccf95227ad7de6a16944b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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;
}
|