Timer + rc5


Closed Thread
Results 1 to 9 of 9

Thread: Timer + rc5

  1. #1
    Join Date
    Sep 2006
    Posts
    42

    Default Timer + rc5

    Hello All,
    Controlling timer with few buttons using darreltaylor's Elapsed Timer Routines perfectly, Would like to control wirelessly with the use of a normal TV-remote-control with the RC5 protocol..seeking help..Thanx.
    Some thing like this:
    Main:
    if command = 1 then start timer
    if command = 2 then stop timer
    if command = 3 then toggle led
    goto Main

    Current Code:
    define osc 4
    INCLUDE "DT_INTS-14.bas"
    INCLUDE "ReEnterPBP.bas"
    INCLUDE "Elapsed_INT.bas" ; Elapsed Timer Routines

    TRISB = %11111111
    PushButton var PortB.0
    DIPSwitch var PortB.1
    Switch1 var PortB.2
    Switch4 var PortB.3
    LED var portd.3
    LED1 var portd.2
    Low LED
    low led1

    'TRISE = %00000111
    ' Set LCD Data port
    DEFINE LCD_DREG PORTD
    ' Set starting Data bit (0 or 4) if 4-bit bus
    DEFINE LCD_DBIT 4
    ' Set LCD Register Select port
    DEFINE LCD_RSREG PORTD
    ' Set LCD Register Select bit
    DEFINE LCD_RSBIT 1
    ' Set LCD Enable port
    DEFINE LCD_EREG PORTD
    ' Set LCD Enable bit
    DEFINE LCD_EBIT 0
    ' Set LCD bus size (4 or 8 bits)
    DEFINE LCD_BITS 4
    ' Set number of lines on LCD
    DEFINE LCD_LINES 2
    ' Set command delay time in us
    DEFINE LCD_COMMANDUS 2000
    ' Set data delay time in us
    DEFINE LCD_DATAUS 50

    LCDOUT $FE, 1, "Hello" ' Clear display and show “Hello”

    ASM
    INT_LIST macro ; IntSource, Label, Type, ResetFlag?
    INT_Handler TMR1_INT, _ClockCount, PBP, yes
    endm
    INT_CREATE ; Creates the interrupt processor
    ENDASM

    @ INT_ENABLE TMR1_INT ; Enable Timer 1 Interrupts

    GOSUB ResetTime ' Reset Time to 0d-00:00:00.00
    GOSUB StartTimer ' Start the Elapsed Timer

    Main:
    If PushButton=0 then GOSUB ResetTime ' Check for Button Press
    While PushButton=0 : Wend
    If Switch1 =0 then GOSUB StartTimer ' Check for Button Press
    While Switch1 =0 : Wend
    If DIPSwitch=0 then GOSUB StopTimer ' Check for Options
    While DIPSwitch=0 : Wend
    If Switch4 =0 then GOSUB tog ' Check for Button Press
    IF SecondsChanged = 1 THEN
    SecondsChanged = 0
    LCDOUT $FE,2, DEC Days,"d-",DEC2 Hours,":",DEC2 Minutes,":",DEC2 Seconds

    If Seconds > 0 And Seconds = 5 Then High LED1
    If Seconds > 5 And Seconds = 10 Then Low LED1 : Seconds = 0
    ENDIF
    GOTO Main

    tog:
    Toggle LED ' Toggle LED at each Button Press
    pause 250
    return

  2. #2
    Join Date
    Sep 2006
    Posts
    42


    Did you find this post helpful? Yes | No

    Default

    HI..desperately waiting for help..

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


    Did you find this post helpful? Yes | No

    Default

    Hi Naga,

    I did some RC5 controlled projects last year.
    I did some searching but i could only find some of my test code.
    You should read the info found on http://www.sbprojects.com/knowledge/ir/rc5.htm this will give you an idea of how it works and a schematic ...

    Best regards, UB

    Code:
    '==== Set fuses =========================
    @ device pic10F202,wdt_off,mclr_off,protect_off
    
    '==== Set XTAL =========================
    DEFINE OSC 4                                    ' int XTAL @ 4 Mhz
    
    '==== Set variables ======================
    Y       VAR word                                      ' To Hold the 12-bit RC5 code
    TMP     var BYTE
    
    '==== Set IO ===========================    
    IR_PIN  VAR GPIO.3                               ' GPIO.0 input pin reading IR data
    SDA     var GPIO.0
    SCL     var GPIO.1
    'errled  var GPIO.2
    
    OPTION_REG.7 = 0                                ' Internal pull-ups = on
    TRISIO = %00001000                              ' Set TRIS register input's & output's
    OPTION_REG.5 = 0                                ' Set Timer inc. on internal inst.
    GPIO   = %00000000                              ' Set all digital low
    
    '==== Signal information ==================
    'Given the information found on http://www.sbprojects.com/knowledge/ir/rc5.htm
    '
    '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 see 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 
    
    TMP.1 = Y.13
    TMP.0 = Y.12
    if not tmp = 3 then goto error
    
    TMP.4 = Y.10
    TMP.3 = Y.9
    TMP.2 = Y.8
    TMP.1 = Y.7
    TMP.0 = Y.6
    if not tmp = 0 then goto error
    
    TMP.2 = Y.5
    TMP.1 = Y.4
    TMP.0 = Y.3
    if tmp > 0 then goto error
    
    TMP.2 = Y.2
    TMP.1 = Y.1
    TMP.0 = Y.0
    
    ' TMP now holds the decoded RC5 signal
    
    '==== End of main loop reset and go from top ====
    ERROR:                                        
    Y=0
    tmp=0                                       ' Clear key codes
    PAUSE 250                                   ' debounce
    GOTO MAIN                                   ' Return to main loop
    
    END

  4. #4
    Join Date
    Sep 2006
    Posts
    42


    Did you find this post helpful? Yes | No

    Default

    @ Altiblade: Thank you for you code.. Still struggling.. I would really appreciate if someone can share the complete project/working code...Thanx again.

  5. #5
    Join Date
    Jan 2009
    Location
    California, USA
    Posts
    323


    Did you find this post helpful? Yes | No

    Default

    I can't help you with working RC5 code, but here's a Microchip application note that gives some info about using a 10F206 to build a small IR remote transmitter. It talks a little about RC5 and Sony 12 formats.

    http://ww1.microchip.com/downloads/e...tes/01064A.pdf

    I've got some working test code that receives Sony12 and displays the button pressed on an LCD display, but that probably won't be much help to you.
    I haven't learned RC5 yet....



    steve

  6. #6
    Join Date
    May 2008
    Location
    Italy
    Posts
    825


    Did you find this post helpful? Yes | No

    Default

    Naga, there is a code example (in assembly) @ the following link: http://www.freescale.com/files/micro...ote/AN3402.pdf

    May be you can use it.

    Al.
    All progress began with an idea

  7. #7
    Join Date
    Sep 2006
    Posts
    42


    Did you find this post helpful? Yes | No

    Default

    Hi all, Thanks again..
    @Steve: could you please share your sony 12 project also..
    @ Aratti: i m not good with assembly language.. Really appreciate some basic code.
    Mean while i have found some code,it worked out as what i expected but its for proton IDE...and also i tried to convert in PBP..no success.
    Site: http://www.picbasic.nl/indexes_uk.htm
    Projects / 10outputs and univarsal rc5 etc..

  8. #8
    Join Date
    Jan 2009
    Location
    California, USA
    Posts
    323


    Did you find this post helpful? Yes | No

    Default

    Here's my bit of test code that displays on an LCD which button is pressed on my remote. This is for the Sony 12 bit format.

    Much of the code was simply stolen from this page "Controlling the world from your armchair":
    http://www.picbasic.co.uk/support/Article.pdf

    --------------------------------

    Code:
    'Test program for 16F727 with IR sensor (PNA4612M)
    
    '****************************************************************
    
    Include "MODEDEFS.BAS"   ' Include Shiftin/out modes
    DEFINE LCD_DREG PORTD    ' Set LCD Data port
    DEFINE LCD_DBIT 4        ' Set starting Data bit (0 or 4) if 4-bit bus
    DEFINE LCD_RSREG PORTC   ' Set LCD Register Select port
    DEFINE LCD_RSBIT 5       ' Set LCD Register Select bit
    DEFINE LCD_EREG PORTC    ' Set LCD Enable port                                                   
    DEFINE LCD_EBIT 6        ' Set LCD Enable bit
    DEFINE LCD_BITS 4        ' Set LCD bus size (4 or 8 bits)
    'DEFINE ADC_BITS 8        ' Set number of bits in ADC result
    'DEFINE ADC_CLOCK 3       ' Set clock source for ADC (rc = 3)
    'DEFINE ADC_SAMPLEUS 100  ' Set ADC sampling time in microseconds 
    DEFINE OSC 8             ' 8 MHz Osc.
    define I2C_SCLOUT 1      ' Set I2C Clock to drive high instead of needing pullup
    
    
    '?????????????????????????????????????????????????????????????????
    
    @  __config _CONFIG1, _DEBUG_OFF & _PLL_EN & _BORV_2_5 & _BOR_ON & _CP_OFF & _MCLRE_OFF & _PWRT_EN & _WDT_ON & _INTOSCIO
    @  __config _CONFIG2, _VCAP_RA6
    
    OSCCON = %00100000             'Set Osc to 8MHz.
    OPTION_REG = %10101111
    CPSCON0.0 = 1
    
    TRISA= %00000000    'Set 'em all to outputs
    TRISB= %11111111	'Set portB to inputs
    TRISC= %00000000    'Set portC all outputs
        
    ANSELA= %00000000	 ' Set all pins to digital...
    ANSELB= %00000000   ' Set all pins to digital 
    ADCON0 = %00100001
    '??????????????????????????????????????????????????????????????????????
    
    ' Alias pins - LCD
    backlight var   PORTC.2  'LCD backlight
    RW       var    PORTC.7  'LCD R/W
    
    'Alias pins - I.R. Input
    IRinput  var     PORTB.0
    
    'Allocate IR Sensor variables
    Bitcnt      var     byte    'Loop counter
    Header      var     Word    'Hold the length value of the first PULSIN to check for header.
    P_Val       var     word    'Hold the length value of each consecutive bit in it's turn.
    Packet      var     word    'Stores the raw code built up from 12 cycles of counting P_Val
    IR_Dev      var     byte    'Stores the code # for the DEVICE being addressed (decoded from Packet)
    IR_But      var     Byte    'Stores the code # for the BUTTON pressed. (decoded from Packet)
    clear
    
    pause 200  'Give the LCD a chance to wake up
    Lcdout $fe,1 'reset LCD
    HPWM 1,127,200  'Set the backlight brightness
    LCDOUT $fe,2, "    test"   'print "test" and pause for a second.
    pause 1000
    LCDOUT $fe,1            'clear the display
    
    
    ' Receive a signal from a Sony remote control,
    ' and return with the 7-bit BUTTON code in the variable
    ' IR_BUT and the 5-bit DEVICE code in the variable IR_DEV.
    ' If no header then IR_DEV, IR_BUT will hold 255
    
    ' MAIN PROGRAM LOOP
    Again:       
        Gosub IRIN ' Receive an IR signal
        If IR_Dev=255 then goto Again ' Check for valid header
        If IR_Dev=0 then goto Again ' If not a valid device code then look again
        If IR_But=0 then LCDOUT $fe,2,  "0, Channel 1      "
        If IR_But=1 then LCDOUT $fe,2,  "1, Channel 2      "
        If IR_But=2 then LCDOUT $fe,2,  "2, Channel 3      "
        If IR_But=3 then LCDOUT $fe,2,  "3, Channel 4      "
        If IR_But=4 then LCDOUT $fe,2,  "4, Channel 5      "
        If IR_But=5 then LCDOUT $fe,2,  "5, Channel 6      "
        If IR_But=6 then LCDOUT $fe,2,  "6, Channel 7      "
        If IR_But=7 then LCDOUT $fe,2,  "7, Channel 8      "
        If IR_But=8 then LCDOUT $fe,2,  "8, Channel 9      "
        If IR_But=9 then LCDOUT $fe,2,  "9, Channel 0      "
        If IR_But=11 then LCDOUT $fe,2, "11 Enter          "
        If IR_But=14 then LCDOUT $fe,2, "14 Guide          "         
        If IR_But=16 then LCDOUT $fe,2, "16 Channel Up     "
        If IR_But=17 then LCDOUT $fe,2, "17 Channel Down   "
        If IR_But=18 then LCDOUT $fe,2, "18 Volume  Up     "
        If IR_But=19 then LCDOUT $fe,2, "19 Volume Down    "
        If IR_But=20 then LCDOUT $fe,2, "20 Mute           "
        If IR_But=21 then LCDOUT $fe,2, "21 Power          "
        If IR_But=37 then LCDOUT $fe,2, "37 TV/VCR input   "
        If IR_But=42 then LCDOUT $fe,2, "42 Record         "
        If IR_But=51 then LCDOUT $fe,2, "51 Right          "    
        If IR_But=52 then LCDOUT $fe,2, "52 Left           "
        If IR_But=54 then LCDOUT $fe,2, "54 Sleep          "
        If IR_But=58 then LCDOUT $fe,2, "58 Info           "
        If IR_But=59 then LCDOUT $fe,2, "59 Repeat         "
        If IR_But=64 then LCDOUT $fe,2, "64 Play           "
        If IR_But=65 then LCDOUT $fe,2, "65 Pause           "
        If IR_But=67 then LCDOUT $fe,2, "67 Scan +         "
        If IR_But=68 then LCDOUT $fe,2, "68 Scan -         "
        If IR_But=77 then LCDOUT $fe,2, "77 Stop           "
        If IR_But=91 then LCDOUT $fe,2, "91 PIP Toggle     "
        If IR_But=95 then LCDOUT $fe,2, "95 PIP Swap       "
        If IR_But=96 then LCDOUT $fe,2, "96 Menu, Quit     "
        If IR_But=101 then LCDOUT $fe,2,"101 Select        "    
        If IR_But=116 then LCDOUT $fe,2,"116 Channel Up    " 
        If IR_But=117 then LCDOUT $fe,2,"117 Channel Down  "
        Goto Again ' Repeat until nauseated...
    
    IRIN:     
        IR_Dev=255:IR_But=255 ' Preset the Return variables
        Pulsin IRinput,0,Header ' Measure the header length.
        If Header < 450 then Return' If the result is less than 450 toss it out
        If Header > 520 then Return' If the result is greater than 520 toss it out  
    ' Receive the 12 data bits and convert them into a packet
        For Bitcnt=0 to 11 ' Create a loop of 12
        Pulsin IRinput,0,P_Val ' Receive the IR pulses
        If P_Val >= 190 then ' If >= 190 then we've received a 1
            Packet.0[Bitcnt]=1 ' So set the appropriate bit
            Else
            Packet.0[Bitcnt]=0 '...or clear the appropriate bit
        Endif
        Next 
        
        IR_But=Packet & %01111111 'Extract the 7 BUTTON bits
        IR_Dev=(Packet >>7) & %00011111 'Right shift and extract the 5 DEVICE bits    
        lcdout $fe,1, dec IR_But, "     ", $fe,$c0, dec IR_Dev, "   ", dec header    
    return 
        
       end
    ----

    steve

  9. #9
    Join Date
    Sep 2006
    Posts
    42


    Did you find this post helpful? Yes | No

    Default

    Many Thanks,
    Shall give it a try...

Similar Threads

  1. Elapsed Timer Demo
    By Darrel Taylor in forum Code Examples
    Replies: 111
    Last Post: - 29th October 2012, 18:39
  2. High Resolution Timer & Speed Calculator
    By WOZZY-2010 in forum Code Examples
    Replies: 4
    Last Post: - 7th February 2010, 17:45
  3. Timer interrupt frequency
    By Samoele in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 18th January 2009, 00:49
  4. dual 7-segment countdown timer code
    By dr.ragh in forum mel PIC BASIC Pro
    Replies: 15
    Last Post: - 30th April 2007, 14:19
  5. timer interupt help 16f73
    By EDWARD in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 3rd July 2005, 09:41

Members who have read this thread : 1

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