LTlib LaurTec Library  4.0.0 Beta
Open Source C Library for Microchip Microcontrollers based on XC8 Compiler
 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 BAUDRATE_19200 207
59  #define BAUDRATE_57600 68
60  #define BAUDRATE_115200 34
61 #endif
62 
63 
64 #if (UART_CLOCK == 40000000)
65  #define UART_BAUDRATE_9600 64
66  #define UART_BAUDRATE_19200 31
67  #define UART_BAUDRATE_57600 10
68  #define UART_BAUDRATE_115200 4
69 #endif
70 
71 #if (UART_CLOCK == 20000000)
72  #define UART_BAUDRATE_9600 129
73  #define UART_BAUDRATE_19200 64
74  #define UART_BAUDRATE_57600 21
75  #define UART_BAUDRATE_115200 10
76 #endif
77 
78 #if (UART_CLOCK == 16000000)
79  #define UART_BAUDRATE_9600 103
80  #define UART_BAUDRATE_19200 51
81  #define UART_BAUDRATE_57600 16
82  #define UART_BAUDRATE_115200 8
83 #endif
84 
85 
86 //****************************************************
87 // UART 1
88 //****************************************************
89 
99 #define UART1_data_ready( ) (PIR1bits.RCIF)
100 
109 #define UART1_close( ) (RCSTA&=0b01001111,TXSTAbits.TXEN=0)
110 
122 #define UART1_TX_busy( ) (!TXSTAbits.TRMT)
123 
124 
125 //****************************************************
126 // UART 2
127 //****************************************************
128 
129 #ifdef UART_MODULE_TYPE_2
130  #define UART2_is_busy( ) (!TXSTA2bits.TRMT)
131  #define UART2_data_ready( ) (PIR3bits.RC2IF)
132  #define UART2_close( ) (RCSTA2&=0b01001111,TXSTA2bits.TXEN=0)
133  #define UART2_TX_busy( ) (!TXSTA2bits.TRMT)
134 #endif
135 
149 void UART1_open (unsigned int baud_rate);
150 
151 #ifdef UART_MODULE_TYPE_2
152  void UART2_open (unsigned int baud_rate);
153 #endif
154 
165 void UART1_write_byte (unsigned char data);
166 
167 #ifdef UART_MODULE_TYPE_2
168  void UART2_write_byte (unsigned char data);
169 #endif
170 
179 unsigned char UART1_read_byte(void);
180 
181 #ifdef UART_MODULE_TYPE_2
182  unsigned char UART2_read_byte(void);
183 #endif
184 
195 void UART1_write_message(const unsigned char *data);
196 
197 #ifdef UART_MODULE_TYPE_2
198  void UART2_write_message(const unsigned char *data);
199 #endif
200 
211 void UART1_write_string (unsigned char *data);
212 
213 #ifdef UART_MODULE_TYPE_2
214  void UART2_write_string (unsigned char *data);
215 #endif
216 
217 #endif