RC5 de philips decodificación y control

hola Moyano, me parecio genial ver tu proyecto funcionando ya que realmente es mi sueño hacerlo tambien. ultimamente me e estado documentando sobre el protocolo RC5 y luego de leer y probarlo realmente comprendi como funciona. Ahora quiero seguir tus pasos, y decodificar , el problema es que trabajo con un microcontrolador motorola GP32 y no se como empezar. Necesito ayuda, aun sigo analizando el codigo para PIC, pero no soy muy bueno con las interrupciones, porfavor ayuda. Gracias por la inspiracion.
 
Decime exactamente que micro estás usando por que el codewarrior tiene diferentes IDE según el procesador utilizado. Ahora tenés que investigar nomás no es muy complejo el código....buscate algún manual sencillo de las instrucciones del codewarrior y sus librerías para ver como funciona y luego empezá a crear el programa.

Yo también lo estoy portando para AVR mediante WinAVR y te digo que se me ha complicado un poco por los tiempos exactos que se requieren...pero investigando a fondo todo se puede.

Saludos !
 
Cordial saludo,
en mi caso en particular, deseo hacer un control para controlar el radio del auto, se que se puede comprar pero deseo hacerlo con un pic, podrias decirme como enfocar el proyecto? pues tengo estas dudas.
Cada marca parece llevar un codigo diferente, ademas quisiera saber si hay alguna aplicacion que se instale en el pc, y poder observar el efecto o el valor binario o hex de cada tecla y asi hacer una base de datos.
gracias..
 
Hola johenrod, como estás.

Interesante proyecto, mirá mi librería no contempla la decodificación de cualquier protocolo. Tengo una librería para Arduino o AVR - C++..que quizás las puedas portar a lenguaje C para PIC.
Si elejís usar un control RC5..tipo PHILIPS....podés usar mi librería.

Cada marca parece llevar un codigo diferente, ademas quisiera saber si hay alguna aplicacion que se instale en el pc, y poder observar el efecto o el valor binario o hex de cada tecla y asi hacer una base de datos.
gracias..

Yo uso el hyperterminal para ver los datos...y los datos los guardo en una hoja de datos de excel.

Te dejo el código de C++ para ver que podés hacer...con el mismo podés decodificar cualquier código por que es universal.

Código:
/*
 * IRremote
 * Version 0.11 August, 2009
 * Copyright 2009 Ken Shirriff
 * For details, see http://arcfn.com/2009/08/multi-protocol-infrared-remote-library.html
 *
 * Interrupt code based on NECIRrcv by Joe Knapp
 * http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1210243556
 * Also influenced by http://zovirl.com/2008/11/12/building-a-universal-remote-with-an-arduino/
 */

#include "IRremote.h"
#include "IRremoteInt.h"

// Provides ISR
#include <avr/interrupt.h>

volatile irparams_t irparams;

// These versions of MATCH, MATCH_MARK, and MATCH_SPACE are only for debugging.
// To use them, set DEBUG in IRremoteInt.h
// Normally macros are used for efficiency
#ifdef DEBUG
int MATCH(int measured, int desired) {
  Serial.print("Testing: ");
  Serial.print(TICKS_LOW(desired), DEC);
  Serial.print(" <= ");
  Serial.print(measured, DEC);
  Serial.print(" <= ");
  Serial.println(TICKS_HIGH(desired), DEC);
  return measured >= TICKS_LOW(desired) && measured <= TICKS_HIGH(desired);
}

int MATCH_MARK(int measured_ticks, int desired_us) {
  Serial.print("Testing mark ");
  Serial.print(measured_ticks * USECPERTICK, DEC);
  Serial.print(" vs ");
  Serial.print(desired_us, DEC);
  Serial.print(": ");
  Serial.print(TICKS_LOW(desired_us + MARK_EXCESS), DEC);
  Serial.print(" <= ");
  Serial.print(measured_ticks, DEC);
  Serial.print(" <= ");
  Serial.println(TICKS_HIGH(desired_us + MARK_EXCESS), DEC);
  return measured_ticks >= TICKS_LOW(desired_us + MARK_EXCESS) && measured_ticks <= TICKS_HIGH(desired_us + MARK_EXCESS);
}

int MATCH_SPACE(int measured_ticks, int desired_us) {
  Serial.print("Testing space ");
  Serial.print(measured_ticks * USECPERTICK, DEC);
  Serial.print(" vs ");
  Serial.print(desired_us, DEC);
  Serial.print(": ");
  Serial.print(TICKS_LOW(desired_us - MARK_EXCESS), DEC);
  Serial.print(" <= ");
  Serial.print(measured_ticks, DEC);
  Serial.print(" <= ");
  Serial.println(TICKS_HIGH(desired_us - MARK_EXCESS), DEC);
  return measured_ticks >= TICKS_LOW(desired_us - MARK_EXCESS) && measured_ticks <= TICKS_HIGH(desired_us - MARK_EXCESS);
}
#endif

void IRsend::sendNEC(unsigned long data, int nbits)
{
  enableIROut(38);
  mark(NEC_HDR_MARK);
  space(NEC_HDR_SPACE);
  for (int i = 0; i < nbits; i++) {
    if (data & TOPBIT) {
      mark(NEC_BIT_MARK);
      space(NEC_ONE_SPACE);
    } 
    else {
      mark(NEC_BIT_MARK);
      space(NEC_ZERO_SPACE);
    }
    data <<= 1;
  }
  mark(NEC_BIT_MARK);
  space(0);
}

void IRsend::sendSony(unsigned long data, int nbits) {
  enableIROut(40);
  mark(SONY_HDR_MARK);
  space(SONY_HDR_SPACE);
  data = data << (32 - nbits);
  for (int i = 0; i < nbits; i++) {
    if (data & TOPBIT) {
      mark(SONY_ONE_MARK);
      space(SONY_HDR_SPACE);
    } 
    else {
      mark(SONY_ZERO_MARK);
      space(SONY_HDR_SPACE);
    }
    data <<= 1;
  }
}

void IRsend::sendRaw(unsigned int buf[], int len, int hz)
{
  enableIROut(hz);
  for (int i = 0; i < len; i++) {
    if (i & 1) {
      space(buf[i]);
    } 
    else {
      mark(buf[i]);
    }
  }
  space(0); // Just to be sure
}

// Note: first bit must be a one (start bit)
void IRsend::sendRC5(unsigned long data, int nbits)
{
  enableIROut(36);
  data = data << (32 - nbits);
  mark(RC5_T1); // First start bit
  space(RC5_T1); // Second start bit
  mark(RC5_T1); // Second start bit
  for (int i = 0; i < nbits; i++) {
    if (data & TOPBIT) {
      space(RC5_T1); // 1 is space, then mark
      mark(RC5_T1);
    } 
    else {
      mark(RC5_T1);
      space(RC5_T1);
    }
    data <<= 1;
  }
  space(0); // Turn off at end
}

// Caller needs to take care of flipping the toggle bit
void IRsend::sendRC6(unsigned long data, int nbits)
{
  enableIROut(36);
  data = data << (32 - nbits);
  mark(RC6_HDR_MARK);
  space(RC6_HDR_SPACE);
  mark(RC6_T1); // start bit
  space(RC6_T1);
  int t;
  for (int i = 0; i < nbits; i++) {
    if (i == 3) {
      // double-wide trailer bit
      t = 2 * RC6_T1;
    } 
    else {
      t = RC6_T1;
    }
    if (data & TOPBIT) {
      mark(t);
      space(t);
    } 
    else {
      space(t);
      mark(t);
    }

    data <<= 1;
  }
  space(0); // Turn off at end
}

void IRsend::mark(int time) {
  // Sends an IR mark for the specified number of microseconds.
  // The mark output is modulated at the PWM frequency.
  TCCR2A |= _BV(COM2B1); // Enable pin 3 PWM output
  delayMicroseconds(time);
}

/* Leave pin off for time (given in microseconds) */
void IRsend::space(int time) {
  // Sends an IR space for the specified number of microseconds.
  // A space is no output, so the PWM output is disabled.
  TCCR2A &= ~(_BV(COM2B1)); // Disable pin 3 PWM output
  delayMicroseconds(time);
}

void IRsend::enableIROut(int khz) {
  // Enables IR output.  The khz value controls the modulation frequency in kilohertz.
  // The IR output will be on pin 3 (OC2B).
  // This routine is designed for 36-40KHz; if you use it for other values, it's up to you
  // to make sure it gives reasonable results.  (Watch out for overflow / underflow / rounding.)
  // TIMER2 is used in phase-correct PWM mode, with OCR2A controlling the frequency and OCR2B
  // controlling the duty cycle.
  // There is no prescaling, so the output frequency is 16MHz / (2 * OCR2A)
  // To turn the output on and off, we leave the PWM running, but connect and disconnect the output pin.
  // A few hours staring at the ATmega documentation and this will all make sense.
  // See my Secrets of Arduino PWM at http://arcfn.com/2009/07/secrets-of-arduino-pwm.html for details.

  
  // Disable the Timer2 Interrupt (which is used for receiving IR)
  TIMSK2 &= ~_BV(TOIE2); //Timer2 Overflow Interrupt
  
  pinMode(3, OUTPUT);
  digitalWrite(3, LOW); // When not sending PWM, we want it low
  
  // COM2A = 00: disconnect OC2A
  // COM2B = 00: disconnect OC2B; to send signal set to 10: OC2B non-inverted
  // WGM2 = 101: phase-correct PWM with OCRA as top
  // CS2 = 000: no prescaling
  TCCR2A = _BV(WGM20);
  TCCR2B = _BV(WGM22) | _BV(CS20);

  // The top value for the timer.  The modulation frequency will be SYSCLOCK / 2 / OCR2A.
  OCR2A = SYSCLOCK / 2 / khz / 1000;
  OCR2B = OCR2A / 3; // 33% duty cycle
}

IRrecv::IRrecv(int recvpin)
{
  irparams.recvpin = recvpin;
  irparams.blinkflag = 0;
}

// initialization
void IRrecv::enableIRIn() {
  // setup pulse clock timer interrupt
  TCCR2A = 0;  // normal mode

  //Prescale /8 (16M/8 = 0.5 microseconds per tick)
  // Therefore, the timer interval can range from 0.5 to 128 microseconds
  // depending on the reset value (255 to 0)
  cbi(TCCR2B,CS22);
  sbi(TCCR2B,CS21);
  cbi(TCCR2B,CS20);

  //Timer2 Overflow Interrupt Enable
  sbi(TIMSK2,TOIE2);

  RESET_TIMER2;

  sei();  // enable interrupts

  // initialize state machine variables
  irparams.rcvstate = STATE_IDLE;
  irparams.rawlen = 0;


  // set pin modes
  pinMode(irparams.recvpin, INPUT);
}

// enable/disable blinking of pin 13 on IR processing
void IRrecv::blink13(int blinkflag)
{
  irparams.blinkflag = blinkflag;
  if (blinkflag)
    pinMode(BLINKLED, OUTPUT);
}

// TIMER2 interrupt code to collect raw data.
// Widths of alternating SPACE, MARK are recorded in rawbuf.
// Recorded in ticks of 50 microseconds.
// rawlen counts the number of entries recorded so far.
// First entry is the SPACE between transmissions.
// As soon as a SPACE gets long, ready is set, state switches to IDLE, timing of SPACE continues.
// As soon as first MARK arrives, gap width is recorded, ready is cleared, and new logging starts
ISR(TIMER2_OVF_vect)
{
  RESET_TIMER2;

  uint8_t irdata = (uint8_t)digitalRead(irparams.recvpin);

  irparams.timer++; // One more 50us tick
  if (irparams.rawlen >= RAWBUF) {
    // Buffer overflow
    irparams.rcvstate = STATE_STOP;
  }
  switch(irparams.rcvstate) {
  case STATE_IDLE: // In the middle of a gap
    if (irdata == MARK) {
      if (irparams.timer < GAP_TICKS) {
        // Not big enough to be a gap.
        irparams.timer = 0;
      } 
      else {
        // gap just ended, record duration and start recording transmission
        irparams.rawlen = 0;
        irparams.rawbuf[irparams.rawlen++] = irparams.timer;
        irparams.timer = 0;
        irparams.rcvstate = STATE_MARK;
      }
    }
    break;
  case STATE_MARK: // timing MARK
    if (irdata == SPACE) {   // MARK ended, record time
      irparams.rawbuf[irparams.rawlen++] = irparams.timer;
      irparams.timer = 0;
      irparams.rcvstate = STATE_SPACE;
    }
    break;
  case STATE_SPACE: // timing SPACE
    if (irdata == MARK) { // SPACE just ended, record it
      irparams.rawbuf[irparams.rawlen++] = irparams.timer;
      irparams.timer = 0;
      irparams.rcvstate = STATE_MARK;
    } 
    else { // SPACE
      if (irparams.timer > GAP_TICKS) {
        // big SPACE, indicates gap between codes
        // Mark current code as ready for processing
        // Switch to STOP
        // Don't reset timer; keep counting space width
        irparams.rcvstate = STATE_STOP;
      } 
    }
    break;
  case STATE_STOP: // waiting, measuring gap
    if (irdata == MARK) { // reset gap timer
      irparams.timer = 0;
    }
    break;
  }

  if (irparams.blinkflag) {
    if (irdata == MARK) {
      PORTB |= B00100000;  // turn pin 13 LED on
    } 
    else {
      PORTB &= B11011111;  // turn pin 13 LED off
    }
  }
}

void IRrecv::resume() {
  irparams.rcvstate = STATE_IDLE;
  irparams.rawlen = 0;
}



// Decodes the received IR message
// Returns 0 if no data ready, 1 if data ready.
// Results of decoding are stored in results
int IRrecv::decode(decode_results *results) {
  results->rawbuf = irparams.rawbuf;
  results->rawlen = irparams.rawlen;
  if (irparams.rcvstate != STATE_STOP) {
    return ERR;
  }
#ifdef DEBUG
  Serial.println("Attempting NEC decode");
#endif
  if (decodeNEC(results)) {
    return DECODED;
  }
#ifdef DEBUG
  Serial.println("Attempting Sony decode");
#endif
  if (decodeSony(results)) {
    return DECODED;
  }
#ifdef DEBUG
  Serial.println("Attempting RC5 decode");
#endif  
  if (decodeRC5(results)) {
    return DECODED;
  }
#ifdef DEBUG
  Serial.println("Attempting RC6 decode");
#endif 
  if (decodeRC6(results)) {
    return DECODED;
  }
  if (results->rawlen >= 6) {
    // Only return raw buffer if at least 6 bits
    results->decode_type = UNKNOWN;
    results->bits = 0;
    results->value = 0;
    return DECODED;
  }
  // Throw away and start over
  resume();
  return ERR;
}

long IRrecv::decodeNEC(decode_results *results) {
  long data = 0;
  int offset = 1; // Skip first space
  // Initial mark
  if (!MATCH_MARK(results->rawbuf[offset], NEC_HDR_MARK)) {
    return ERR;
  }
  offset++;
  // Check for repeat
  if (irparams.rawlen == 4 &&
    MATCH_SPACE(results->rawbuf[offset], NEC_RPT_SPACE) &&
    MATCH_MARK(results->rawbuf[offset+1], NEC_BIT_MARK)) {
    results->bits = 0;
    results->value = REPEAT;
    results->decode_type = NEC;
    return DECODED;
  }
  if (irparams.rawlen < 2 * NEC_BITS + 4) {
    return ERR;
  }
  // Initial space  
  if (!MATCH_SPACE(results->rawbuf[offset], NEC_HDR_SPACE)) {
    return ERR;
  }
  offset++;
  for (int i = 0; i < NEC_BITS; i++) {
    if (!MATCH_MARK(results->rawbuf[offset], NEC_BIT_MARK)) {
      return ERR;
    }
    offset++;
    if (MATCH_SPACE(results->rawbuf[offset], NEC_ONE_SPACE)) {
      data = (data << 1) | 1;
    } 
    else if (MATCH_SPACE(results->rawbuf[offset], NEC_ZERO_SPACE)) {
      data <<= 1;
    } 
    else {
      return ERR;
    }
    offset++;
  }
  // Success
  results->bits = NEC_BITS;
  results->value = data;
  results->decode_type = NEC;
  return DECODED;
}

long IRrecv::decodeSony(decode_results *results) {
  long data = 0;
  if (irparams.rawlen < 2 * SONY_BITS + 2) {
    return ERR;
  }
  int offset = 1; // Skip first space
  // Initial mark
  if (!MATCH_MARK(results->rawbuf[offset], SONY_HDR_MARK)) {
    return ERR;
  }
  offset++;

  while (offset + 1 < irparams.rawlen) {
    if (!MATCH_SPACE(results->rawbuf[offset], SONY_HDR_SPACE)) {
      break;
    }
    offset++;
    if (MATCH_MARK(results->rawbuf[offset], SONY_ONE_MARK)) {
      data = (data << 1) | 1;
    } 
    else if (MATCH_MARK(results->rawbuf[offset], SONY_ZERO_MARK)) {
      data <<= 1;
    } 
    else {
      return ERR;
    }
    offset++;
  }

  // Success
  results->bits = (offset - 1) / 2;
  if (results->bits < 12) {
    results->bits = 0;
    return ERR;
  }
  results->value = data;
  results->decode_type = SONY;
  return DECODED;
}

// Gets one undecoded level at a time from the raw buffer.
// The RC5/6 decoding is easier if the data is broken into time intervals.
// E.g. if the buffer has MARK for 2 time intervals and SPACE for 1,
// successive calls to getRClevel will return MARK, MARK, SPACE.
// offset and used are updated to keep track of the current position.
// t1 is the time interval for a single bit in microseconds.
// Returns -1 for error (measured time interval is not a multiple of t1).
int IRrecv::getRClevel(decode_results *results, int *offset, int *used, int t1) {
  if (*offset >= results->rawlen) {
    // After end of recorded buffer, assume SPACE.
    return SPACE;
  }
  int width = results->rawbuf[*offset];
  int val = ((*offset) % 2) ? MARK : SPACE;
  int correction = (val == MARK) ? MARK_EXCESS : - MARK_EXCESS;

  int avail;
  if (MATCH(width, t1 + correction)) {
    avail = 1;
  } 
  else if (MATCH(width, 2*t1 + correction)) {
    avail = 2;
  } 
  else if (MATCH(width, 3*t1 + correction)) {
    avail = 3;
  } 
  else {
    return -1;
  }

  (*used)++;
  if (*used >= avail) {
    *used = 0;
    (*offset)++;
  }
#ifdef DEBUG
  if (val == MARK) {
    Serial.println("MARK");
  } 
  else {
    Serial.println("SPACE");
  }
#endif
  return val;   
}

long IRrecv::decodeRC5(decode_results *results) {
  if (irparams.rawlen < MIN_RC5_SAMPLES + 2) {
    return ERR;
  }
  int offset = 1; // Skip gap space
  long data = 0;
  int used = 0;
  // Get start bits
  if (getRClevel(results, &offset, &used, RC5_T1) != MARK) return ERR;
  if (getRClevel(results, &offset, &used, RC5_T1) != SPACE) return ERR;
  if (getRClevel(results, &offset, &used, RC5_T1) != MARK) return ERR;
  int nbits;
  for (nbits = 0; offset < irparams.rawlen; nbits++) {
    int levelA = getRClevel(results, &offset, &used, RC5_T1); 
    int levelB = getRClevel(results, &offset, &used, RC5_T1);
    if (levelA == SPACE && levelB == MARK) {
      // 1 bit
      data = (data << 1) | 1;
    } 
    else if (levelA == MARK && levelB == SPACE) {
      // zero bit
      data <<= 1;
    } 
    else {
      return ERR;
    } 
  }

  // Success
  results->bits = nbits;
  results->value = data;
  results->decode_type = RC5;
  return DECODED;
}

long IRrecv::decodeRC6(decode_results *results) {
  if (results->rawlen < MIN_RC6_SAMPLES) {
    return ERR;
  }
  int offset = 1; // Skip first space
  // Initial mark
  if (!MATCH_MARK(results->rawbuf[offset], RC6_HDR_MARK)) {
    return ERR;
  }
  offset++;
  if (!MATCH_SPACE(results->rawbuf[offset], RC6_HDR_SPACE)) {
    return ERR;
  }
  offset++;
  long data = 0;
  int used = 0;
  // Get start bit (1)
  if (getRClevel(results, &offset, &used, RC6_T1) != MARK) return ERR;
  if (getRClevel(results, &offset, &used, RC6_T1) != SPACE) return ERR;
  int nbits;
  for (nbits = 0; offset < results->rawlen; nbits++) {
    int levelA, levelB; // Next two levels
    levelA = getRClevel(results, &offset, &used, RC6_T1); 
    if (nbits == 3) {
      // T bit is double wide; make sure second half matches
      if (levelA != getRClevel(results, &offset, &used, RC6_T1)) return ERR;
    } 
    levelB = getRClevel(results, &offset, &used, RC6_T1);
    if (nbits == 3) {
      // T bit is double wide; make sure second half matches
      if (levelB != getRClevel(results, &offset, &used, RC6_T1)) return ERR;
    } 
    if (levelA == MARK && levelB == SPACE) { // reversed compared to RC5
      // 1 bit
      data = (data << 1) | 1;
    } 
    else if (levelA == SPACE && levelB == MARK) {
      // zero bit
      data <<= 1;
    } 
    else {
      return ERR; // Error
    } 
  }
  // Success
  results->bits = nbits;
  results->value = data;
  results->decode_type = RC6;
  return DECODED;
}

De por si...es un poco compleja la implementación...vas a tener que leer bastante.
 
hora esta bueno tu proyecto pero mi problema es. q dispondo de un pic 16f877 ze podria adaptar ese codigo para este pic. por q este trabaja con un oscilador de 4Mhz nada mas.
 
hora esta bueno tu proyecto pero mi problema es. q dispondo de un pic 16f877 ze podria adaptar ese codigo para este pic. por q este trabaja con un oscilador de 4Mhz nada mas.

Si usas CCS es perfectamente portable, solo tendrías que cambiar las definiciones de procesador y algunas definiciones pero se puede adaptar.

Un saludo !
 
Hola tengo un problema al adaptar tu codigo del decodificador RC5 moyano, me preguntaba si me puedes explicar algunas partes de del programa que no comprendo. El pic que estoy utilizando es un 16f628a ya arme el circuito solo que sin el otro integrado que utilizas, como dije arme el circuito y lo probe con un control philips que supuestamente maneja ese protocolo pero no logro obtener las salidas que deseo.
 
Hola tengo un problema al adaptar tu codigo del decodificador RC5 moyano, me preguntaba si me puedes explicar algunas partes de del programa que no comprendo. El pic que estoy utilizando es un 16f628a ya arme el circuito solo que sin el otro integrado que utilizas, como dije arme el circuito y lo probe con un control philips que supuestamente maneja ese protocolo pero no logro obtener las salidas que deseo.

Hola yo hice un decodificador muy simple con pic 16f628 o 12f629 sin ningun integrado extrerno, del sensor al pic. Te dejo la parte mas importante..

pausa = 1710 ;Tiempo ke dura un cilo "01" o "10"

Senal:
Command = 0
if pinIR=0 then
Command.bit13 = 1 ;bit 13 start bit
pauseus 2066 ;primer pausa para ke kede en medio del sig bit
;pauseus 1300
else : goto senal :endif

if pinIR=1 then
Command.bit12 = 0 : Else : Command.bit12 = 1 : endif : pauseus pausa ;pauseus 1874 Start bit
if pinIR=1 then
Command.bit11 = 0 : Else : Command.bit11 = 1 : endif : pauseus pausa ;pauseus 1693 toggle bit
if pinIR=1 then
Command.bit10 = 0 : Else : Command.bit10 = 1 : endif : pauseus pausa ;pauseus 1693
if pinIR=1 then
Command.bit9 = 0 : Else : Command.bit9 = 1 : endif : pauseus pausa ;pauseus 1714
if pinIR=1 then
Command.bit8 = 0 : Else : Command.bit8 = 1 : endif : pauseus pausa ;pauseus 1718
if pinIR=1 then
Command.bit7 = 0 : Else : Command.bit7 = 1 : endif : pauseus pausa ;pauseus 1711
if pinIR=1 then
Command.bit6 = 0 : Else : Command.bit6 = 1 : endif : pauseus pausa ;pauseus 1666
if pinIR=1 then
Command.bit5 = 0 : Else : Command.bit5 = 1 : endif : pauseus pausa ;pauseus 1766
if pinIR=1 then
Command.bit4 = 0 : Else : Command.bit4 = 1 : endif : pauseus pausa ;pauseus 1640
if pinIR=1 then
Command.bit3 = 0 : Else : Command.bit3 = 1 : endif : pauseus pausa ;pauseus 1762
if pinIR=1 then
Command.bit2 = 0 : Else : Command.bit2 = 1 : endif : pauseus pausa ;pauseus 1671
if pinIR=1 then
Command.bit1 = 0 : Else : Command.bit1 = 1 : endif : pauseus pausa ;pauseus 1620
if pinIR=1 then
Command.bit0 = 0 : Else : Command.bit0 = 1 : endif

if Command.bit12 = 0 then ;Si la señal viene invertida la arregla
command = command ^ %01111111111111 ; invierte el estado del bit 0 de B0
endif
 
Saludos. :apreton:
Aqui les dejo algo que tenia por ahi sobre el RC5 de PHILIPS
Lo acabo de compilar para ver que todo estubiera bien.
Esta en ASM y viene completo. BY4NOW
 

Adjuntos

  • RC5.rar
    113.3 KB · Visitas: 99
Hola yo hice un decodificador muy simple con pic 16f628 o 12f629 sin ningun integrado extrerno, del sensor al pic. Te dejo la parte mas importante..

pausa = 1710 ;Tiempo ke dura un cilo "01" o "10"

Senal:
Command = 0
if pinIR=0 then
Command.bit13 = 1 ;bit 13 start bit
pauseus 2066 ;primer pausa para ke kede en medio del sig bit
;pauseus 1300
else : goto senal :endif

if pinIR=1 then
Command.bit12 = 0 : Else : Command.bit12 = 1 : endif : pauseus pausa ;pauseus 1874 Start bit
if pinIR=1 then
Command.bit11 = 0 : Else : Command.bit11 = 1 : endif : pauseus pausa ;pauseus 1693 toggle bit
if pinIR=1 then
Command.bit10 = 0 : Else : Command.bit10 = 1 : endif : pauseus pausa ;pauseus 1693
if pinIR=1 then
Command.bit9 = 0 : Else : Command.bit9 = 1 : endif : pauseus pausa ;pauseus 1714
if pinIR=1 then
Command.bit8 = 0 : Else : Command.bit8 = 1 : endif : pauseus pausa ;pauseus 1718
if pinIR=1 then
Command.bit7 = 0 : Else : Command.bit7 = 1 : endif : pauseus pausa ;pauseus 1711
if pinIR=1 then
Command.bit6 = 0 : Else : Command.bit6 = 1 : endif : pauseus pausa ;pauseus 1666
if pinIR=1 then
Command.bit5 = 0 : Else : Command.bit5 = 1 : endif : pauseus pausa ;pauseus 1766
if pinIR=1 then
Command.bit4 = 0 : Else : Command.bit4 = 1 : endif : pauseus pausa ;pauseus 1640
if pinIR=1 then
Command.bit3 = 0 : Else : Command.bit3 = 1 : endif : pauseus pausa ;pauseus 1762
if pinIR=1 then
Command.bit2 = 0 : Else : Command.bit2 = 1 : endif : pauseus pausa ;pauseus 1671
if pinIR=1 then
Command.bit1 = 0 : Else : Command.bit1 = 1 : endif : pauseus pausa ;pauseus 1620
if pinIR=1 then
Command.bit0 = 0 : Else : Command.bit0 = 1 : endif

if Command.bit12 = 0 then ;Si la señal viene invertida la arregla
command = command ^ %01111111111111 ; invierte el estado del bit 0 de B0
endif




Estoy interesado en tu codigo podrias explicarme como funciona o ponerlo completo esque llevo algo de tiempo tratando de hacer funcionar un decodificador de ese protocolo
 
Estoy interesado en tu codigo podrias explicarme como funciona o ponerlo completo esque llevo algo de tiempo tratando de hacer funcionar un decodificador de ese protocolo

Todavia se puede mejorar mucho igual, la verda no profundise mucho en el RC5 porque tengo mas controles NEC32.
Tengo puesto un circuito para prender y apagar la luz de mi piesa y tb para manejar la PC con el mismo control asi me tiro en la cama apago la luz y pongo pelis :LOL:

Aca te dejo un video de un ejemplo que hice, decodifica el NEC32 y muestra en el LCD la tecla presionada.

Si queres pasame tu mail por privado y te ayudo con el proyecto.
 
Todavia se puede mejorar mucho igual, la verda no profundise mucho en el RC5 porque tengo mas controles NEC32.
Tengo puesto un circuito para prender y apagar la luz de mi piesa y tb para manejar la PC con el mismo control asi me tiro en la cama apago la luz y pongo pelis :LOL:

Aca te dejo un video de un ejemplo que hice, decodifica el NEC32 y muestra en el LCD la tecla presionada. http://www.youtube.com/watch?v=p3y2olnjM1A

Si queres pasame tu mail por privado y te ayudo con el proyecto.


Lamentablemente aun no puedo mandarte un mensaje privado pero podemos platicar aqui en el foro.
El programa que pusiste esta en ccs? o en que lenguaje algunas instrucciones se me hacen conocidas como a visualBasic pero no estoy seguro. En estos momentos estoy utilizando el ccs
ya trate de hacer un codigo con la logica que vi de tu programa pero tuve algunos problemitas
con el manejo de los bits y con las operaciones logicas, obtuve un codigo muy largo ya que la operacion de XOR la tuve que hacer bit por bit. Me falta probarlo o si tienes alguna sugerencia
sea bienvenida!!!
 
Lamentablemente aun no puedo mandarte un mensaje privado pero podemos platicar aqui en el foro.
El programa que pusiste esta en ccs? o en que lenguaje algunas instrucciones se me hacen conocidas como a visualBasic pero no estoy seguro. En estos momentos estoy utilizando el ccs
ya trate de hacer un codigo con la logica que vi de tu programa pero tuve algunos problemitas
con el manejo de los bits y con las operaciones logicas, obtuve un codigo muy largo ya que la operacion de XOR la tuve que hacer bit por bit. Me falta probarlo o si tienes alguna sugerencia
sea bienvenida!!!

Mmm yo no use operaciones XOR ni nada raro, lo programe en Picbasic pro con el Microcode Studio, pero sino te recomiendo el IDE de Proton que es muy similar pero un poco mejor.
 
Mmm yo no usé operaciones XOR ni nada raro, lo programe en Picbasic pro con el Microcode Studio, pero si no te recomiendo el IDE de Proton que es muy similar pero un poco mejor.


Oye. ¿Puedes decirme como hacerlo en picBasic? Es que ese programa ya lo tengo instalado en mi maquina y he estado trabajándolo junto con visual basic.
Trate de hacer el programa pero creo que necesito un archivo extra porque solo puedo trabajar con el pic 18f4550 y no aparece otro. ¿Que compilador debo elegir??

La operación Xor me refería a la instrucción
command = command ^ %01111111111111 ; invierte el estado del bit 0 de B0
endif

Según yo cuando colocas "^" es porque quieres aplicar la operación XOR, pero puedo equivocarme.
Esta instrucción no la comprendo del todo. ¿Por qué hacerla y que función tiene?
Y si no la hago tendrá alguna consecuencia?

El código que pasé en Mplab utilizando el compilador ccs es el siguiente.
Me basé en tu lógica o en la parte de programa que pusiste anteriormente.

Código:
struct empaquetado {                    ///Todo esto es para tratar de hacer lo mismo que tu
    unsigned int bit0:1;         /// con la variable comando, creo una estructura 
    unsigned int bit1:1;                  /// empaquetado con 14 variables las cuales 
    unsigned int bit2:1;                  /// corresponden a cada bit de la señal del control
    unsigned int bit3:1;
    unsigned int bit4:1;
    unsigned int bit5:1;
    unsigned int bit6:1;
    unsigned int bit7:1;
    unsigned int bit8:1;
    unsigned int bit9:1;
    unsigned int bit10:1;
    unsigned int bit11:1;
    unsigned int bit12:1;
    unsigned int bit13:1;
    
    
} paquete;

///////////////////////////Dentro de la funcion principal tengo el sig. codigo basado en el tuyo

    Senal:                              //Etiqueta del goto
    paquete = 0;                    //Todas las variables de la estructura a cero
    if (!input(IR_RECEPTOR))    // Pregunto si la entrada del pin es cero
    {
    paquete.bit13=1;              // Pongo el bit13=1,,para acceder a cada bit de la 
                                          // estructura debo poner paquete.bitx=
    delay_us(1330);               //primer pausa para ke kede en medio del sig bit
    if(paquete.bit13)              //segun yo el valor es 1330 en el retardo y no 2066
    {
            codigo(); //funcion donde pregunto por los demas bits



              }

///////////////////////////////Función código
//Esta parte del código va checando la trama mandada por el control de tal forma que checa cada bit de
// la trama compuesta por 14 bits, los retardos son los adecuados para que separe a cada bit 
// si al checar cae en un uno es porque es un uno y en caso contrario si cae en un cero corresponde a un cero, en esto según yo como estoy tomando la salida de un receptor donde
// la señal de salida siempre sera un uno al recibir la señal de control se hace cero
// y obtendremos una señal invertida de como la muestran normalmente
/////////////////////////////////////////////////////////////////////////////////////////////////
//
    
int codigo()
{
if (input(IR_RECEPTOR)){     paquete.bit12 = 1;}//Asigno valor a cada bit dependiendo de la
else{                        paquete.bit12 = 0;}// entrada
delay_us(pausa);

if (input(IR_RECEPTOR)){    paquete.bit11 = 1;}
else{            paquete.bit11 = 0;}
  delay_us(pausa) ;

if (input(IR_RECEPTOR)){    paquete.bit10 = 1;}
else{            paquete.bit10 = 0;}
  delay_us(pausa);

if (input(IR_RECEPTOR)){    paquete.bit9 = 1;}
 else{                     paquete.bit9 = 0 ;}
 delay_us(pausa);

if (input(IR_RECEPTOR)){    paquete.bit8 = 1;}
 else {            paquete.bit8 = 0;}
delay_us(pausa);

if (input(IR_RECEPTOR)){    paquete.bit7 = 1;}
 else {            paquete.bit7 = 0;}
delay_us( pausa) ;

if (input(IR_RECEPTOR)){    paquete.bit6 = 1;}
else{            paquete.bit6 = 0;}
delay_us (pausa );

if (input(IR_RECEPTOR)){    paquete.bit5 = 1;}
else {            paquete.bit5 = 0;}
delay_us( pausa );

if (input(IR_RECEPTOR)){    paquete.bit4 = 1;}
else         {    paquete.bit4 = 0;}
delay_us( pausa );

if (input(IR_RECEPTOR)){    paquete.bit3 = 1;}
 else{            paquete.bit3 = 0;}
delay_us( pausa );

if (input(IR_RECEPTOR)){    paquete.bit2 = 1;}
else {                     paquete.bit2 = 0;}
delay_us( pausa );

if (input(IR_RECEPTOR)){    paquete.bit1 = 1;}
else {            paquete.bit1 = 0;}
delay_us (pausa) ;

if (input(IR_RECEPTOR)){    paquete.bit0 = 1;}
else {            paquete.bit0 = 0; }

///////////En esta parte no se como hacer la operación que hiciste la de invertir los bits
/////lo puedo hacer uno por uno pero es muy largo 
if (paquete.bit12) ;//Si la señal viene invertida la arregla

if (paquete.bit13){     paquete.bit13 = 0;}//Por ejemplo para invertir el estado del bi13
else{                        paquete.bit13 = 1;}//pregunto si es uno si es cierto lo pongo a 
                                                                    // cero y si es cero lo pongo a uno y así para 
                                                                    // todos los bits bit12,bit11,bit10,....bit0
// Depués regresaríamos a donde fue llamada la función tecla y en ese espacio checaría los 
// últimos bits para saber la tecla que fue presionada y hacer algo por ejemplo mostrarlo en 
// el lcd prender un led con el peso correspondiente a la tecla o activar un motor,etc.

Bueno hasta aquí mis problemas, espero y puedas ayudarme o seguir aconsejándome como lo
has hecho, esperando que comprendas lo que trato de hacer en mi código y las explicaciones que en él doy.
Sin nada más me despido.
 
Última edición por un moderador:
Atrás
Arriba