int i,j;
char uart_rd;
char PitTag[17];
unsigned int i=0;
unsigned int j=0;
unsigned char LF=0x0A;
AD1PCFG = 0xFFFF; // Configure all pins as digital I/O
TRISA.B4=0;
LATA.B4=1;
Delay_ms(1500);
LATA.B4=0;
Unlock_IOLOCK();
PPS_Mapping(15, _INPUT,_U1RX); // Map RP15 as Rx1
PPS_Mapping(14, _OUTPUT, _U1TX); // Map RP14 as Tx1
PPS_Mapping(6, _INPUT,_U2RX); // Map RP6 as Rx2
PPS_Mapping(7, _OUTPUT, _U2TX); // Map RP7 as Tx2
Lock_IOLOCK();
UART1_Init(9600);
Delay_ms(200); // Wait for UART module to stabilize
UART2_Init(9600);
Delay_ms(200); // Wait for UART module to stabilize
UART_Set_Active (& UART1_Read, & UART1_Write, & UART1_Data_Ready, & UART1_Tx_Idle); // active UART1
UART1_Write_Text("Hello");
while(1)
{
UART_Set_Active (& UART1_Read, & UART1_Write, & UART1_Data_Ready, & UART1_Tx_Idle); // active UART1
if(UART1_Data_Ready()) // If data is received
{
PitTag = UART1_Read(); // read the received data
//UART1_Write(PitTag);
i++;
}
if(i==16)
{
LATA.B4=1;
Delay_ms(50);
LATA.B4=0;
Delay_ms(50);
LATA.B4=1;
Delay_ms(50);
LATA.B4=0;
Delay_ms(50);
UART_Set_Active (& UART2_Read, & UART2_Write, & UART2_Data_Ready, & UART2_Tx_Idle); // active UART2
do
{
if (UART2_Tx_Idle())
{
UART2_Write(PitTag[j]);
j++;
}
} while (j!=17);
UART2_Write(LF);
i=0;
j=0;
}
}