1 /*-------------------------------------------------------------------------
2 usart.h - USART communications module library header
4 Copyright (C) 2005, Vangelis Rokas <vrokas AT otenet.gr>
6 This library is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this library; see the file COPYING. If not, write to the
18 Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
21 As a special exception, if you link this library with other files,
22 some of which are compiled with SDCC, to produce an executable,
23 this library does not by itself cause the resulting executable to
24 be covered by the GNU General Public License. This exception does
25 not however invalidate any other reasons why the executable file
26 might be covered by the GNU General Public License.
27 -------------------------------------------------------------------------*/
35 #define RAM_SCLS __data
37 /* configuration bit masks for open function */
38 #define USART_TX_INT_ON 0xff
39 #define USART_TX_INT_OFF 0x7f
40 #define USART_RX_INT_ON 0xff
41 #define USART_RX_INT_OFF 0xbf
42 #define USART_BRGH_HIGH 0xff
43 #define USART_BRGH_LOW 0xef
44 #define USART_CONT_RX 0xff
45 #define USART_SINGLE_RX 0xf7
46 #define USART_SYNC_MASTER 0xff
47 #define USART_SYNC_SLAVE 0xfb
48 #define USART_NINE_BIT 0xff
49 #define USART_EIGHT_BIT 0xfd
50 #define USART_SYNCH_MODE 0xff
51 #define USART_ASYNCH_MODE 0xfe
56 * --- Families with 1 USART ---
64 * RB1/AN5/TX and RB4/AN6/RX
66 * TRISB<1> = TRISB<4> = 1 (TX, RX)
67 * ADCON1<5> = ADCON1<6> = 1 (PCFG<5>, PCFG<6>)
71 * RB7/TX and RB5/AN11/RX
73 * TRISB<7> = TRISB<5> = 1 (TX, RX)
74 * ANSELH<3> = 0 (ANS11/RX)
84 * 18f2221/18f2331/18f23k20/18f2410/18f2420/18f2423/18f2455/18f24j10/18f2525:
87 * TRISC<6> = TRISC<7> = 1 (TX, RX)
90 * 18f2450/18f2480/18f2585/18f2682/18f6585/18f6680/18f8585/18f8680:
97 * --- Families with 2+ USARTs ---
100 * RCSTA1<7> = 1 (SPEN)
101 * TXSTA1<4> = 0 (SYNC)
102 * TXSTA1<5> = 1 (TXEN)
104 * 18f24j50/18f6527/18f65j50/18f66j60:
105 * RC6/TX1 and RC7/RX1 (EUSART1)
112 * RC6/TX1 and RC7/RX1 (EUSART1)
119 #include "pic18fam.h"
121 #if (__SDCC_USART_STYLE == 0)
122 #warning The target device is not supported by the SDCC PIC16 USART library.
125 #if (__SDCC_USART_STYLE == 1822200) || \
126 (__SDCC_USART_STYLE == 1865200)
127 #define __SDCC_NO_SPBRGH 1
128 #endif /* device lacks SPBRGH */
132 typedef unsigned char sdcc_spbrg_t
;
133 #else /* !__SDCC_NO_SPBRGH */
134 typedef unsigned int sdcc_spbrg_t
;
135 #endif /* !__SDCC_NO_SPBRGH */
146 unsigned FRAME_ERROR
:1;
147 unsigned OVERRUN_ERROR
:1;
152 void usart_open (unsigned char config
, sdcc_spbrg_t spbrg
) __wparam
;
153 void usart_close (void);
155 unsigned char usart_busy (void) __naked
;
156 unsigned char usart_drdy (void) __naked
;
158 unsigned char usart_getc (void);
159 void usart_gets (RAM_SCLS
char * buffer
, unsigned char len
);
161 void usart_putc (unsigned char data
) __wparam __naked
;
162 void usart_puts (char * data
);
165 void usart_baud (sdcc_spbrg_t baudconfig
) __wparam
;