RF communications - data transmitter

Introduction
This project demonstrates the 'AM RF Transmitter'
sub-circuit and is intended to be used with project
RFRX.QPR. Sending data over the RF link effects a
simple remote control.
The target device is a PIC16F872. A
smaller target such as the PIC16F84 could be used
if required.
Operation
When the RS232 port receives a numeric character it
is used as the remote receiver ID and initiates a
data transmission. Data is transmitted to the remote
receiver to turn a relay on and then off again (see
project RFRX.QPR). Data is sent several times to ensure
reliable data transfer. This is done since an acknowledgement
is not possible with one-way communications.
The ID of the remote receiver may be
anywhere within the range 0-255.
Application code
Below is the application code for this project. To
use it, select and copy (ctr-insert) the code below,
paste it into a text editor and save it as a 'C' file
in your working directory.
You may also need to change the build
output path using 'Project | Options'.
///////////////////////////////////////////////////////////////////////
//// ARFTX.C ////
//// ////
//// Demonstrates the 'AM RF Transmitter' (RFTX) sub-circuit ////
//// based on the RF Solutions AM-RT4 transmitter module. ////
//// The transmitter can address any receiver with an ID ////
//// in the range 0-255 (see 'AM RF Receiver'). ////
//// When a character in the range '0' - '9' is received by ////
//// the RS232 PORT it's used as the ID of the remote ////
//// receiver. Data is sent to energise or de-energise a ////
//// relay at the remote receiver. ////
//// See also project RFRX.QPR. ////
//// ////
//// This program is an example of how your application code is ////
//// is organised. Note the #include "rftx.c", this include ////
//// file was generated by QuickBuilder and contains all ////
//// dirver code. ////
//// ////
//// This demo is intended for a PIC16F872 ////
//// Compile using CCS 'C' visit www.quickbuilder.co.uk/qb/ccs ////
///////////////////////////////////////////////////////////////////////
#include <16f872.H>
#fuses hs,nowdt,noprotect,put,nowrt,nolvp
#case
#define PORTA 5
#define PORTB 6
#define PORTC 7
#define TRISA 0x85
#define TRISB 0x86
#define TRISC 0x87
#include "rftx.c"
main() {
char c,i;
// initialise
//------------
setup_adc(ADC_OFF);
setup_adc_ports(NO_ANALOGS);
INIT_SUB_CIRCUITS();
// main loop
//----------
while(1) {
// wait for numeric character from console
//
c = RS232_IN();
c = c-'0';
RFTX_REMOTE = c; // set remote ID
// send energise relay command 5 times
//
for (i=0 ; i<5; i++) {
RFTX_START(0x0); // data address
RFTX_SENDDATA(1); // energise relay
RFTX_STOP();
}
// wait 2 secconds
//
delay_ms(2000);
// send de-energise relay 5 times
//
for (i=0 ; i<5; i++) {
RFTX_START(0x0); // data address
RFTX_SENDDATA(0); // de-energise relay
RFTX_STOP();
}
}
}