3 * uopen - initialize USART module
5 * written by Vangelis Rokas, 2004 <vrokas AT otenet.gr>
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Library General Public License
13 * as published by the Free Software Foundation; either version 2
14 * of the License, or (at your option) any later version.
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26 * $Id: uopen.c 5195 2008-06-21 21:36:29Z tecodev $
30 #include <pic18fregs.h>
34 // USART Status Structure
35 extern union USART USART_Status;
37 void usart_open(unsigned char config, unsigned int spbrg) __wparam
39 TXSTA = 0; // Reset USART registers to POR state
42 if(config&0x01)TXSTAbits.SYNC = 1;
49 if(config&0x04)TXSTAbits.CSRC = 1;
51 if(config&0x08)RCSTAbits.CREN = 1;
52 else RCSTAbits.SREN = 1;
54 if(config&0x10)TXSTAbits.BRGH = 1;
55 else TXSTAbits.BRGH = 0;
58 #if defined(pic18f66j60) || defined(pic18f66j65) || \
59 defined(pic18f67j60) || defined(pic18f86j60) || \
60 defined(pic18f86j65) || defined(pic18f87j60) || \
61 defined(pic18f96j60) || defined(pic18f96j65) || \
64 PIR1bits.TXIF_PIR1 = 0;
66 #else /* all other devices */
72 if(config&0x40)PIE1bits.RCIE = 1;
73 else PIE1bits.RCIE = 0;
78 #if defined(pic18f66j60) || defined(pic18f66j65) || \
79 defined(pic18f67j60) || defined(pic18f86j60) || \
80 defined(pic18f86j65) || defined(pic18f87j60) || \
81 defined(pic18f96j60) || defined(pic18f96j65) || \
84 if(config&0x80)PIE1bits.TXIE_PIE1 = 1;
85 else PIE1bits.TXIE_PIE1 = 0;
87 #else /* all other devices */
89 if(config&0x80)PIE1bits.TXIE = 1;
90 else PIE1bits.TXIE = 0;