1. Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
    Dismiss Notice

InfraRed in Pic simulator

Discussion in 'Oshonsoft' started by gold94, Aug 27, 2014.

  1. gold94

    gold94 New Member

    Joined:
    Jun 10, 2014
    Messages:
    11
    Likes:
    0
    Location:
    Paris
    hello

    I want to convert this code:
    http://www.picbasic.co.uk/forum/showthread.php?t=15413
    pulsin but does not exist in pic simulator ide
    This code allows the reception and decoding of an infrared signal

    thank you

    Thierry

    PS : Sorry for my bad english (Google Translation) ;)
     
  2. leftfield95

    leftfield95 Member

    Joined:
    Aug 5, 2008
    Messages:
    71
    Likes:
    2
    Location:
    lincs, UK
    I think for the application you are converting to oshonsoft picbasic, the following should work

    servoin GPIO.3,start
    servoin GPIO.3,pulse[counter]

    'servoin' can only count in 'bytes', and not 'words' like 'pulsin'.
    But for this application this limitation does not matter, since 'start' and 'pulse' are declared as bytes.
     
  3. jjw

    jjw Member

    Joined:
    Apr 16, 2012
    Messages:
    270
    Likes:
    15
    Location:
    Helsinki, Finland
    You could use almost directly the second example in the thread for reading Philips RC5 protocol.
    Just read the state of an input, for example: IF GPIO.3=1 THEN ....
    and add correct delay statements ( Waitus x )
     
  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. gold94

    gold94 New Member

    Joined:
    Jun 10, 2014
    Messages:
    11
    Likes:
    0
    Location:
    Paris

    Hello,
    thank you for your answer it advance a little, the two solutions me always give the same values. except for some keys data 118 id 28

    My code
    Code (text):
    '// SONY SIRC IR decoder

    Define CONF_WORD = 0x3f72
    Define CLOCK_FREQUENCY = 4
    Define COUNT_MODE = 2
    Define LCD_BITS = 8
    Define LCD_DREG = PORTD
    Define LCD_DBIT = 0
    Define LCD_RSREG = PORTB
    Define LCD_RSBIT = 5
    Define LCD_RWREG = PORTB
    Define LCD_RWBIT = 4
    Define LCD_EREG = PORTB
    Define LCD_EBIT = 3
    Define LCD_READ_BUSY_FLAG = 1
    Define COUNT_MODE = 2
    Lcdinit
    'Define SIMULATION_WAITMS_VALUE = 0
    Dim a As Byte
    Dim y(12) As Byte  'Holds 12-bit SIRC code
    Dim loop As Byte  'Loop variable
    Dim data As Byte
    Dim id As Byte
    Symbol pin = PORTB.0  'RB.0 input pin reading data

    TRISB.0 = 1  'Set RB.0 direction to input
    OPTION_REG.7 = 0  'Internal pull-ups = on

    home:
    If pin = 1 Then Goto home  'Wait for low going pulse
    WaitUs 100  'Short delay
    If pin = 1 Then Goto home  'Was it noise?
    WaitUs 2400  'Pause to read 2nd half of 1st bit period
    WaitUs 600
    For loop = 11 To 0 Step -1  '12 pulses MSB to LSB
    Count pin, 3, y(loop)
    WaitUs 600
    Next loop  'in middle of 2nd bit period

    If y(11) > 1 Then
    id.7 = 1
    Else
    id.7 = 0
    Endif
    If y(10) > 1 Then
    id.6 = 1
    Else
    id.6 = 0
    Endif
    If y(9) > 1 Then
    id.5 = 1
    Else
    id.5 = 0
    Endif
    If y(8) > 1 Then
    id.4 = 1
    Else
    id.4 = 0
    Endif
    If y(7) > 1 Then
    id.3 = 1
    Else
    id.3 = 0
    Endif

    If y(6) > 1 Then
    data.6 = 1
    Else
    data.6 = 0
    Endif
    If y(5) > 1 Then
    data.5 = 1
    Else
    data.5 = 0
    Endif
    If y(4) > 1 Then
    data.4 = 1
    Else
    data.4 = 0
    Endif
    If y(3) > 1 Then
    data.3 = 1
    Else
    data.3 = 0
    Endif
    If y(2) > 1 Then
    data.2 = 1
    Else
    data.2 = 0
    Endif
    If y(1) > 1 Then
    data.1 = 1
    Else
    data.1 = 0
    Endif
    If y(0) > 1 Then
    data.0 = 1
    Else
    data.0 = 0
    Endif


    'If y.LB = $ff Then Goto home  'Was it noise?
    'y = ~y & $003f  'Mask upper 10-bits to return 6-bit data
    'in lower 6-bits of word result
    'Hserout ["Key Pressed = ", dec y, 13, 10]
    'y = 0  'Clear key codes
    'pause 250  'Used for testing only

    Lcdcmdout LcdClear
    'For a = 11 To 0 Step -1
    Lcdout #data, " ", #id
    'Next a
    WaitMs 5000
    Lcdcmdout LcdClear

    Goto home  'Return Home
    thank you for your help

    Thierry

    PS: Sorry for my bad english (google translate);)
     
    Last edited: Aug 31, 2014

Share This Page