uart.h

Ir a la documentación de este archivo.
00001 #ifndef __UART_H__
00002 #define __UART_H__
00003 
00004 /*
00005   This code is free software; you can redistribute it and/or modify
00006    it under the terms of the GNU General Public License as published by
00007    the Free Software Foundation; either version 2, or (at your option)
00008    any later version.
00009    
00010    This code is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013    GNU General Public License for more details.
00014 */
00015 
00028 /* Modificaciones:
00029         6-06-2008       [Pedro José Ramírez Gutiérrez] Añadida función macro para colocar el bitrate.
00030 */
00031 
00032 #include <tipos.h>
00033 
00038 #ifndef FOSC_HZ
00039         #warning "FOSC_HZ macro must be defined to PIC frecuency (in hz)."
00040         #warning "Get default value of 20000000"
00041         #define   FOSC_HZ 20000000
00042 #endif 
00043 
00044 #define uart_set_baudrate(x) {SPBRG=(BYTE)((x>=9600L)?((FOSC_HZ-8L*x)/(16L*x)):((FOSC_HZ-32L*x)/(64L*x)));\
00045                               TXSTA=(BYTE)((x>=9600L)?(TXSTA|(1<<TXSTA_BRGH)):(TXSTA&(~(1<<TXSTA_BRGH))));};
00046 
00047 #define  HIGH_SPEED (1<<TXSTA_BRGH)
00048 #define   LOW_SPEED  0
00049 
00050 #define   SET_1200_8N1    ((FOSC_HZ-32*1200L)/(64*1200L)),LOW_SPEED
00051 #define   SET_2400_8N1    ((FOSC_HZ-32*2400L)/(64*2400L)),LOW_SPEED
00052 #define   SET_4800_8N1    ((FOSC_HZ-32*4800L)/(64*4800L)),LOW_SPEED
00053 #define   SET_9600_8N1     ((FOSC_HZ-8*9600L)/(16*9600L)),HIGH_SPEED
00054 #define  SET_19200_8N1   ((FOSC_HZ-8*19200L)/(16*19200L)),HIGH_SPEED
00055 #define  SET_38400_8N1   ((FOSC_HZ-8*38400L)/(16*38400L)),HIGH_SPEED
00056 #define  SET_57600_8N1   ((FOSC_HZ-8*57600L)/(16*57600L)),HIGH_SPEED
00057 #define SET_115200_8N1 ((FOSC_HZ-8*115200L)/(16*115200L)),HIGH_SPEED
00058 
00068 void uart_open( BYTE STATUS_SPBRG, BYTE STATUS_SPEED);
00069 
00078 BYTE uart_kbhit(void);
00079 
00088 char uart_getc(void);
00089 
00099 void uart_putc(char dato);
00100 
00110 void uart_puts(char *datos);
00111 
00119 void uart_close(void);
00120 
00121 #endif 
00122 

Generado el Thu Jan 8 00:55:37 2009 para pic-gcc-library por  doxygen 1.5.1