jadeku
Main Page
Data Structures
Files
File List
Globals
src
sci.c
Go to the documentation of this file.
1
23
#include "
app.h
"
24
31
BYTE
SCI_Init
(
DWORD
baud,
BYTE
ninebits)
32
{
33
int
X;
34
DWORD
tmp;
35
36
/* calculate and set baud rate register */
37
/* for asynchronous mode */
38
tmp = 16UL * baud;
39
X = (int)(
FOSC
/tmp) - 1;
40
if
((X>255) || (X<0))
41
{
42
tmp = 64UL * baud;
43
X = (int)(
FOSC
/tmp) - 1;
44
if
((X>255) || (X<0))
45
{
46
return
TRUE
;
/* panic - baud rate unobtainable */
47
}
48
else
49
BRGH =
CLEAR
;
/* low baud rate */
50
}
51
else
52
BRGH =
SET
;
/* high baud rate */
53
SPBRG = X;
/* set the baud rate */
54
55
SYNC =
CLEAR
;
/* asynchronous */
56
SPEN =
ENABLE
;
/* enable serial port pins */
57
CREN =
ENABLE
;
/* enable reception */
58
SREN =
CLEAR
;
/* no effect */
59
TXIE =
DISABLE
;
/* disable tx interrupts */
60
RCIE =
DISABLE
;
/* disable rx interrupts */
61
TX9 = ninebits?
SET
:
CLEAR
;
/* 8- or 9-bit transmission */
62
RX9 = ninebits?
SET
:
CLEAR
;
/* 8- or 9-bit reception */
63
TXEN =
ENABLE
;
/* enable the transmitter */
64
65
return
FALSE
;
66
}
67
68
//#pragma interrupt_level 1
73
void
SCI_Write
(
BYTE
byte)
74
{
75
while
(!TXIF)
/* set when register is empty */
76
continue
;
77
TXREG = byte;
78
79
return
;
80
}
81
86
BYTE
SCI_Read
(
void
)
87
{
88
while
(!RCIF)
/* set when register is not empty */
89
continue
;
90
91
return
RCREG;
/* RXD9 and FERR are gone now */
92
}
93
98
BYTE
SCI_CheckOverrun
(
void
)
99
{
100
if
(OERR)
// re-enable after overrun error
101
{
102
CREN =
DISABLE
;
103
CREN =
ENABLE
;
104
return
TRUE
;
105
}
106
107
return
FALSE
;
108
}
109
110
//*****************************************************************************[ENDL]***************
SCI_Write
void SCI_Write(BYTE byte)
Definition:
sci.c:73
SCI_Read
BYTE SCI_Read(void)
Definition:
sci.c:86
SET
#define SET
Definition:
pgrl.h:104
TRUE
#define TRUE
Definition:
pgrl.h:97
CLEAR
#define CLEAR
Definition:
pgrl.h:103
SCI_Init
BYTE SCI_Init(DWORD baud, BYTE ninebits)
Definition:
sci.c:31
FALSE
#define FALSE
Definition:
pgrl.h:98
DISABLE
#define DISABLE
Definition:
pgrl.h:86
SCI_CheckOverrun
BYTE SCI_CheckOverrun(void)
Definition:
sci.c:98
ENABLE
#define ENABLE
Definition:
pgrl.h:85
DWORD
unsigned long DWORD
Definition:
pgrl.h:46
BYTE
unsigned char BYTE
Definition:
pgrl.h:38
app.h
JADEKU project defines and dependency headers.
FOSC
#define FOSC
Definition:
sci.h:27
Generated by
1.8.14