Subversion Repositories Code-Repo

Compare Revisions

Ignore whitespace Rev 125 → Rev 126

/PIC Stuff/PIC_27J13/uart.c/uart.c
1,6 → 1,7
#include "maindefs.h"
#include "uart.h"
#include <string.h>
#include <stdio.h>
 
static UART_DATA uart_1_data;
 
59,6 → 60,7
if (PIR1bits.RC1IF) { // Check if data receive flag is set
c = RCREG1;
 
#ifdef UART1_RECV_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) {
83,6 → 85,10
uart_1_data.buffer_in_len = uart_1_data.buffer_in_len_tmp;
uart_1_data.buffer_in_len_tmp = 0;
}
#endif
#ifdef UART1_RECV_XBEE
 
#endif
}
 
if (RCSTAbits.OERR == 1) {
120,7 → 126,21
}
 
void UART1_WriteS(const rom char *fmt, ...) {
#ifdef _DEBUG
unsigned char i;
va_list args;
va_start(args, fmt);
vsprintf((char *) uart_1_data.buffer_out, fmt, args);
va_end(args);
uart_1_data.buffer_out_len = strlen((char *) uart_1_data.buffer_out);
uart_1_data.buffer_out_ind = 1;
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
}
#else
va_list args;
while (TXSTA1bits.TXEN); // Wait for previous message to finish sending
va_start(args, fmt);
vsprintf((char *) uart_1_data.buffer_out, fmt, args);
129,10 → 149,19
uart_1_data.buffer_out_ind = 1;
TXREG1 = uart_1_data.buffer_out[0]; // Put first byte in TSR
TXSTA1bits.TXEN = 1; // Begin transmission
#endif
}
 
void UART1_WriteB(const char *msg, unsigned char length) {
unsigned char i;
#ifdef _DEBUG
for (i = 0; i < length; i++) {
TXREG1 = msg[i];
Nop();
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;
141,6 → 170,7
}
TXREG1 = uart_1_data.buffer_out[0]; // Put first byte in TSR
TXSTA1bits.TXEN = 1; // Begin transmission
#endif
}
 
unsigned char UART1_Buffer_Len() {