-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuart.h
More file actions
executable file
·67 lines (57 loc) · 1.54 KB
/
uart.h
File metadata and controls
executable file
·67 lines (57 loc) · 1.54 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
#ifndef UART_H
#define UART_H
char UART_Init(void)
{
// ABDEN disabled; WUE disabled; RCIDL idle; ABDOVF no_overflow; SCKP async_noninverted_sync_fallingedge; BRG16 16bit_generator;
BAUD1CON = 0x48;
// ADDEN disabled; RX9 8-bit; RX9D 0x0; FERR no_error; CREN enabled; SPEN enabled; SREN disabled; OERR no_error;
RC1STA = 0x90;
// CSRC slave_mode; TRMT TSR_empty; TXEN enabled; BRGH hi_speed; SYNC asynchronous; SENDB sync_break_complete; TX9D 0x0; TX9 8-bit;
TX1STA = 0x26;
//Rev001
SP1BRGL = 0xCF;
SP1BRGH = 0x00;
//Rev002
//SP1BRGL = 0xA0;
//SP1BRGH = 0x01;
}
//--------------------UART TRANSMISSION----------------------------------------
void UART_Write(uint8_t data)
{
while(0 == PIR1bits.TXIF);
TX1REG = data; // Write the data byte to the USART.
}
void UART_Write_Text(char *text)
{
for(int i=0;text[i] != '\0' ;i++)
UART_Write(text[i]);
}
void SendUartCmd (char * cmd){
UART_Write_Text(cmd);
}
//--------------------UART RECEPTION----------------------------------------
char UART_Data_Ready()
{
return RCIF;
}
uint8_t UART_Read(void)
{
while(!PIR1bits.RCIF)
if(1 == RC1STAbits.OERR)
{
RC1STAbits.CREN = 0;
RC1STAbits.CREN = 1;
}
return RC1REG;
}
void UART_Read_Text(char *Output, unsigned int length)
{
Output[0] = UART_Read();
for(int i=1;i<length;i++)
{
Output[i] = UART_Read();
if(Output[i-1]=='O' && Output[i]=='K')
break;
}
}
#endif