-
Notifications
You must be signed in to change notification settings - Fork 0
/
usart.h
119 lines (98 loc) · 3.47 KB
/
usart.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/*----------------------------------------------------------------------------
Copyright: Radig Ulrich mailto: mail@ulrichradig.de
Author: Radig Ulrich
Remarks:
known Problems: none
Version: 24.10.2007
Description: RS232 Routinen
Dieses Programm ist freie Software. Sie können es unter den Bedingungen der
GNU General Public License, wie von der Free Software Foundation veröffentlicht,
weitergeben und/oder modifizieren, entweder gemäß Version 2 der Lizenz oder
(nach Ihrer Option) jeder späteren Version.
Die Veröffentlichung dieses Programms erfolgt in der Hoffnung,
daß es Ihnen von Nutzen sein wird, aber OHNE IRGENDEINE GARANTIE,
sogar ohne die implizite Garantie der MARKTREIFE oder der VERWENDBARKEIT
FÜR EINEN BESTIMMTEN ZWECK. Details finden Sie in der GNU General Public License.
Sie sollten eine Kopie der GNU General Public License zusammen mit diesem
Programm erhalten haben.
Falls nicht, schreiben Sie an die Free Software Foundation,
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
------------------------------------------------------------------------------*/
#ifndef _UART_H
#define _UART_H
#include "config.h"
#define USART_ECHO 1
#define BUFFER_SIZE 50
volatile unsigned int buffercounter;
char usart_rx_buffer[BUFFER_SIZE];
char *rx_buffer_pointer_in;
char *rx_buffer_pointer_out;
struct {
volatile unsigned char usart_ready:1;
volatile unsigned char usart_rx_ovl:1;
volatile unsigned char usart_disable:1; //benötigt für ftp2com
}usart_status ;
//----------------------------------------------------------------------------
#include <avr/interrupt.h>
#include <avr/pgmspace.h>
#include <stdlib.h>
#include <stdarg.h>
#include <ctype.h>
#include <string.h>
#include <avr/io.h>
#include "stack.h"
//----------------------------------------------------------------------------
//Die Quarzfrequenz auf dem Board (in config.h)
/*
#ifndef SYSCLK
#define SYSCLK 16000000UL
#endif //SYSCLK
*/
//Anpassen der seriellen Schnittstellen Register wenn ein ATMega128 benutzt wird
#if defined (__AVR_ATmega128__)
#define USR UCSR0A
#define UCR UCSR0B
#define UDR UDR0
#define UBRR UBRR0L
#define USART_RX USART0_RX_vect
#endif
#if defined (__AVR_ATmega644__) || defined (__AVR_ATmega644P__)
#define USR UCSR0A
#define UCR UCSR0B
#define UBRR UBRR0L
#define EICR EICRB
#define TXEN TXEN0
#define RXEN RXEN0
#define RXCIE RXCIE0
#define UDR UDR0
#define UDRE UDRE0
#define USART_RX USART0_RX_vect
#endif
#if defined (__AVR_ATmega32__)
#define USR UCSRA
#define UCR UCSRB
#define UBRR UBRRL
#define EICR EICRB
#define USART_RX USART_RXC_vect
#endif
#if defined (__AVR_ATmega8__)
#define USR UCSRA
#define UCR UCSRB
#define UBRR UBRRL
#endif
#if defined (__AVR_ATmega88__)
#define USR UCSR0A
#define UCR UCSR0B
#define UBRR UBRR0L
#define TXEN TXEN0
#define UDR UDR0
#define UDRE UDRE0
#endif
//----------------------------------------------------------------------------
void usart_init(unsigned long baudrate);
void usart_write_char(char c);
void usart_write_str(char *str);
void usart_write_P (const char *Buffer,...);
#define usart_write(format, args...) usart_write_P(PSTR(format) , ## args)
//----------------------------------------------------------------------------
#endif //_UART_H