IR Remote Controlled 4 Channel Relay

Print Friendly, PDF & Email

Code to read IR Signal from a Sony Remote and trigger a relay.

Code adapted from

Compiler : CCS C Compiler
Target MCU: Microchip PIC 16F628A

#include  
#fuses INTRC_IO, NOWDT, BROWNOUT,  NOLVP 
#use delay(internal=4MHz)
#define LED  PIN_B4
#define IR  PIN_B3
#define RELAY1  PIN_A2
#define RELAY2  PIN_A3
#define RELAY3  PIN_B1
#define RELAY4  PIN_B2

/* TIMER0 configuration */ 
#define TIMER0_CONFIG   RTCC_INTERNAL | RTCC_DIV_1 

/* Interrupt rate:                     */ 
/* 4/4000000*65536*1 = 0.256 ms       */ 
/*                                     */ 
/*     Start: 3.0 ms (ignored)         */ 
/*     "1":   1.8 ms (225)           */ 
/*     "0":   1.2 ms  (150)           */ 
/*

*/
#define ONE_MIN  190
#define ONE_MAX  400 
#define ZERO_MIN 10 
#define ZERO_MAX 185 

short rly1,rly2,rly3,rly4,state;

/* irframes[0] (start) will be garbage, ignore it...  */ 
int16 irframes[13]; 
int8 ircount = 0; 
int1 irdone = FALSE; 

#int_ccp1 
void ext_ccp1() { 
  if (irdone) return; 
  irframes[ircount++] = get_timer0(); 
  if (ircount >= 13) 
    irdone = TRUE; 
  set_timer0(0); 
  enable_interrupts(INT_TIMER0); 
//#output_bit(LED,1);delay_ms(1);output_bit(LED,0);delay_ms(1);
} 

#int_timer0 
void timer0_isr() { 
  disable_interrupts(INT_TIMER0); 
} 

#separate 
int1 decode_ir(int8 &addr, int8 &cmd) { 
  int8 i; 
  int8 mask; 
  int8 bits[13]; 

  addr = 0; 
  cmd = 0; 

  for (i=1; i
Ishan Karve

About Ishan Karve

Ishan Karve is just an every day normal guy next door who happens to be an Electronics Engineer by profession and dabbles with PHP, Javascript, C++ and python. His interests vary as seasons change.. they change from astronomy to soul searching. This site is just a reflection of what he does to keep his mind engaged when he is not occupied by work and family. He is an extremely objective guy and is always ready for some good arguments.. of course over a glass of 40% proof alcohol.
This entry was posted in CCS C, Electronics, PIC and tagged , , , , , , , , . Bookmark the permalink.

2 Responses to IR Remote Controlled 4 Channel Relay

  1. muammer says:

    thank you..

Leave a Reply

Your email address will not be published. Required fields are marked *