Timer + rc5


Closed Thread
Results 1 to 9 of 9

Thread: Timer + rc5

Hybrid View

  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..

Similar Threads

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