usart.h 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*----------------------------------------------------------------------------
  2. Copyright: Radig Ulrich mailto: mail@ulrichradig.de
  3. Author: Radig Ulrich
  4. Remarks:
  5. known Problems: none
  6. Version: 24.10.2007
  7. Description: RS232 Routinen
  8. Dieses Programm ist freie Software. Sie können es unter den Bedingungen der
  9. GNU General Public License, wie von der Free Software Foundation veröffentlicht,
  10. weitergeben und/oder modifizieren, entweder gemäß Version 2 der Lizenz oder
  11. (nach Ihrer Option) jeder späteren Version.
  12. Die Veröffentlichung dieses Programms erfolgt in der Hoffnung,
  13. daß es Ihnen von Nutzen sein wird, aber OHNE IRGENDEINE GARANTIE,
  14. sogar ohne die implizite Garantie der MARKTREIFE oder der VERWENDBARKEIT
  15. FÜR EINEN BESTIMMTEN ZWECK. Details finden Sie in der GNU General Public License.
  16. Sie sollten eine Kopie der GNU General Public License zusammen mit diesem
  17. Programm erhalten haben.
  18. Falls nicht, schreiben Sie an die Free Software Foundation,
  19. Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
  20. ------------------------------------------------------------------------------*/
  21. #ifndef _UART_H
  22. #define _UART_H
  23. //----------------------------------------------------------------------------
  24. #include <stdlib.h>
  25. #include <stdarg.h>
  26. #include <ctype.h>
  27. #include <string.h>
  28. #include <avr/io.h>
  29. #include <avr/pgmspace.h>
  30. //----------------------------------------------------------------------------
  31. //Die Quarzfrequenz auf dem Board
  32. #ifndef F_CPU
  33. #define F_CPU 14745600UL
  34. #endif //SYSCLK
  35. //Anpassen der seriellen Schnittstellen Register wenn ein ATMega128 benutzt wird
  36. #if defined (__AVR_ATmega128__)
  37. #define USR UCSR0A
  38. #define UCR UCSR0B
  39. #define UDR UDR0
  40. #define UBRR UBRR0L
  41. #define USART_RX USART0_RX_vect
  42. #endif
  43. #if defined (__AVR_ATmega644__) || defined (__AVR_ATmega644P__)
  44. #define USR UCSR0A
  45. #define UCR UCSR0B
  46. #define UBRR UBRR0L
  47. #define EICR EICRB
  48. #define TXEN TXEN0
  49. #define RXEN RXEN0
  50. #define RXCIE RXCIE0
  51. #define UDR UDR0
  52. #define UDRE UDRE0
  53. #define USART_RX USART0_RX_vect
  54. #endif
  55. #if defined (__AVR_ATmega32__)
  56. #define USR UCSRA
  57. #define UCR UCSRB
  58. #define UBRR UBRRL
  59. #define EICR EICRB
  60. #define USART_RX USART_RXC_vect
  61. #endif
  62. #if defined (__AVR_ATmega8__)
  63. #define USR UCSRA
  64. #define UCR UCSRB
  65. #define UBRR UBRRL
  66. #endif
  67. #if defined (__AVR_ATmega88__)
  68. #define USR UCSR0A
  69. #define UCR UCSR0B
  70. #define UBRR UBRR0L
  71. #define TXEN TXEN0
  72. #define UDR UDR0
  73. #define UDRE UDRE0
  74. #endif
  75. //----------------------------------------------------------------------------
  76. void usart_init(unsigned long baudrate);
  77. void usart_write_char(char c);
  78. void usart_write_str(char *str);
  79. void usart_write_P (const char *Buffer,...);
  80. #define usart_write(format, args...) usart_write_P(PSTR(format) , ## args)
  81. //----------------------------------------------------------------------------
  82. #endif //_UART_H