Multiple IR Receivers


Closed Thread
Results 1 to 9 of 9

Hybrid View

  1. #1
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    It may be reading one, then executing the GOTO and then continues
    to execute below the if thens and repeats at the GoTo STARTPULSE.
    <br>
    I would make the GOTOs into gosubs with returns, so the code will return
    to the next line which is the next sensor.
    Code:
    INCLUDE "modedefs.bas"
    CMCON = 7
    trisio = %00001111
    GPIO = 0
    DEFINE OSCCAL_1K 1 ' Set OSCCAL for 1K device
    Define OSC 4
    @ DEVICE PIC12f629, XT_OSC
    @ DEVICE PIC12f629, WDT_ON
    @ DEVICE PIC12f629, PWRT_ON
    @ DEVICE PIC12f629, MCLR_OFF
    @ DEVICE PIC12f629, BOD_ON
    @ DEVICE PIC12f629, CPD_OFF
    CODELENGTH VAR BYTE 'BYTE VARIABLE OK - LESS THAN 8 PULSES MEASURED
    UID VAR BYTE
    PIN VAR BYTE
    RXPIN1 Var GPIO.3
    
    Pause 100 'SETTLE DOWN BOTH PIC & IR RECEIVER
    
    STARTPULSE:
    PulsIn GPIO.3,0,CODELENGTH 'MEASURE LOW PULSE (IR LED ON TIME)
    IF (CODELENGTH > 200) and (CODELENGTH < 400) Then SENSOR1
    goto STARTPULSE
    
    SENSOR1:
    RXPIN1 = GPIO.3
    pin = 1
    GOSUB CODEPULSES
    
    SENSOR2:
    RXPIN1 = GPIO.2
    pin = 2
    GOSUB CODEPULSES
    
    CODEPULSES:
    PulsIn RXPIN1,0,CODELENGTH
    IF CODELENGTH > 150 Then LET UID.bit0 = 1 '2MS PULSE IS 1
    IF CODELENGTH < 150 Then LET UID.bit0 = 0 '1MS PULSE IS 0
    
    PulsIn RXPIN1,0,CODELENGTH
    IF CODELENGTH > 150 Then LET UID.bit1 = 1
    IF CODELENGTH < 150 Then LET UID.bit1 = 0
    
    PulsIn RXPIN1,0,CODELENGTH
    IF CODELENGTH > 150 Then LET UID.bit2 = 1
    IF CODELENGTH < 150 Then LET UID.bit2 = 0
    
    PulsIn RXPIN1,0,CODELENGTH
    IF CODELENGTH > 150 Then LET UID.bit3 = 1
    IF CODELENGTH < 150 Then LET UID.bit3 = 0
    
    PulsIn RXPIN1,0,CODELENGTH
    IF CODELENGTH > 150 Then LET UID.bit4 = 1
    IF CODELENGTH < 150 Then LET UID.bit4 = 0
    
    PulsIn RXPIN1,0,CODELENGTH
    IF CODELENGTH > 150 Then LET UID.bit5 = 1
    IF CODELENGTH < 150 Then LET UID.bit5 = 0
    
    PulsIn RXPIN1,0,CODELENGTH
    IF CODELENGTH > 150 Then LET UID.bit6 = 1
    IF CODELENGTH < 150 Then LET UID.bit6 = 0
    
    PulsIn RXPIN1,0,CODELENGTH
    IF CODELENGTH > 150 Then LET UID.bit7 = 1
    IF CODELENGTH < 150 Then LET UID.bit7 = 0
    
    IF UID = 247 Then
     GOSUB LEDON
    ENDIF
    codelength = 0
    UID = 0
    RETURN
    
    GoTo STARTPULSE
    
    LEDON:
    High GPIO.0 'LED ON
    serout 1, N2400,[#PIN," ",#UID,10,13]
    Pause 500
    Low GPIO.0
    codelength = 0
    UID = 0
    GoTo STARTPULSE
    
    End
    Last edited by Archangel; - 6th September 2008 at 07:33.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

Similar Threads

  1. Replies: 17
    Last Post: - 12th April 2014, 02:17
  2. Plz help in completing RC-5 IR remote lamp dimmer project
    By vu2iia in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 3rd April 2008, 08:44
  3. PIC10F200 Automated IR Light Switch
    By Bruce in forum Code Examples
    Replies: 7
    Last Post: - 3rd May 2007, 11:40
  4. how to get pic to pic communication
    By kinsiro in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 30th August 2005, 17:12
  5. Multiple IR LEDs from 1 port using transistor
    By belpe123 in forum General
    Replies: 3
    Last Post: - 20th May 2005, 22:07

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