IR Counter


Closed Thread
Results 1 to 13 of 13

Thread: IR Counter

Hybrid View

  1. #1
    Join Date
    May 2009
    Posts
    4


    Did you find this post helpful? Yes | No

    Default

    Thanks again for your help Dave. I pretty much used your RF receiver code and modified it for use with the IR signal. Here is the code I used on an 16F84A with a 4 MHz crystal. I used it to test if the channel up button was pressed on the remote.

    Code:
    define PULSIN_MAX 968
    
    IRPIN           var     PORTB.0
    LED             var     PORTB.1
    LED2            var     PORTB.2
    RF              var     byte[4]
    Header          var     word
    PULSE_LENGTH    var     byte
    i               var     byte
    
    INIT:   RF[0]=0
            RF[1]=0
            RF[2]=0
            RF[3]=0
            i=0
            Pulsin IRPIN, 0, Header
            if (Header < 792) then INIT
            while irpin = 0:wend
            repeat
                pulsin IRPIN, 1, PULSE_LENGTH
                if (PULSE_LENGTH < 40) or (PULSE_LENGTH > 175) then INIT
                if (PULSE_LENGTH > 90) then 
                    RF.0(i) = 1
                else
                    rf.0(i) = 0
                endif
                i=i+1
            until (i>31)
            if (RF[3]=230) then 
            high LED
            pause 500
            low LED
            else
            high LED2
            pause 500
            low LED2
            endif
            goto INIT
    end
    I get LED to go high when I press the channel up button.

    It took me awhile to figure out how the data was arranged in the array. I started out using RF[0]=10 to light LED, but kept getting LED2 to light up. So, I thought there was something screwed up with the values pulsin was generating. Finally, I read through the FAQ on arrays and figured out my problem. I used RF[0]=80 and got LED to light up. However, LED would light up with any button I pushed since all the buttons used the same starting code. So, I ended up using RF[3] to test if channel up was pressed.

    Is testing RF[3] going to be the best way to determine which button is pushed? I plan to use channel up/channel down for one team and volume up/volume down for the other team.

  2. #2
    Join Date
    Dec 2005
    Posts
    1,073


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by partime View Post
    Is testing RF[3] going to be the best way to determine which button is pushed? I plan to use channel up/channel down for one team and volume up/volume down for the other team.
    The way most use this protocol, RF[0] indicates a device (e.g. TV, CD player) and RF[2] indicates a button (e.g. number, Vol+). RF[1] is the bitwise complement of RF[0] and RF[3] is the bitwise complement of RF[2]. So, you are probably safe using either RF[2] or RF[3].

    I would suggest a change...
    Code:
            while irpin = 1:wend
    That merely waits until the initial space part of the header passes. With RF I found that was necessary.

  3. #3
    Join Date
    Dec 2005
    Posts
    1,073


    Did you find this post helpful? Yes | No

    Default

    Also, since the array elements are reset to zero at the top of the loop, you can simplify this...
    Code:
                if (PULSE_LENGTH > 90) then 
                    RF.0(i) = 1
                else
                    rf.0(i) = 0
                endif
    to this...
    Code:
                if (PULSE_LENGTH > 90) then 
                    RF.0(i) = 1
                endif
    And, while errors are less likely with IR, you can detect them buy adding RF[2] and RF[3]. They should always sum to 255 or $FF.
    Last edited by dhouston; - 3rd June 2009 at 13:40.

Similar Threads

  1. Conway's Game Of Life
    By wellyboot in forum mel PIC BASIC Pro
    Replies: 45
    Last Post: - 28th May 2020, 07:14
  2. Replies: 17
    Last Post: - 12th April 2014, 03:17
  3. 20 Digit Virtual LED Counter
    By T.Jackson in forum Code Examples
    Replies: 9
    Last Post: - 19th November 2007, 06:02
  4. PIC10F200 Automated IR Light Switch
    By Bruce in forum Code Examples
    Replies: 7
    Last Post: - 3rd May 2007, 12:40
  5. Microcontroller with 2 way paging application problem
    By oneohthree in forum mel PIC BASIC Pro
    Replies: 30
    Last Post: - 20th April 2007, 18:27

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