RC5 decode on a 10F + Question


Results 1 to 9 of 9

Threaded View

  1. #1
    Join Date
    Apr 2006
    Location
    GearSweaterMountain, The Netherlands
    Posts
    52

    Question RC5 decode on a 10F + Question

    Hi all,

    I needed to build a philips RC5 IR decoder, in order to be able to control some other circuitry. When a predefined key is received an decoded the corresponding IO is made high.

    However, the example source code's if found could not fit a 10F202.

    I used a TSOP(TK)1836 connected to GPIO.0, and in order to "see" the values received the pic sends it's data trough a max232 to my pc. This is only for debug purposes, and must be removed later (removing the moddefs include and serout will free up lots ofprogram memory).

    Code:
    '==== Set fuses ================================================================
    @ device pic10F202,wdt_off,mclr_off,protect_off
    
    '==== Set includes =============================================================
    INCLUDE "modedefs.bas"                          ' Include for Serout
    
    '==== Set XTAL =================================================================
    DEFINE OSC 4                                    ' int XTAL @ 4 Mhz
    
    '==== Set variables ============================================================
    Y VAR word                                      ' To Hold the 12-bit RC5 code
    
    
    '==== Set IO ===================================================================    
    IR_PIN VAR GPIO.0                               ' GPIO.0 input pin reading IR data
    SERIAL var GPIO.1                               ' GPIO.1 SEROUT 9600-8-n-1 output
    TRISIO = %00001001                              ' Set TRIS register input's & output's
    OPTION_REG.7 = 0                                ' Internal pull-ups = on
    
    '==== Signal information =======================================================
    'Given the information found on http://www.sbprojects.com/knowledge/ir/rc5.htm
    'The incoming RC5 signal will look like this :
    '
    'bit      1    2    3    4    5    6    7    8    9   10   11   12   13   14
    '      |    |    |    |    |    |    |    |    |    |    |    |    |    |    |
    'uSec   1778 1778 1778 1778 1778 1778 1778 1778 1778 1778 1778 1778 1778 1778
    
    '==== Main program =============================================================  
    MAIN:
    IF IR_PIN = 1 THEN GOTO MAIN                    ' Wait for the first bit to arive
    y.13 = IR_PIN                                    ' Incoming signal 
    pauseus 889                                     ' In order to se this 0 we are in the second 
                                                    ' period of the first 1.778 msec, so we will 
                                                    ' wait another 889 usec to enter the 2nd period.
    
    pauseus 1600                                    ' Almost at the end of the second period, look for
    y.12 = IR_pin                                    ' a high or low signal
    pauseus 178                                     ' Time to the end of this period
    
    pauseus 1600                                    ' Almost at the end of this period, look for
    y.11 = IR_pin                                    ' a high or low signal
    pauseus 178                                     ' Time to the end of this period
    
    pauseus 1600                                    ' Almost at the end of this period, look for
    y.10 = IR_pin                                    ' a high or low signal
    pauseus 178                                     ' Time to the end of this period
    
    pauseus 1600                                    ' Almost at the end of this period, look for
    y.9 = IR_pin                                    ' a high or low signal
    pauseus 178                                     ' Time to the end of this period
    
    pauseus 1600                                    ' Almost at the end of this period, look for
    y.8 = IR_pin                                    ' a high or low signal
    pauseus 178                                     ' Time to the end of this period
    
    pauseus 1600                                    ' Almost at the end of this period, look for
    y.7 = IR_pin                                    ' a high or low signal
    pauseus 178                                     ' Time to the end of this period
    
    pauseus 1600                                    ' Almost at the end of this period, look for
    y.6 = IR_pin                                    ' a high or low signal
    pauseus 178                                     ' Time to the end of this period
    
    pauseus 1600                                    ' Almost at the end of this period, look for
    y.5 = IR_pin                                    ' a high or low signal
    pauseus 178                                     ' Time to the end of this period
    
    pauseus 1600                                    ' Almost at the end of this period, look for
    y.4 = IR_pin                                    ' a high or low signal
    pauseus 178                                     ' Time to the end of this period
    
    pauseus 1600                                    ' Almost at the end of this period, look for
    y.3 = IR_pin                                   ' a high or low signal
    pauseus 178                                     ' Time to the end of this period
    
    pauseus 1600                                    ' Almost at the end of this period, look for
    y.2 = IR_pin                                   ' a high or low signal
    pauseus 178                                     ' Time to the end of this period
    
    pauseus 1600                                    ' Almost at the end of this period, look for
    y.1 = IR_pin                                   ' a high or low signal
    pauseus 178                                     ' Time to the end of this period
    
    pauseus 1600                                    ' Almost at the end of this period, look for
    y.0 = IR_pin                                   ' a high or low signal
    pauseus 178                                     ' Time to the end of this period
    
    y = ~y                                          ' Invert y word
    if Y.lowbyte = 255 then goto ERROR              ' If all lowbytes are 0xFF then noise is received 
    
    '==== DEBUG , output received data serial ======================================
    Serout serial,T9600,["STX= ",#y.13,#Y.12,#Y.11,10,13]
    Serout serial,T9600,["SYS= ",#y.10,#y.9,#y.8,#y.7,#y.6,13,10]                
    Serout serial,T9600,["CMD= ",#Y.5,#y.4,#y.3,#y.2,#y.1,#Y.0,13,10]
    
    '==== End of main loop reset and look again ==================================== 
    ERROR:                                        
    Y=0                                         ' Clear key codes
    PAUSE 250                                   ' debounce
    GOTO MAIN                                   ' Return to main loop
    My problem now is:
    The variable Y is a WORD the has bit's 0 to 13 stored with info.
    How do i break up the word in to 3 sections ?

    bits 0 to 2 '000' are for the S1, S2 and toggle bit
    bits 3 to 7 '00000' are for the System address
    bits 8 to 13 '000000' are for the command bits

    I want to end up with 2 variables SYSTEM(5 bits) and COMMAND(6 bits)

    Anyone ?
    (Also, comments on my code are very welcome !!!)

    Thanks !
    Last edited by ultiblade; - 10th September 2008 at 12:52.

Similar Threads

  1. Please answer my first question
    By John_001 in forum Off Topic
    Replies: 1
    Last Post: - 15th September 2006, 06:49
  2. Switch Debounce using a 10F chip
    By modifyit in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 21st March 2006, 05:22
  3. IR decode problem "hitachi TV remote"
    By chai98a in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 13th March 2006, 15:29
  4. Decode RC5 ?
    By charudatt in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 3rd November 2005, 10:12
  5. RC5 Encode / Decode
    By charudatt in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 18th October 2003, 05:14

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