uart2.h
Go to the documentation of this file.
1 /*
2 
3 UART2 Driver Header File for PIC24.
4 
5 ********************************************************************************
6  FileName: uart2.c
7  Dependencies: HardwareProfile.h
8  Processor: PIC24
9  Compiler: MPLAB C30
10  Linker: MPLAB LINK30
11  Company: Microchip Technology Incorporated
12 
13 Author Date Comment
14 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
15 Anton Alkhimenok 18-Oct-2005
16 KO 11-Oct-2006 v1.0
17 Paolo Tamayo 17-Feb-2009 Added UART2Char2Hex(), UART2Hex2Char(),
18  UART2ClearError(), UART2DataReceived()
19 
20 ********************************************************************************
21 Software License Agreement
22 
23 Microchip Technology Inc. ("Microchip") licenses to you the right to use, copy,
24 modify and distribute the software - including source code - only for use with
25 Microchip microcontrollers or Microchip digital signal controllers; provided
26 that no open source or free software is incorporated into the Source Code
27 without Microchip’s prior written consent in each instance.
28 
29 The software is owned by Microchip and its licensors, and is protected under
30 applicable copyright laws. All rights reserved.
31 
32 SOFTWARE AND DOCUMENTATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
33 EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF
34 MERCHANTABILITY, TITLE, NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
35 IN NO EVENT SHALL MICROCHIP OR ITS LICENSORS BE LIABLE OR OBLIGATED UNDER
36 CONTRACT, NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION, BREACH OF WARRANTY, OR
37 OTHER LEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT DAMAGES OR EXPENSES
38 INCLUDING BUT NOT LIMITED TO ANY INCIDENTAL, SPECIAL, INDIRECT OR
39 CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF PROCUREMENT OF
40 SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, ANY CLAIMS BY THIRD PARTIES (INCLUDING
41 BUT NOT LIMITED TO ANY DEFENSE THEREOF), OR OTHER SIMILAR COSTS.
42 
43 ********************************************************************************
44 */
45 
46 //******************************************************************************
47 // Function Prototypes
48 //******************************************************************************
49 
50 /*********************************************************************
51 Function: char UART2GetChar()
52 
53 PreCondition: none
54 
55 Input: none
56 
57 Output: last character received
58 
59 Side Effects: none
60 
61 Overview: returns last character received
62 
63 Note: none
64 
65 ********************************************************************/
66 char UART2GetChar();
67 
68 /*********************************************************************
69 Function: void UART2PutChar(char ch)
70 
71 PreCondition: none
72 
73 Input: none
74 
75 Output: none
76 
77 Side Effects: none
78 
79 Overview: puts character
80 
81 Note: none
82 ********************************************************************/
83 void UART2PutChar( char ch );
84 
85 /*********************************************************************
86 Function: void UART2Init(void)
87 
88 PreCondition: none
89 
90 Input: none
91 
92 Output: none
93 
94 Side Effects: none
95 
96 Overview: initializes UART
97 
98 Note: none
99 ********************************************************************/
100 void UART2Init();
101 
102 /*******************************************************************************
103 Function: UART2IsPressed()
104 
105 Precondition:
106  UART2Init must be called prior to calling this routine.
107 
108 Overview:
109  This routine checks to see if there is a new byte in UART reception buffer.
110 
111 Input: None.
112 
113 Output:
114  0 : No new data received.
115  1 : Data is in the receive buffer
116 
117 *******************************************************************************/
118 char UART2IsPressed();
119 
120 /*******************************************************************************
121 Function: UART2PrintString( char *str )
122 
123 Precondition:
124  UART2Init must be called prior to calling this routine.
125 
126 Overview:
127  This function prints a string of characters to the UART.
128 
129 Input: Pointer to a null terminated character string.
130 
131 Output: None.
132 
133 *******************************************************************************/
134 void UART2PrintString( char *str );
135 
136 /*******************************************************************************
137 Function: UART2PutDec(unsigned char dec)
138 
139 Precondition:
140  UART2Init must be called prior to calling this routine.
141 
142 Input: Binary data
143 
144 Output: none
145 
146 Side Effects: none
147 
148 Overview: This function converts decimal data into a string
149  and outputs it to UART.
150 
151 Note: none
152 *******************************************************************************/
153 void UART2PutDec( unsigned char dec );
154 
155 /*******************************************************************************
156 Function: UART2PutHex
157 
158 Precondition:
159  UART2Init must be called prior to calling this routine.
160 
161 Input: Binary data
162 
163 Output: none
164 
165 Side Effects: none
166 
167 Overview: This function converts hex data into a string
168  and outputs it to UART.
169 
170 Note: none
171 *******************************************************************************/
172 void UART2PutHex( int toPrint );
173 
174 /*******************************************************************************
175 Function: UART2PutHexWord(unsigned int toPrint)
176 
177 Precondition:
178  UART2Init must be called prior to calling this routine.
179 
180 Input: Binary data
181 
182 Output: none
183 
184 Side Effects: none
185 
186 Overview: This function converts hex data into a string
187  and outputs it to UART.
188 
189 Note: none
190 *******************************************************************************/
191 #if defined( __C30__ ) || defined( __PIC32MX__ )
192 void UART2PutHexWord( unsigned int toPrint );
193 void UART2PutHexDWord( unsigned long int toPrint );
194 #endif
195 
196 /*********************************************************************
197 Function: char UART2Char2Hex(char ch)
198 
199 PreCondition: none
200 
201 Input: ASCII to be converted
202 
203 Output: number
204 
205 Side Effects: none
206 
207 Overview: converts ASCII coded digit into number
208 
209 Note: none
210 
211 ********************************************************************/
212 char UART2Char2Hex(char ch);
213 
214 /*********************************************************************
215 Function: char UART2Hex2Char(char hex)
216 
217 PreCondition: none
218 
219 Input: number
220 
221 Output: ASCII code
222 
223 Side Effects: none
224 
225 Overview: converts low nibble into ASCII coded digit
226 
227 Note: none
228 
229 ********************************************************************/
230 char UART2Hex2Char(char hex);
231 
232 /*********************************************************************
233 Function: void UART2ClrError(void)
234 
235 PreCondition: none
236 
237 Input: none
238 
239 Output: character received
240 
241 Side Effects: none
242 
243 Overview: wait for character
244 
245 Note: none
246 
247 ********************************************************************/
248 void UART2ClrError(void);
249 
250 /*********************************************************************
251 Macros: UART2DataReceived()
252 
253 PreCondition: none
254 
255 Input: none
256 
257 Output: zero if character is not received
258 
259 Side Effects: none
260 
261 Overview: checks if data is available
262 
263 Note: none
264 
265 ********************************************************************/
266 #define UART2DataReceived() (U2STAbits.URXDA)
267 
char UART2GetChar()
char UART2IsPressed()
void UART2PrintString(char *str)
void UART2PutDec(unsigned char dec)
void UART2PutHex(int toPrint)
void UART2ClrError(void)
void UART2PutChar(char ch)
void UART2PutHexWord(unsigned int toPrint)
char UART2Char2Hex(char ch)
void UART2Init()
char UART2Hex2Char(char hex)
void UART2PutHexDWord(unsigned long int toPrint)