Can not decode properly IR remote code.


Closed Thread
Results 1 to 11 of 11

Hybrid View

  1. #1
    Join Date
    Feb 2012
    Location
    PERTH AUSTRALIA
    Posts
    838


    Did you find this post helpful? Yes | No

    Default Re: Can not decode properly IR remote code.

    here is part of code i wrote to capture the IR codes for NEC protocol from a remote controlled LED RGB lamp project
    code uses a 8mhz, PIC12F683, code use IOC with darrel 's int routines

    hope it helps

    Code:
    DEFINE OSC 8             ' Timing referance for pause , pauseus commands 
    DEFINE PULSIN_MAX 21600  ' Maximum counts( clock ticks) allowed before pulsin times out( 21600 ^ 5ms =  108 ms)
                             ' Norm IR pulse length is 108ms
    
    
    ' =========================  Get IR Code Routine    =================
     ' *                                                                 *
     ' *             *******  IOC - Interupt Handler routine *******     *
     ' *                                                                 *
     '====================================================================
     
     GetIRcode:
         
          z = 0                            ' Z points to start range of byte 
          S = 7                            ' S points to end range of byte 
          X = 0                            ' start X at 0 to line up with BtnVal array
          y = 0                            ' Y is used for each byte 
       
       rctime IR,0,Leader                         ' get leader low pulse time value in on GPIO.0   
         IF Leader < 1700 or  Leader > 1875 tHEN  ' look for 9000us Low pulse of header for 1st or 2nd key area pulse  
    @ INT_RETURN                                  ; reject if < 8500us  or > 9375us (1700^ 5us= 8500us)
         endif
      
    
       RCtime IR,1,Leader                         ' check for 1st key seq high pulse for 4.5ms after the 9ms low pulse so no repeat headers or 2nd key 
         if Leader < 850  or Leader > 950 then    ' if high for < 4250us  then its the 2nkey /data at wrong or > 4750us ( invalid pulse) ( 850 * 5us = 4250us)
    @ INT_RETURN      
         endif
    
     
      FOR X = 0 TO 31                  ' grab 32 incoming pulses
           PULSIN IR,1,leader          ' now measuring high-going pulse widths   ( pulsin_max set to 21600 = 108ms )
           BtnVal(x) = leader/2        ' leader divide by 2 so array Btnval(x) is byte (<255) not word value  
      NEXT X
     
          
      for Y = 1 to 4                       ' Get in Array and decode 4 bytes from 32 bit pulses 
            T = 7                          ' Set T to 7 so that it puts BtnVal(0) in to D7 location  
            FOR X = Z TO S                 ' sort 8 pulses of byte
        
              IF BtnVal[X]  > 120 THEN     ' > 120 x (5uS *2) = > 1.2mS pulse period = 1 (150)
                 DByteTmp = DByte[Y]       ' get into temp var
                 DByteTmp.0[T]=1           ' Set value to 0 or 1 , T reverses bit order of BtnVal(x) so byte has correct bin value to write byte 
                ELSE
                 DByteTmp = DByte[Y]       ' get into temp var
                 DByteTmp.0[T]=0           ' Set value to 0 or 1 , T reverses bit order of BtnVal(x) so byte has correct bin value to write byte 
               ENDIF
      
              DByte[Y] = DByteTmp          ' get it back into DByte(y)                                                                                                                                            c
              T = T - 1                    ' T points to next MSB on loop
            NEXT X
        
          Z = x                            ' Z = X (0,8,16,24) points to start of next byte
          S = 7 + X                        ' S  (7,15,23,31) points to End of next DByte BtnVal offset to X
      next Y                               ' loop for 4 bytes

  2. #2
    Join Date
    Feb 2013
    Posts
    1,158


    Did you find this post helpful? Yes | No

    Default Re: Can not decode properly IR remote code.

    Thanks, but your code lacks some commands as I can see, like:

    OSCCON = %01110111

    to set OSC clock to 8mhz

  3. #3
    Join Date
    Feb 2013
    Posts
    1,158


    Did you find this post helpful? Yes | No

    Default Re: Can not decode properly IR remote code.

    And it is quite interesting, if it's possible to decode air conditioner remote codes? they are very long and very weird

  4. #4
    Join Date
    Aug 2008
    Location
    Portugal
    Posts
    240


    Did you find this post helpful? Yes | No

    Default Re: Can not decode properly IR remote code.

    Quote Originally Posted by CuriousOne View Post
    Thanks, but your code lacks some commands as I can see, like:

    OSCCON = %01110111

    to set OSC clock to 8mhz
    You cannot assume that just by see "DEFINE OSC 8", because he can be using an external osc. You can only assume that, it he had post the config fuses.

    One more thing, about this
    There's nothing much to post in schematic, the receiver is hooked as it should, GND goes to GND, VDD goes to VDD, and OUT is connected to PORTC.4
    What's the reference of your IR receiver? Because some need a pull up resistor, when your are not using it.
    Thanks and Regards;
    Gadelhas

  5. #5
    Join Date
    Feb 2013
    Posts
    1,158


    Did you find this post helpful? Yes | No

    Default Re: Can not decode properly IR remote code.

    I've solved the problem, but code is quite weird

    Code looks like this:

    Code:
    MAIN:
    PULSIN FLASH,1,SOMEVAR
    IF SOMEVAR<50 AND SOMEVAR >20 THEN GOTO KOUNT
    GOTO MAIN
    KOUNT:
    INCREMENT=INCREMENT+1
    IF FLASH=1 THEN POS=POS+1 ELSE NEG=NEG+1
    IF INCREMENT>1000 THEN GOTO COMPLETE
    GOTO KOUNT
    COMPLETE:
    IF POS>100 AND POS<300 AND NEG>1000 AND NEG<3000 THEN GOSUB JOB:
    POS=0:NEG=0:INCREMENT=0
    GOTO MAIN
    JOB:
    TOGGLE RELAY1
    RETURN
    END
    Last edited by CuriousOne; - 22nd December 2013 at 19:52.

Similar Threads

  1. remote code learning
    By Bruce in forum Code Examples
    Replies: 20
    Last Post: - 21st February 2021, 16:38
  2. Using Walter's Servo PWM encode / decode code
    By NickMu in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 2nd November 2012, 00:17
  3. Is this code not initialising the LCD properly?
    By Platypus in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 30th January 2010, 20:14
  4. Hitachi remote code
    By aa222k in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 27th October 2008, 00:20
  5. IR decode problem "hitachi TV remote"
    By chai98a in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 13th March 2006, 16:29

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts