Xbee Wireless Interface

Program Download:
Transmitter: Main C File
PIC_Xbee_Tx.c

Receiver: Main C File
PIC_Xbee_Rx.c
The Software
           There are two main programs that we are concerned with:

    [1] PIC Transmitter Firmware
    [2] PIC Receiver Firmware


The PIC firmware used for the transmitter and receiver is similar to a basic input out program a beginner might right. There is no reason to write something overly complicated for this tutorial since we are just demonstrating how the Xbee modules work and how to make a functional Xbee wireless interface. The transmitter looks for one or two button presses and then outputs the corresonding serial data to flash the transmitter LED.

Transmitter Firmwware

------------« Begin Code »------------
//********Button/Command Output Control************
//*************************************************
//If No Button Pressed, Send Command L0
if(PORTAbits.RA0 == 1 &&
PORTAbits.RA1 == 1){
     //Turn LED ON
     putcUSART( '0' ); //write value of PORTA
     Delay10KTCYx(10);
     putcUSART( 'L' ); //write value of PORTA
     Delay10KTCYx(10);
}
//If Button #1 Is Pressed, Send Command L1
else if(PORTAbits.RA0 == 0 &&
PORTAbits.RA1 == 1){
     //Turn LED OFF
     putcUSART( '1' ); //write value of PORTA
     Delay10KTCYx(10);
     putcUSART( 'L' ); //write value of PORTA
     Delay10KTCYx(10);
}
//If Button #2 Is Pressed, Send Command L2
else if(PORTAbits.RA0 == 1 &&
PORTAbits.RA1 == 0){
     //Turn LED OFF
     putcUSART( '2' ); //write value of PORTA
     Delay10KTCYx(10);
     putcUSART( 'L' ); //write value of PORTA
     Delay10KTCYx(10);
}
//*************************************************
------------« End Code »------------

           The code above shows you the output routine from the Xbee transmitter PIC. Depending on the status of PORTA Pin 0 or 1 (RA0/RA1) a different set of commands will be output by the USART module in the PIC to the Xbee module. One command turns PORTA off, the other two set a particular bit in PORTA turning one of the LEDs on. This routine is continuously sending data.

Receiver Firmware

------------« Begin Code »------------
//******** Button/LED Control *********
if(data_array[1] == 'L' &&
     data_array[2] == '0')
     PORTA= 0x00;
//**** Button 1 Pressed - LED #1 On ****
else if(data_array[1] == 'L' &&
     data_array[2] == '1')
     PORTA= 0x01;
//**** Button 2 Pressed - LED #2 On ****
else if(data_array[1] == 'L' &&
     data_array[2] == '2')
     PORTA= 0x02;
//*****************************************
...
....
...
//Interrupt Evaluation Routine
if(PIR1bits.RCIF){
     buf = ReadUSART();
     data_array[7] = data_array[6];
     data_array[6] = data_array[5];
     data_array[5] = data_array[4];
     data_array[4] = data_array[3];
     data_array[3] = data_array[2];
     data_array[2] = data_array[1];
     data_array[1] = data_array[0];
     data_array[0] = buf;
     PIR1bits.RCIF = 0; //Clear RCIF Flag
}
------------« End Code »------------
           The two pieces of code above are firmware from the PIC Xbee receiver portion of this tutorial. The first portion shows you how the incoming commands are evaluated. Just as the commands are sent: L0, L1 or L2, they are received the same. The second part of the code is capturing the incoming data from the USART. An interrupt routine is used, and everytime the flag RCIF is set, we tell the PIC to shift the new element in the data array.



;