LTlib LaurTec Library
4.0.3
Open Source C Library for Microchip Microcontrollers based on XC8 Compiler
Main Page
Data Structures
Files
File List
Globals
All
Data Structures
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Macros
module_UART.h
Go to the documentation of this file.
1
/*******************************************************************************
2
3
Autore : Mauro Laurenti
4
Versione : 1.0
5
6
Created on Date : 25/11/2015
7
Last update : 25/11/2015
8
9
CopyRight 2006-2015 all rights are reserved
10
11
********************************************************
12
SOFTWARE LICENSE AGREEMENT
13
********************************************************
14
15
The usage of the supplied software imply the acceptance of the following license.
16
17
The software supplied herewith by Mauro Laurenti (the Author) is intended for
18
use solely and exclusively on Microchip PIC Microcontroller (registered mark).
19
The software is owned by the Author, and is protected under applicable
20
copyright laws. All rights are reserved.
21
Any use in violation of the foregoing restrictions may subject the
22
user to criminal sanctions under applicable laws, as well as to civil liability
23
for the breach of the terms and conditions of this license.
24
Commercial use is forbidden without a written acknowledgement with the Author.
25
Personal or educational use is allowed if the application containing the
26
following software doesn't aim to commercial use or monetary earning of any kind.
27
28
THIS SOFTWARE IS PROVIDED IN AN "AS IS" CONDITION. NO WARRANTIES,
29
WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED
30
TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
31
PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. THE AUTHOR SHALL NOT,
32
IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR
33
CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
34
35
*******************************************************************************/
36
37
#ifndef LTLIB_UART_MODULE_H
38
#define LTLIB_UART_MODULE_H
39
40
#ifdef __XC8
41
#include <xc.h>
42
#endif
43
44
//*****************************************
45
// Library Test
46
//*****************************************
47
#include "
LTlib.h
"
48
49
#ifndef UART_LIBRARY_SUPPORTED
50
#error (LTlib) The MCU you have selected is not supported by module_UART library.
51
#endif
52
53
//****************************************************
54
// BAUDRATE DEFINITION
55
//****************************************************
56
57
#if (UART_CLOCK == 64000000)
58
#define UART_BAUDRATE_9600 0 // Not supported
59
#define BAUDRATE_19200 207
60
#define UART_BAUDRATE_38400 103
61
#define BAUDRATE_57600 68
62
#define BAUDRATE_115200 34
63
#endif
64
65
#if (UART_CLOCK == 48000000)
66
#define UART_BAUDRATE_9600 0 // Not supported
67
#define UART_BAUDRATE_19200 155
68
#define UART_BAUDRATE_38400 77
69
#define UART_BAUDRATE_57600 51
70
#define UART_BAUDRATE_115200 25
71
#endif
72
73
74
#if (UART_CLOCK == 40000000)
75
#define UART_BAUDRATE_9600 64
76
#define UART_BAUDRATE_19200 31
77
#define UART_BAUDRATE_38400 15
78
#define UART_BAUDRATE_57600 10
79
#define UART_BAUDRATE_115200 4
80
#endif
81
82
#if (UART_CLOCK == 20000000)
83
#define UART_BAUDRATE_9600 129
84
#define UART_BAUDRATE_19200 64
85
#define UART_BAUDRATE_38400 31
86
#define UART_BAUDRATE_57600 21
87
#define UART_BAUDRATE_115200 10
88
#endif
89
90
#if (UART_CLOCK == 16000000)
91
#define UART_BAUDRATE_9600 103
92
#define UART_BAUDRATE_19200 51
93
#define UART_BAUDRATE_38400 25
94
#define UART_BAUDRATE_57600 16
95
#define UART_BAUDRATE_115200 8
96
#endif
97
98
99
//****************************************************
100
// UART 1
101
//****************************************************
102
112
#define UART1_data_ready( ) (PIR1bits.RCIF)
113
122
#define UART1_close( ) (RCSTA&=0b01001111,TXSTAbits.TXEN=0)
123
135
#define UART1_TX_busy( ) (!TXSTAbits.TRMT)
136
137
138
//****************************************************
139
// UART 2
140
//****************************************************
141
142
#ifdef UART_MODULE_TYPE_2
143
#define UART2_is_busy( ) (!TXSTA2bits.TRMT)
144
#define UART2_data_ready( ) (PIR3bits.RC2IF)
145
#define UART2_close( ) (RCSTA2&=0b01001111,TXSTA2bits.TXEN=0)
146
#define UART2_TX_busy( ) (!TXSTA2bits.TRMT)
147
#endif
148
162
void
UART1_open
(
unsigned
int
baud_rate);
163
164
#ifdef UART_MODULE_TYPE_2
165
void
UART2_open (
unsigned
int
baud_rate);
166
#endif
167
178
void
UART1_write_byte
(
unsigned
char
data);
179
180
#ifdef UART_MODULE_TYPE_2
181
void
UART2_write_byte (
unsigned
char
data);
182
#endif
183
192
unsigned
char
UART1_read_byte
(
void
);
193
194
#ifdef UART_MODULE_TYPE_2
195
unsigned
char
UART2_read_byte(
void
);
196
#endif
197
208
void
UART1_write_message
(
const
unsigned
char
*data);
209
210
#ifdef UART_MODULE_TYPE_2
211
void
UART2_write_message(
const
unsigned
char
*data);
212
#endif
213
224
void
UART1_write_string
(
unsigned
char
*data);
225
226
#ifdef UART_MODULE_TYPE_2
227
void
UART2_write_string (
unsigned
char
*data);
228
#endif
229
230
#endif
LTlib_v_4.0.3
inc
module_UART.h
Generated on Wed Aug 3 2016 19:57:31 for LTlib LaurTec Library by
1.8.3.1