.

QuickBuilder
for Microchip PICs

Home - About- Consulting* - Articles - FAQs - Contact
Tour - Application Example - Sub circuits - Projects - Download
Projects: RF communications - master transponder
This QuickBuilder project can be downloaded here.

RF communications - master transponder

Introduction
This project demonstrates the 'AM RF Transponder' sub-circuit when used as a master. The master transponder operates by sending request data over a radio frequency link to a remote 'AM RF Transponder' which is operating as a slave. If the remote transponder is present it will reply with the requested data. See also project RFXS.QPR.


Operation
When the RS232 port receives a numeric character it is used as the ID of the remote transponder to request data from. A request is transmitted to the remote transponder which, if present, replies with the requested data.

RFX_NOTIFY indicates the arrival of new data which in the case of this project is temperature data from the remote transponder. The data is sent as human readable text out of the RS232 port.


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'.



///////////////////////////////////////////////////////////////////////
////                           ARFXM.C                             ////
////                                                               ////
////  This project demonstrates the 'AM RF Transponder'            ////
////  sub-circuit used as a master. When a character in the range  ////
////  '0' - '9' is received by the RS232 PORT it's used as the ID  ////
////  of the remote transponders. Data is sent to the selected     ////
////  transponder requesting temperature data. When it             ////
////  replies the reading is sent out of the RS232 port            ////
////  as human readable text.                                      ////
////  See also project RFXS.QPR.                                   ////
////                                                               ////
////  This program is an example of how your application code is   ////
////  is organised. Note the #include "rfxm.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 "rfxm.c"




main() {
    char c;
    signed long l;
    
    // initialise
    //------------
    setup_adc(ADC_OFF);
    setup_adc_ports(NO_ANALOGS);
    INIT_SUB_CIRCUITS();
    
    RFX_RON();          // receiver on
    RFX_LOCAL = 15;     // local transponder id
    

    // main loop
    //----------
    while(1) {
    
            
        // wait for numeric character from console
        //
        c = RS232_IN();
        c = c-'0';      
        RFX_REMOTE = c; // remote ID

        // request data
        //
        RFX_TSTART(0x0);        // address
        RFX_TSENDDATA(1);       // data (request reading)
        RFX_TSTOP();

        // wait 0.75 seconds for the response 
        //
        for (l=0 ; l<10000 ; l++) {
            if ( RFX_RINCOMING() )
                RFX_RDO();
            delay_us(50);
            
            }


        // process received data
        //
        if (RFX_RNOTIFY) {
            if ( RFX_RADDR == 1) {
                l = RFX_RDATA[0];
                l |= RFX_RDATA[1]<<8;
                printf(RS232_OUT, 
                    "Remote ID=%d, Temperature=%3ld.%ld\r\n",
                    RFX_REMOTE, (l>>1), (l&1)*5);
                RFX_RNOTIFY = 0;            
            }
        }
    }
}

Copyright 2002-2009 Summit Electronics Ltd
www.quickbuilder.co.uk