#include <18F26K22.h>

#FUSES     NOWDT
#FUSES     XT
#FUSES     PUT
#FUSES     NOPROTECT
#FUSES     NODEBUG
#FUSES     NOBROWNOUT
#FUSES     NOLVP
#FUSES     NOCPD
#FUSES     NOWRT
#use delay(clock=4000000)

#include "lib_rf2gh4_10_PIC18F26K22.h"

#byte porta=0x05           // Dirección del puerto A.

#int_ext                   // Interrupción del módulo RF.

void int_RB2()
{
   int8 ret1;

   ret1 = RF_RECEIVE();
   if ( (ret1 == 0) || (ret1 == 1) ) // Tanto si hay recepción simple o múltiple, leer datos.
   {
      do
      {   
         porta=RF_DATA[0];           // El puerto A contendrá el valor que le llegue del emisor, a través de RF_DATA[0].
         ret1 = RF_RECEIVE();        // "ret1" nos dirá si hay recepción simple, múltiple o no hay datos para leer.
      } while ( (ret1 == 0) || (ret1 == 1) ); // Mientras haya datos para leer, seguir leyendo.
   } 
}

void main()                  // Programa principal.
{
   port_b_pullups(FALSE);         // Todo digital... etc.
   setup_adc_ports(NO_ANALOGS);
   setup_adc(ADC_CLOCK_DIV_2);
   setup_spi(SPI_SS_DISABLED);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);
  
   set_tris_a(0b000000);     // Todo el puerto A como salida.
   porta=0;                  // Inicialmente lo ponemos a cero.
  
   RF_INT_EN();              // Habilitar interrupción RB0/INT.
   RF_CONFIG_SPI();          // Configurar módulos SPI del PIC.
   RF_CONFIG(0x40,0x08);     // Configurar módulo RF (canal y dirección).
   RF_ON();                  // Activar el módulo RF.
  
   while(true);              // Bucle infinito.            
      
}