0,0 → 1,58 |
|
#include <avr/io.h> |
#include <inttypes.h> |
#include <stdlib.h> |
#include <avr/interrupt.h> |
#include "main.h" |
#include "rs232.h" |
|
volatile uint8_t read_index, write_index; |
volatile uint8_t rs232_buffer[16]; |
|
ISR(USART_RXC_vect) |
{ |
rs232_buffer[write_index++] = UDR; |
write_index &= 15; |
} |
|
void RS232_init (void) |
{ |
UCSRB = (1<<RXEN)|(1<<TXEN)|(1<<RXCIE); |
// UBRRL = 7; // 57600 Baud @ 7,372800 MHz |
UBRR = 7; // 57600 Baud @ 7,372800 MHz |
} |
|
uint8_t RS232_get (void) |
{ |
uint8_t c; |
|
rs232_timer = 10; |
|
while ((read_index == write_index) && (rs232_timer > 0)); |
if (rs232_timer != 0) |
{ |
c = rs232_buffer[read_index++]; |
read_index &= 15; |
} |
else |
{ |
c=0; |
} |
return c; |
} |
void RS232_send (uint8_t data) |
{ |
// while ((UCSRA & (1<<UDRE)) == 0); |
while ((USR & (1<<UDRE)) == 0); |
UDR = data; |
} |
void RS232_text (uint8_t *text) |
{ |
while (*text) |
{ |
RS232_send(*text); |
text++; |
} |
} |
|
|