The Software
There are two firmware files that this tutorial uses:
-RF Transmitter Firmware
-RF Receiver Firmware
The firmware for this tutorial is split into two parts, one for the receiver PIC and one for the transmitter. They are short and to the point; the transmitter is constantly transmitting depending on the button currently pressed and the receiver is constantly receiving and decoding the command.
RF Transmitter Firmware
The code above shows you the output routine from the RF transmitter PIC. Depending on the status of PORTD Pin 0 or 1 (RD0/RD1) a different set of commands will be output by the USART module in the PIC to the rf 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.
RF Receiver Firmware
The two pieces of code above are firmware from the rf 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.
There are two firmware files that this tutorial uses:
-RF Transmitter Firmware
-RF Receiver Firmware
The firmware for this tutorial is split into two parts, one for the receiver PIC and one for the transmitter. They are short and to the point; the transmitter is constantly transmitting depending on the button currently pressed and the receiver is constantly receiving and decoding the command.
RF Transmitter Firmware
------------« Begin Code »------------
//********Button/Command Output Control************ //************************************************* //If No Button Pressed, Send Command L0 if(PORTDbits.RD0 == 1 && PORTDbits.RD1 == 1){ //Turn LED ON putcUSART( '0' ); //write value of PORTD Delay10KTCYx(10); putcUSART( 'L' ); //write value of PORTD Delay10KTCYx(10); } //If Button #1 Is Pressed, Send Command L1 else if(PORTDbits.RD0 == 0 && PORTDbits.RD1 == 1){ //Turn LED OFF putcUSART( '1' ); //write value of PORTD Delay10KTCYx(10); putcUSART( 'L' ); //write value of PORTD Delay10KTCYx(10); } //If Button #2 Is Pressed, Send Command L2 else if(PORTDbits.RD0 == 1 && PORTDbits.RD1 == 0){ //Turn LED OFF putcUSART( '2' ); //write value of PORTD Delay10KTCYx(10); putcUSART( 'L' ); //write value of PORTD Delay10KTCYx(10); } //*************************************************
------------« End Code »------------
The code above shows you the output routine from the RF transmitter PIC. Depending on the status of PORTD Pin 0 or 1 (RD0/RD1) a different set of commands will be output by the USART module in the PIC to the rf 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.
RF 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 rf 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.