pic24_uart.h

00001 /*
00002  * "Copyright (c) 2008 Robert B. Reese, Bryan A. Jones, J. W. Bruce ("AUTHORS")"
00003  * All rights reserved.
00004  * (R. Reese, reese_AT_ece.msstate.edu, Mississippi State University)
00005  * (B. A. Jones, bjones_AT_ece.msstate.edu, Mississippi State University)
00006  * (J. W. Bruce, jwbruce_AT_ece.msstate.edu, Mississippi State University)
00007  *
00008  * Permission to use, copy, modify, and distribute this software and its
00009  * documentation for any purpose, without fee, and without written agreement is
00010  * hereby granted, provided that the above copyright notice, the following
00011  * two paragraphs and the authors appear in all copies of this software.
00012  *
00013  * IN NO EVENT SHALL THE "AUTHORS" BE LIABLE TO ANY PARTY FOR
00014  * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
00015  * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE "AUTHORS"
00016  * HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00017  *
00018  * THE "AUTHORS" SPECIFICALLY DISCLAIMS ANY WARRANTIES,
00019  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
00020  * AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
00021  * ON AN "AS IS" BASIS, AND THE "AUTHORS" HAS NO OBLIGATION TO
00022  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
00023  *
00024  * Please maintain this header in its entirety when copying/modifying
00025  * these files.
00026  *
00027  *
00028  */
00029 
00030 
00031 #ifndef _PIC24_UART1_H_
00032 #define _PIC24_UART1_H_
00033 
00034 // Only include if this UART module exists.
00035 #if (NUM_UART_MODS >= 1)
00036 
00037 // Documentation for this file. If the \file tag isn't present,
00038 // this file won't be documented.
00039 // Note: place this comment below the #if NUM_UART_MODS so Doxygen
00040 // will only see it once.
00052 #ifndef DEFAULT_BAUDRATE1
00053 #define DEFAULT_BAUDRATE1  DEFAULT_BAUDRATE
00054 #endif
00055 
00059 #ifndef DEFAULT_BRGH1
00060 #define DEFAULT_BRGH1  DEFAULT_BRGH
00061 #endif
00062 
00071 inline static void CONFIG_BAUDRATE_UART1(uint32 baudRate) {
00072 #if (DEFAULT_BRGH1 == 0)
00073   float f_brg = (((float) FCY)/((float) baudRate)/16.0) - 1.0;
00074 #else
00075   float f_brg = (((float) FCY)/((float) baudRate)/4.0) - 1.0;
00076 #endif
00077   ASSERT(f_brg < 65535.5);
00078   U1MODEbits.BRGH = DEFAULT_BRGH1;
00079   U1BRG = roundFloatToUint16(f_brg);
00080 }
00081 
00082 
00087 #define UXMODE_PDSEL_8DATA_NOPARITY   0
00088 #define UXMODE_PDSEL_8DATA_EVENPARITY 1
00089 #define UXMODE_PDSEL_8DATA_ODDPARITY  2
00090 #define UXMODE_PDSEL_9DATA_NOPARITY   3
00092 
00093 
00097 inline static void CONFIG_PDSEL_UART1(uint8 u8_pdsel) {
00098   ASSERT(u8_pdsel <= UXMODE_PDSEL_9DATA_NOPARITY);
00099   U1MODEbits.PDSEL = u8_pdsel;
00100 }
00101 
00106 inline static void CONFIG_STOPBITS_UART1(uint8 u8_numStopbits) {
00107   ASSERT(u8_numStopbits <= 2);
00108   U1MODEbits.STSEL = u8_numStopbits - 1;
00109 }
00110 
00112 inline static void ENABLE_UART1() {
00113   U1MODEbits.UEN = 0b00;                    // UxTX and UxRX pins are enabled and used; no flow control pins
00114   U1MODEbits.UARTEN = 1;                    // enable UART RX/TX
00115   U1STAbits.UTXEN = 1;                      //Enable the transmitter
00116 }
00117 
00122 #define IS_CHAR_READY_UART1() U1STAbits.URXDA
00123 
00128 #define IS_TRANSMIT_BUFFER_FULL_UART1() U1STAbits.UTXBF
00129 
00135 #define IS_TRANSMIT_COMPLETE_UART1() U1STAbits.TRMT
00136 
00138 inline static void WAIT_UNTIL_TRANSMIT_COMPLETE_UART1() {
00139   while (!IS_TRANSMIT_COMPLETE_UART1())
00140     doHeartbeat();
00141 }
00142 
00143 void outChar1(uint8 u8_c);
00144 uint8 inChar1(void);
00145 void configUART1(uint32 u32_baudRate);
00146 uint8 isCharReady1(void);
00147 void checkRxErrorUART1(void);  //check for UART RX error
00148 
00149 #endif // #if (NUM_UART_MODS >= 1)
00150 #endif // #ifndef _PIC24_UART1_H_
00151 
00152 
00153 
00154 
00155 
00156 
00157 
00158 
00159 /*
00160  * "Copyright (c) 2008 Robert B. Reese, Bryan A. Jones, J. W. Bruce ("AUTHORS")"
00161  * All rights reserved.
00162  * (R. Reese, reese_AT_ece.msstate.edu, Mississippi State University)
00163  * (B. A. Jones, bjones_AT_ece.msstate.edu, Mississippi State University)
00164  * (J. W. Bruce, jwbruce_AT_ece.msstate.edu, Mississippi State University)
00165  *
00166  * Permission to use, copy, modify, and distribute this software and its
00167  * documentation for any purpose, without fee, and without written agreement is
00168  * hereby granted, provided that the above copyright notice, the following
00169  * two paragraphs and the authors appear in all copies of this software.
00170  *
00171  * IN NO EVENT SHALL THE "AUTHORS" BE LIABLE TO ANY PARTY FOR
00172  * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
00173  * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE "AUTHORS"
00174  * HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00175  *
00176  * THE "AUTHORS" SPECIFICALLY DISCLAIMS ANY WARRANTIES,
00177  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
00178  * AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
00179  * ON AN "AS IS" BASIS, AND THE "AUTHORS" HAS NO OBLIGATION TO
00180  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
00181  *
00182  * Please maintain this header in its entirety when copying/modifying
00183  * these files.
00184  *
00185  *
00186  */
00187 
00188 
00189 #ifndef _PIC24_UART2_H_
00190 #define _PIC24_UART2_H_
00191 
00192 // Only include if this UART module exists.
00193 #if (NUM_UART_MODS >= 2)
00194 
00195 // Documentation for this file. If the \file tag isn't present,
00196 // this file won't be documented.
00197 // Note: place this comment below the #if NUM_UART_MODS so Doxygen
00198 // will only see it once.
00210 #ifndef DEFAULT_BAUDRATE2
00211 #define DEFAULT_BAUDRATE2  DEFAULT_BAUDRATE
00212 #endif
00213 
00217 #ifndef DEFAULT_BRGH2
00218 #define DEFAULT_BRGH2  DEFAULT_BRGH
00219 #endif
00220 
00229 inline static void CONFIG_BAUDRATE_UART2(uint32 baudRate) {
00230 #if (DEFAULT_BRGH2 == 0)
00231   float f_brg = (((float) FCY)/((float) baudRate)/16.0) - 1.0;
00232 #else
00233   float f_brg = (((float) FCY)/((float) baudRate)/4.0) - 1.0;
00234 #endif
00235   ASSERT(f_brg < 65535.5);
00236   U2MODEbits.BRGH = DEFAULT_BRGH2;
00237   U2BRG = roundFloatToUint16(f_brg);
00238 }
00239 
00240 
00245 #define UXMODE_PDSEL_8DATA_NOPARITY   0
00246 #define UXMODE_PDSEL_8DATA_EVENPARITY 1
00247 #define UXMODE_PDSEL_8DATA_ODDPARITY  2
00248 #define UXMODE_PDSEL_9DATA_NOPARITY   3
00250 
00251 
00255 inline static void CONFIG_PDSEL_UART2(uint8 u8_pdsel) {
00256   ASSERT(u8_pdsel <= UXMODE_PDSEL_9DATA_NOPARITY);
00257   U2MODEbits.PDSEL = u8_pdsel;
00258 }
00259 
00264 inline static void CONFIG_STOPBITS_UART2(uint8 u8_numStopbits) {
00265   ASSERT(u8_numStopbits <= 2);
00266   U2MODEbits.STSEL = u8_numStopbits - 1;
00267 }
00268 
00270 inline static void ENABLE_UART2() {
00271   U2MODEbits.UEN = 0b00;                    // UxTX and UxRX pins are enabled and used; no flow control pins
00272   U2MODEbits.UARTEN = 1;                    // enable UART RX/TX
00273   U2STAbits.UTXEN = 1;                      //Enable the transmitter
00274 }
00275 
00280 #define IS_CHAR_READY_UART2() U2STAbits.URXDA
00281 
00286 #define IS_TRANSMIT_BUFFER_FULL_UART2() U2STAbits.UTXBF
00287 
00293 #define IS_TRANSMIT_COMPLETE_UART2() U2STAbits.TRMT
00294 
00296 inline static void WAIT_UNTIL_TRANSMIT_COMPLETE_UART2() {
00297   while (!IS_TRANSMIT_COMPLETE_UART2())
00298     doHeartbeat();
00299 }
00300 
00301 void outChar2(uint8 u8_c);
00302 uint8 inChar2(void);
00303 void configUART2(uint32 u32_baudRate);
00304 uint8 isCharReady2(void);
00305 void checkRxErrorUART2(void);  //check for UART RX error
00306 
00307 #endif // #if (NUM_UART_MODS >= 2)
00308 #endif // #ifndef _PIC24_UART2_H_
00309 
00310 
00311 
00312 
00313 
00314 
00315 
00316 
00317 /*
00318  * "Copyright (c) 2008 Robert B. Reese, Bryan A. Jones, J. W. Bruce ("AUTHORS")"
00319  * All rights reserved.
00320  * (R. Reese, reese_AT_ece.msstate.edu, Mississippi State University)
00321  * (B. A. Jones, bjones_AT_ece.msstate.edu, Mississippi State University)
00322  * (J. W. Bruce, jwbruce_AT_ece.msstate.edu, Mississippi State University)
00323  *
00324  * Permission to use, copy, modify, and distribute this software and its
00325  * documentation for any purpose, without fee, and without written agreement is
00326  * hereby granted, provided that the above copyright notice, the following
00327  * two paragraphs and the authors appear in all copies of this software.
00328  *
00329  * IN NO EVENT SHALL THE "AUTHORS" BE LIABLE TO ANY PARTY FOR
00330  * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
00331  * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE "AUTHORS"
00332  * HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00333  *
00334  * THE "AUTHORS" SPECIFICALLY DISCLAIMS ANY WARRANTIES,
00335  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
00336  * AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
00337  * ON AN "AS IS" BASIS, AND THE "AUTHORS" HAS NO OBLIGATION TO
00338  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
00339  *
00340  * Please maintain this header in its entirety when copying/modifying
00341  * these files.
00342  *
00343  *
00344  */
00345 
00346 
00347 #ifndef _PIC24_UART3_H_
00348 #define _PIC24_UART3_H_
00349 
00350 // Only include if this UART module exists.
00351 #if (NUM_UART_MODS >= 3)
00352 
00353 // Documentation for this file. If the \file tag isn't present,
00354 // this file won't be documented.
00355 // Note: place this comment below the #if NUM_UART_MODS so Doxygen
00356 // will only see it once.
00368 #ifndef DEFAULT_BAUDRATE3
00369 #define DEFAULT_BAUDRATE3  DEFAULT_BAUDRATE
00370 #endif
00371 
00375 #ifndef DEFAULT_BRGH3
00376 #define DEFAULT_BRGH3  DEFAULT_BRGH
00377 #endif
00378 
00387 inline static void CONFIG_BAUDRATE_UART3(uint32 baudRate) {
00388 #if (DEFAULT_BRGH3 == 0)
00389   float f_brg = (((float) FCY)/((float) baudRate)/16.0) - 1.0;
00390 #else
00391   float f_brg = (((float) FCY)/((float) baudRate)/4.0) - 1.0;
00392 #endif
00393   ASSERT(f_brg < 65535.5);
00394   U3MODEbits.BRGH = DEFAULT_BRGH3;
00395   U3BRG = roundFloatToUint16(f_brg);
00396 }
00397 
00398 
00403 #define UXMODE_PDSEL_8DATA_NOPARITY   0
00404 #define UXMODE_PDSEL_8DATA_EVENPARITY 1
00405 #define UXMODE_PDSEL_8DATA_ODDPARITY  2
00406 #define UXMODE_PDSEL_9DATA_NOPARITY   3
00408 
00409 
00413 inline static void CONFIG_PDSEL_UART3(uint8 u8_pdsel) {
00414   ASSERT(u8_pdsel <= UXMODE_PDSEL_9DATA_NOPARITY);
00415   U3MODEbits.PDSEL = u8_pdsel;
00416 }
00417 
00422 inline static void CONFIG_STOPBITS_UART3(uint8 u8_numStopbits) {
00423   ASSERT(u8_numStopbits <= 2);
00424   U3MODEbits.STSEL = u8_numStopbits - 1;
00425 }
00426 
00428 inline static void ENABLE_UART3() {
00429   U3MODEbits.UEN = 0b00;                    // UxTX and UxRX pins are enabled and used; no flow control pins
00430   U3MODEbits.UARTEN = 1;                    // enable UART RX/TX
00431   U3STAbits.UTXEN = 1;                      //Enable the transmitter
00432 }
00433 
00438 #define IS_CHAR_READY_UART3() U3STAbits.URXDA
00439 
00444 #define IS_TRANSMIT_BUFFER_FULL_UART3() U3STAbits.UTXBF
00445 
00451 #define IS_TRANSMIT_COMPLETE_UART3() U3STAbits.TRMT
00452 
00454 inline static void WAIT_UNTIL_TRANSMIT_COMPLETE_UART3() {
00455   while (!IS_TRANSMIT_COMPLETE_UART3())
00456     doHeartbeat();
00457 }
00458 
00459 void outChar3(uint8 u8_c);
00460 uint8 inChar3(void);
00461 void configUART3(uint32 u32_baudRate);
00462 uint8 isCharReady3(void);
00463 void checkRxErrorUART3(void);  //check for UART RX error
00464 
00465 #endif // #if (NUM_UART_MODS >= 3)
00466 #endif // #ifndef _PIC24_UART3_H_
00467 
00468 
00469 
00470 
00471 
00472 
00473 
00474 
00475 /*
00476  * "Copyright (c) 2008 Robert B. Reese, Bryan A. Jones, J. W. Bruce ("AUTHORS")"
00477  * All rights reserved.
00478  * (R. Reese, reese_AT_ece.msstate.edu, Mississippi State University)
00479  * (B. A. Jones, bjones_AT_ece.msstate.edu, Mississippi State University)
00480  * (J. W. Bruce, jwbruce_AT_ece.msstate.edu, Mississippi State University)
00481  *
00482  * Permission to use, copy, modify, and distribute this software and its
00483  * documentation for any purpose, without fee, and without written agreement is
00484  * hereby granted, provided that the above copyright notice, the following
00485  * two paragraphs and the authors appear in all copies of this software.
00486  *
00487  * IN NO EVENT SHALL THE "AUTHORS" BE LIABLE TO ANY PARTY FOR
00488  * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
00489  * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE "AUTHORS"
00490  * HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00491  *
00492  * THE "AUTHORS" SPECIFICALLY DISCLAIMS ANY WARRANTIES,
00493  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
00494  * AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
00495  * ON AN "AS IS" BASIS, AND THE "AUTHORS" HAS NO OBLIGATION TO
00496  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
00497  *
00498  * Please maintain this header in its entirety when copying/modifying
00499  * these files.
00500  *
00501  *
00502  */
00503 
00504 
00505 #ifndef _PIC24_UART4_H_
00506 #define _PIC24_UART4_H_
00507 
00508 // Only include if this UART module exists.
00509 #if (NUM_UART_MODS >= 4)
00510 
00511 // Documentation for this file. If the \file tag isn't present,
00512 // this file won't be documented.
00513 // Note: place this comment below the #if NUM_UART_MODS so Doxygen
00514 // will only see it once.
00526 #ifndef DEFAULT_BAUDRATE4
00527 #define DEFAULT_BAUDRATE4  DEFAULT_BAUDRATE
00528 #endif
00529 
00533 #ifndef DEFAULT_BRGH4
00534 #define DEFAULT_BRGH4  DEFAULT_BRGH
00535 #endif
00536 
00545 inline static void CONFIG_BAUDRATE_UART4(uint32 baudRate) {
00546 #if (DEFAULT_BRGH4 == 0)
00547   float f_brg = (((float) FCY)/((float) baudRate)/16.0) - 1.0;
00548 #else
00549   float f_brg = (((float) FCY)/((float) baudRate)/4.0) - 1.0;
00550 #endif
00551   ASSERT(f_brg < 65535.5);
00552   U4MODEbits.BRGH = DEFAULT_BRGH4;
00553   U4BRG = roundFloatToUint16(f_brg);
00554 }
00555 
00556 
00561 #define UXMODE_PDSEL_8DATA_NOPARITY   0
00562 #define UXMODE_PDSEL_8DATA_EVENPARITY 1
00563 #define UXMODE_PDSEL_8DATA_ODDPARITY  2
00564 #define UXMODE_PDSEL_9DATA_NOPARITY   3
00566 
00567 
00571 inline static void CONFIG_PDSEL_UART4(uint8 u8_pdsel) {
00572   ASSERT(u8_pdsel <= UXMODE_PDSEL_9DATA_NOPARITY);
00573   U4MODEbits.PDSEL = u8_pdsel;
00574 }
00575 
00580 inline static void CONFIG_STOPBITS_UART4(uint8 u8_numStopbits) {
00581   ASSERT(u8_numStopbits <= 2);
00582   U4MODEbits.STSEL = u8_numStopbits - 1;
00583 }
00584 
00586 inline static void ENABLE_UART4() {
00587   U4MODEbits.UEN = 0b00;                    // UxTX and UxRX pins are enabled and used; no flow control pins
00588   U4MODEbits.UARTEN = 1;                    // enable UART RX/TX
00589   U4STAbits.UTXEN = 1;                      //Enable the transmitter
00590 }
00591 
00596 #define IS_CHAR_READY_UART4() U4STAbits.URXDA
00597 
00602 #define IS_TRANSMIT_BUFFER_FULL_UART4() U4STAbits.UTXBF
00603 
00609 #define IS_TRANSMIT_COMPLETE_UART4() U4STAbits.TRMT
00610 
00612 inline static void WAIT_UNTIL_TRANSMIT_COMPLETE_UART4() {
00613   while (!IS_TRANSMIT_COMPLETE_UART4())
00614     doHeartbeat();
00615 }
00616 
00617 void outChar4(uint8 u8_c);
00618 uint8 inChar4(void);
00619 void configUART4(uint32 u32_baudRate);
00620 uint8 isCharReady4(void);
00621 void checkRxErrorUART4(void);  //check for UART RX error
00622 
00623 #endif // #if (NUM_UART_MODS >= 4)
00624 #endif // #ifndef _PIC24_UART4_H_
00625 
00626 
00627 
00628 
00629 
00630 
00631 
00632 

Generated on Mon Oct 18 07:40:47 2010 for Python-on-a-chip by  doxygen 1.5.9