Rev 112 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 112 | Rev 114 | ||
---|---|---|---|
1 | 1 | ||
2 | #include <avr/io.h> |
2 | #include <avr/io.h> |
3 | #include <inttypes.h> |
3 | #include <inttypes.h> |
4 | #include <stdlib.h> |
4 | #include <stdlib.h> |
5 | #include <avr/interrupt.h> |
5 | #include <avr/interrupt.h> |
6 | #include "main.h" |
6 | #include "main.h" |
7 | #include "rs232.h" |
7 | #include "rs232.h" |
8 | 8 | ||
9 | volatile uint8_t read_index, write_index; |
9 | volatile uint8_t read_index, write_index; |
10 | volatile uint8_t rs232_buffer[16]; |
10 | volatile uint8_t rs232_buffer[16]; |
11 | 11 | ||
12 | ISR(USART_RXC_vect) |
12 | ISR(USART_RXC_vect) |
13 | { |
13 | { |
14 | rs232_buffer[write_index++] = UDR; |
14 | rs232_buffer[write_index++] = UDR; |
15 | write_index &= 15; |
15 | write_index &= 15; |
16 | } |
16 | } |
17 | 17 | ||
18 | void RS232_init (void) |
18 | void RS232_init (void) |
19 | { |
19 | { |
20 | UCSRB = (1<<RXEN)|(1<<TXEN)|(1<<RXCIE); |
20 | UCSRB = (1<<RXEN)|(1<<TXEN)|(1<<RXCIE); |
21 | // UBRRL = 7; // 57600 Baud @ 7,372800 MHz |
21 | // UBRRL = 7; // 57600 Baud @ 7,372800 MHz |
22 | UBRR = 7; // 57600 Baud @ 7,372800 MHz |
22 | // UBRR = 7; // 57600 Baud @ 7,372800 MHz |
- | 23 | ||
- | 24 | UBRR=(F_CPU / (BAUD_RATE * 16L) - 1); |
|
23 | } |
25 | } |
24 | 26 | ||
25 | uint8_t RS232_get (void) |
27 | uint8_t RS232_get (void) |
26 | { |
28 | { |
27 | uint8_t c; |
29 | uint8_t c; |
28 | 30 | ||
29 | rs232_timer = 10; |
31 | rs232_timer = 10; |
30 | 32 | ||
31 | while ((read_index == write_index) && (rs232_timer > 0)); |
33 | while ((read_index == write_index) && (rs232_timer > 0)); |
32 | if (rs232_timer != 0) |
34 | if (rs232_timer != 0) |
33 | { |
35 | { |
34 | c = rs232_buffer[read_index++]; |
36 | c = rs232_buffer[read_index++]; |
35 | read_index &= 15; |
37 | read_index &= 15; |
36 | } |
38 | } |
37 | else |
39 | else |
38 | { |
40 | { |
39 | c=0; |
41 | c=0; |
40 | } |
42 | } |
41 | return c; |
43 | return c; |
42 | } |
44 | } |
43 | void RS232_send (uint8_t data) |
45 | void RS232_send (uint8_t data) |
44 | { |
46 | { |
45 | // while ((UCSRA & (1<<UDRE)) == 0); |
47 | // while ((UCSRA & (1<<UDRE)) == 0); |
46 | while ((USR & (1<<UDRE)) == 0); |
48 | while ((USR & (1<<UDRE)) == 0); |
47 | UDR = data; |
49 | UDR = data; |
48 | } |
50 | } |
49 | void RS232_text (uint8_t *text) |
51 | void RS232_text (uint8_t *text) |
50 | { |
52 | { |
51 | while (*text) |
53 | while (*text) |
52 | { |
54 | { |
53 | RS232_send(*text); |
55 | RS232_send(*text); |
54 | text++; |
56 | text++; |
55 | } |
57 | } |
56 | } |
58 | } |
57 | 59 | ||
58 | 60 | ||
59 | 61 |