-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathuart.c
65 lines (51 loc) · 845 Bytes
/
uart.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
61
62
63
64
65
/*
* File: IR.c
* Author: rbeal
*
* Created on Febuary 02, 2016, 18:52 PM
*/
#include "uart.h"
#include <xc.h>
#include <stdio.h>
void init_soft_uart()
{
TMR0ON = 1;
T0CS = 0;
PSA = 1;
TRISC6 = 0;
LATC6 = 1;
}
void delay_100u()
{
TMR0L = 255-155;
TMR0IF = 0;
while(!TMR0IF);
}
void uart_write_c(char data)
{
int i;
LATC6 = 0; // start bit
delay_100u();
for (i=0;i<8;i++)
{
LATC6 = (data >> i)&0x01;
delay_100u();
}
LATC6 = 1; // stop bit
delay_100u();
__delay_ms(5);
}
void uart_write_s(const char *data)
{
int i;
for (i=0;*(data+i) != '\0';i++)
{
uart_write_c(*(data+i));
}
}
void uart_write_hex_c(char car)
{
char tmp[4];
sprintf(tmp, "0x%02X ", car);
uart_write_s(tmp);
}