-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuart.c
More file actions
72 lines (52 loc) · 1.21 KB
/
Copy pathuart.c
File metadata and controls
72 lines (52 loc) · 1.21 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
#include <xc.h> /* XC8 General Include File */
#include <stdbool.h> /* Bools, true of false */
#include <stdint.h> /* For uint8_t definition */
#include <stdlib.h>
#include <pic16f877a.h>
#include "ISO.h"
static void configure_baud_uart(void);
static void enable_async_port_uart(void);
// Initialize serial connection
// ~10400 baud --> UBRR = 47
// 8-bit character size
// No parity bit, 1 stop bit
inline void init_uart(void)
{
configure_baud_uart();
enable_async_port_uart();
return;
}
static void configure_baud_uart(void)
{
BRGH = 1;
SPBRG = 23;
return;
}
static void enable_async_port_uart(void)
{
SYNC = 0;
RCSTAbits.SPEN = 1;
/*
* Transmission is enabled by setting enable bit, TXEN(TXSTA<5>).
* The actual transmission will not occur until the TXREG register has
* been loaded with data.
*/
TXSTAbits.TXEN = 1;
return;
}
void disable_async_port_uart(void)
{
RCSTAbits.SPEN = 0;
TXSTAbits.TXEN = 0;
}
void write_uart(uint8_t data)
{
while (!TRMT);
TXREG = data;
return;
}
uint8_t read_uart(void)
{
while(!RCIF);
return RCREG;
}