1,5 → 1,6 |
#include "maindefs.h" |
#include "uart.h" |
#include "xbee.h" |
#include <string.h> |
#include <stdio.h> |
|
59,8 → 60,7 |
unsigned char c; |
if (PIR1bits.RC1IF) { // Check if data receive flag is set |
c = RCREG1; |
|
#ifdef UART1_RECV_BUFFER |
#ifdef UART1_RX_TO_BUFFER |
// Save received data into buffer |
uart_1_data.buffer_in[uart_1_data.buffer_in_write_ind] = c; |
if (uart_1_data.buffer_in_write_ind == MAXUARTBUF - 1) { |
86,12 → 86,12 |
uart_1_data.buffer_in_len_tmp = 0; |
} |
#endif |
#ifdef UART1_RECV_XBEE |
|
#ifdef UART1_RX_TO_XBEE |
XBee_Serial_In(c); |
#endif |
} |
|
if (RCSTAbits.OERR == 1) { |
if (RCSTA1bits.OERR == 1) { |
// We've overrun the USART and must reset |
RCSTA1bits.CREN = 0; // Reset UART1 |
RCSTA1bits.CREN = 1; |
137,7 → 137,7 |
for (i = 0; i < uart_1_data.buffer_out_len; i++) { |
TXREG1 = uart_1_data.buffer_out[i]; |
Nop(); |
while(!PIR1bits.TX1IF); // Wait for byte to be transmitted |
while (!PIR1bits.TX1IF); // Wait for byte to be transmitted |
} |
#else |
va_list args; |
158,10 → 158,9 |
for (i = 0; i < length; i++) { |
TXREG1 = msg[i]; |
Nop(); |
while(!PIR1bits.TX1IF); // Wait for byte to be transmitted |
while (!PIR1bits.TX1IF); // Wait for byte to be transmitted |
} |
#else |
unsigned char i; |
while (TXSTA1bits.TXEN); // Wait for previous message to finish sending |
uart_1_data.buffer_out_len = length; |
uart_1_data.buffer_out_ind = 1; |
173,6 → 172,21 |
#endif |
} |
|
void UART1_WriteC(const unsigned char c) { |
#ifdef _DEBUG |
TXREG1 = c; |
Nop(); |
while (!PIR1bits.TX1IF); |
#else |
while (TXSTA1bits.TXEN); |
uart_1_data.buffer_out_len = 1; |
uart_1_data.buffer_out_ind = 1; |
TXREG1 = c; |
TXSTA1bits.TXEN = 1; |
#endif |
|
} |
|
unsigned char UART1_Buffer_Len() { |
return uart_1_data.buffer_in_len; |
} |