Development code

I have modified a programa that reads by rf comunication the data sent from the transmitter, showing on the computer screen. I´d like to insert a routine to light a led when the transmitter stops sending. In fact I want light two led cause the transmitter sends in two chanels at the same time. If one of this channels stops sending the corresponding led will have the light on. I´m not being able to to this routine. I think that it must be done with a timer that will read when the transmission stops after a certain time and activate an interrupt to put the corresponding pin high, but I don´t know how to do this. I need some help. This is my code.
/*

  • KeeyLoq
  • Rotina básica para decodificar um sinal
  • PWM do transmissor rfPICK

*/

#include "TimerOne.h" // biblioteca de temporizacao

int ledPin = 13; // LED ligado no pino 13
int rxPin = 11; // RxDATA do receptor Microchip
int rxSample;
int rxEnabled;

/////////////////////////////////////////////////////
#define TE 400 // us
#define OVERSAMPLING 3 // Taxa de sobre-amostragem

#define NBIT 65 // numero de bits a receber -1

unsigned char B[9]; // buffer de recepcao

volatile int RFstate; // estado do receptor
volatile int RFcount; // timer
volatile int Bptr; // indice para o buffer de recepcao
volatile int BitCount; // contador de bits recebidos
volatile int XTMR; // contador (software) de 16 bit

volatile int RFFull; // buffer cheio
volatile int RFBit; // amostra do sinal de RF

static int seq;

#define TRFreset 0
#define TRFSYNC 1
#define TRFUNO 2
#define TRFZERO 3

#define TRUE 1
#define FALSE 0

#define HIGH_TO -10 // Te maximo
#define LOW_TO 10 // Te minimo
#define SHORT_HEAD 20 // minimo Thead aceito 2,7ms
#define LONG_HEAD 45 // maximo Thead aceito 6,2ms
/////////////////////////////////////////////////////

#define LEDCOUNT 3750 // pisca o led a 1 Hz (1/133us/2)

volatile int RFstate_flg;

void setup()
{
RFstate_flg = 0;

pinMode(ledPin, OUTPUT);
pinMode(rxPin, INPUT);

Serial.begin(9600);
Serial.println("Keeylooq...");

InitReceiver();
rxEnabled = 1;

Timer1.initialize(133); // initializa timer1 (133 uSecs - TE/OVERSAMPLING)
Timer1.attachInterrupt(callback); // instala callback() como interrupcao de "timer overflow"
//
Serial.print(" Periodo: ");
Serial.println(Timer1.pwmPeriod, DEC);
//
}

void loop()
{
int i;

if (XTMR > LEDCOUNT-1)
{
XTMR = 0;
digitalWrite(ledPin, !digitalRead(ledPin));
}

if (RFFull == 1)
{
for (i=0; i < 9; i++) //(NBIT+1)/8; i++)
{
Serial.print(B*, HEX);*

  • Serial.print(" ");*

  • }*

  • Serial.print("[");*

  • Serial.print(seq++, DEC);*

  • Serial.println("]");*

  • RFFull = 0;*

  • }*
    }
    void callback()
    {

  • rxSample = digitalRead(rxPin); // amostra do pino de entrada (RF)!!!*

  • XTMR++;*

  • if (rxEnabled == 1)*

  • rx_isr(); *
    }
    void rx_isr()
    {

  • // esta rotina eh executada toda vez que o Timer1 interrompe*

  • RFBit = rxSample; *

  • if (RFFull == 1) // buffer cheio !*

  • return;*

  • switch( RFstate) // ponto de entrada da maquina de estado*

  • {*

  • case TRFUNO:*

  • if ( RFBit == 0)*

  • { // transicao negativa detectada ----+*

  • // |*

  • // +----*

  • RFstate= TRFZERO;*

  • RFstate_flg |=1;*

  • }*

  • else*

  • { // enquanto nivel-alto*

  • RFcount--;*

  • if ( RFcount < HIGH_TO)*

  • {*

  • RFstate = TRFreset; // reset se demorar muito*

  • RFstate_flg |=1;*

  • }*

  • }*

  • break;*

  • case TRFZERO:*

  • if ( RFBit == 1)*

  • { // transicao positiva detectada +----*

  • // |*

  • // ----+*

  • RFstate= TRFUNO;*

  • RFstate_flg |=8;*

  • B[Bptr] >>= 1; // desloca o byte para direita*

  • if ( RFcount >= 0)*

  • {*

  • B[Bptr]+=0x80; // insere um novo bit na posicao 7*

  • }*

  • RFcount = 0; // reseta o contador de tamanho*

  • if ( ( ++BitCount & 7) == 0)*

  • Bptr++; // proximo byte*

  • if (BitCount == NBIT)*

  • {*

  • RFstate = TRFreset; // fim da recepcao*

  • RFstate_flg |=1;*

  • RFFull = TRUE;*

  • } *

  • }*

  • else*

  • { // ainda nivel-baixo*

  • RFcount++;*

  • if ( RFcount >= LOW_TO) // nivel-baixo muito longo*

  • {*

  • RFstate = TRFSYNC; // volta para o estado de sincronismo...*

  • Bptr = 0; // reseta ponteiro, mas continua contando...*

  • BitCount = 0;*

  • RFstate_flg |=2; *

  • }*

  • }*

  • break;*

  • case TRFSYNC:*

  • if ( RFBit == 1)*

  • { // transicao positiva detectada +---+ +---..*

  • // | | <-Theader-> | *

  • // +----------------+*

  • if ( ( RFcount < SHORT_HEAD) || ( RFcount >= LONG_HEAD))*

  • {*

  • RFstate = TRFreset;*

  • RFstate_flg |=1;*

  • break; // muito curto/longo -- header invalido*

  • }*

  • else*

  • {*

  • RFcount =0; // reinicializa contador*

  • RFstate= TRFUNO;*

  • RFstate_flg |=4;*

  • }*

  • }*

  • else*

  • { // ainda nivel-baixo*

  • RFcount++;*

  • }*

  • break;*

  • case TRFreset:*

  • default:*

  • RFstate = TRFSYNC; // reinicializa a maquina de estado*

  • RFstate_flg |=1;*

  • RFcount = 0;*

  • Bptr = 0;*

  • BitCount = 0;*

  • break;*

  • } // switch*

} // rx_isr
void InitReceiver()
{

  • RFstate = TRFreset; // inicializa a maquina de estado*

  • RFstate_flg |=1;*

  • RFFull = 0; // inicia com o buffer vazio*

  • XTMR = 0; // inicia o timer por software*
    *} *

Please do not post great big long reams of code. There is a CODE button right above where you type your text when making a post. Click that, then past your code inbetween the inserted tags. That way we don't have to scroll down pages and pages to read your post. Thanks.