Using TSOP4836 for reading codes with IR microcontroller PIC18F2520

Probably many of the fans of development on microcontrollers least a couple of times but the thought of the possibility of the control device using a standard IR remote control from the TV. Particularly captivating is that to connect the IR sensor TSOP4836 required just simply one free pin and two resistors! Once I tried this option.

схема подключения TSOP4836 к микроконтроллеру PIC18F2520

TSOP4836
Pinout TSOP4836

I picked a simple circuit on 18F2520 and figured out how to decode the signals and wrote the code, with which got signatures for all available to me at the moment IR remotes.

The following is the source code, with which you can get 32-bit signatures for different buttons on the remote:

#include <18f2520.h>

#define FCONST OSC_8MHZ 
#define FREQ 8000000

#pragma config WDT = OFF
#pragma config LVP = OFF
#fuses INTRC_IO
#use delay (clock=FREQ)
#use rs232(baud=9600, xmit=PIN_A2,rcv=PIN_A3)

#define LED          PIN_A0

INT1  Received=false;
long t;
int8 i;

#define LH_Edge 0
#define HL_Edge 1
int8 edge;
void setEdge(int1 e) {
  edge=e;
  if (e==LH_Edge) {
    ext_int_edge(0, L_TO_H);
  } else {
    ext_int_edge(0, H_TO_L);
  }
}

int32 t0,t1;
int32 code;
int8 timerov;
int8 cnt=0xFF;

#define MIN_LEAD_IN 1000      // 4 ms 
#define MAX_LEAD_IN 1500      // 6 ms
#define MIN_TIME 60           // 0.24 ms 
#define MID_TIME 200          // 0.8 ms 
#define MAX_TIME 800          // 3.2 ms

#int_EXT

EXT_isr() {
  if (!received) {
    if (edge==HL_Edge) {
      t1=(0x10000*timerov+get_timer0());
    } else {
      t0=(0x10000*timerov+get_timer0());

      if (cnt==0xFF) {
        if ((t1>MIN_LEAD_IN)&&(t1<MAX_LEAD_IN)) {
          cnt=0;
          code=0;
        }
      } else {
        if ((t1<MAX_TIME)&&(t1>MIN_TIME)&&(t0>MIN_TIME)&&(t0<MAX_TIME)) {
          if ((t1<MID_TIME)&&(t0<MID_TIME)) {
          } else {
            bit_set(code,cnt);
          }

          cnt++;        
        } else {
          cnt=0xFF;        
        }
      }    
      if (cnt==23) {
        received=TRUE;
        cnt=0xFF;
      }    
    }
  }
  setEdge(!edge);
  timerov=0;
  set_timer0(0);
}

#int_TIMER0
TIMER0_isr() {
  if (timerov<255)
    timerov++;
}

void main()
{
  setup_oscillator(FCONST);
   delay_ms(5000);
   printf("initr");

   setup_adc_ports(NO_ANALOGS);
   setup_adc(ADC_OFF);
   setup_spi(FALSE);
   setup_wdt(WDT_OFF);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_8);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
   enable_interrupts(INT_EXT);
   enable_interrupts(GLOBAL);
   enable_interrupts(INT_TIMER0);
   setEdge(HL_Edge);

   set_timer0(0);
   delay_ms(10);
   t=get_timer0();
   printf("%Lu",t);
   printf("00 tick/sec");

   printf("gor");
   DO
   {
   IF (received) {
     disable_interrupts(GLOBAL);
     printf("%lx ",code); 
     printf("r");
     enable_interrupts(GLOBAL);
     received=false;
   }
   }
   WHILE (true);
}

The following is a table of IR codes for the studied home consoles. The codes in the table are arranged visually in accordance with the arrangement of buttons on the remote.

Remote Code Table “TOSHIBA CT-90119”

Пульт телевизора TOSHIBA CT-90119 0016bf40 0012bf40
0013bf40 0017bf40 0010bf40
0001bf40 0002bf40 0003bf40
0004bf40 0005bf40 0006bf40
0007bf40 0008bf40 0009bf40
000bbf40 0000bf40 0014bf40
001bbf40
001ebf40 001abf40
001fbf40
005bbf40 0018bf40 001cbf40
0053bf40 0054bf40 000dbf40
0048bf40 0015bf40 004bbf40
0049bf40 004abf40

Remote Code Table “Twinhan-DVB”

ИК-пульт Twinhan-DVB 004dff00 0016ff00
0003ff00 0001ff00 0006ff00
0009ff00 001dff00 001fff00
000dff00 0019ff00 001bff00
0011ff00 0015ff00 0017ff00
0040ff00 0005ff00 0012ff00
000aff00 0014ff00 001eff00
000eff00 0002ff00 001aff00
004cff00 0010ff00 000cff00
0054ff00 0048ff00 001cff00
0004ff00 0000ff00 000fff00

Code Table for Remote ORION-DVD

ИК-пульт ORION-DVD 0054bf40 005bbf40
0014bf40 0057bf40 0041bf40 0046bf40
0009bf40 001dbf40 001fbf40 000dbf40
0019bf40 001bbf40 0011bf40 0015bf40
0017bf40 0012bf40 0059bf40 0008bf40
0050bf40 0055bf40 0048bf40 004abf40
005ebf40 0006bf40 0005bf40 0003bf40
0047bf40 0007bf40 0040bf40 0002bf40
0018bf40 0044bf40 000fbf40 0051bf40
000abf40 001ebf40 000ebf40 001abf40
0053bf40 0052bf40 0001bf40 0045bf40

Table of codes for IR AVerMedia:

ИК-пульт к плате видео-захвата AVerMedia 0001fd02 0002fd02 0003fd02 0000fd02
0005fd02 0006fd02 0007fd02 0004fd02
0009fd02 000afd02 000bfd02 0008fd02
000dfd02 000efd02 000ffd02 000cfd02
0011fd02 0012fd02 0013fd02 0010fd02
0015fd02 0016fd02 0017fd02 0014fd02
0019fd02 001afd02 001bfd02 0018fd02
001dfd02 001efd02 001ffd02 001cfd02
0001fc03 0002fc03 0003fc03 0000fc03

2 thoughts on “Using TSOP4836 for reading codes with IR microcontroller PIC18F2520”

  1. When specific buttons are pressed, you can use the incoming values to do something else in your code, for example turn on and off a motor or LED.

    1. Yes, instead of code
      printf(“%lx “,code);
      printf(“r”);
      you can insert your own code

Leave a Comment

Your email address will not be published.