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.
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;
60 if(config&0x40)PIE1bits.RCIE = 1;
61 else PIE1bits.RCIE = 0;
66 if(config&0x80)PIE1bits.TXIE = 1;
67 else PIE1bits.TXIE = 0;