-
Notifications
You must be signed in to change notification settings - Fork 0
/
serial.c
60 lines (51 loc) · 1.39 KB
/
serial.c
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/*
* File: serial.c
* Author: Juan Nicola
* Comments:
* Revision history:
*/
#include "serial.h"
void init_comms(void)
{
SPBRG = DIVIDER;
TXSTA = (SPEED|NINE_BITS|0x20);
RCSTA = (NINE_BITS|0x90);
TRISC7 = INPUT; //RX
TRISC6 = OUTPUT; //TX
SPBRG=DIVIDER;
BRGH=1; //data rate for sending (see 16F876 manual under 'USART')
SYNC=0; //asynchronous
SPEN=1; //enable serial port pins
SREN=0; // Single Receive Enable bit. No effect in Async mode
TXIE=0; //disable tx interrupts
RCIE=1; //enable rx interrupts
TX9=0; //8-bit transmission
RX9=0; //8-bit reception
CREN=1; //enable reception
TXEN=0; //reset transmitter
TXEN=1; //enable the transmitter
}
void putch(char byte)
{
/* output one byte */
while(!TRMT) /* set whilst TX in progress */
continue;
TXREG = byte;
}
char getch() {
/* retrieve one byte */
while(!RCIF) /* set when register is not empty */
continue;
return RCREG;
}
/** @Brief Send a 8 chars length string through the serial port.
19.1C1S -> 19.1 Cent. degrees and 1S is device status ON.
*/
void comm_send_log (char *log_data)
{
while (*log_data)
{
putch (*log_data);
log_data++;
}
}