Shop OBEX P1 Docs P2 Docs Learn Events
PropBasic - ina[8..15] — Parallax Forums

PropBasic - ina[8..15]

camelot2camelot2 Posts: 54
edited 2010-03-30 02:14 in Propeller 1
hi, what I want to do is read the input register, P8 thru P15,
and assign it to a variable like in spin·· value := ina[noparse][[/noparse]8..15]
·
How can I do this in PropBasic ??· thanks

Comments

  • Gerry KeelyGerry Keely Posts: 75
    edited 2010-03-29 13:35
    I think all you need do is

    Pins PIN 8..15 INPUT
    value·var long

    Program Start
    Start:
    value·=Pins
    ·END

    Gerry
  • JonnyMacJonnyMac Posts: 9,235
    edited 2010-03-29 19:27
    Keep in mind that the order of your declaration affects the value you will get back from the pins -- be mindful of the LSB pin and MSB pin assignments. For example:

    Switch          PIN     7..0
    



    and...

    Switch          PIN     0..7
    



    ... have the LSB and MSB pins reversed, so having %00001111 on P7..P0 will return $0F with the first declaration, but $F0 with the second due to the reversal. As with Spin, this can be a useful feature.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon McPhalen
    Hollywood, CA
  • camelot2camelot2 Posts: 54
    edited 2010-03-29 19:48
    thanks Gerry and JonneyMac for the replies. I tried it but it
    needs 16 ticks of the system clk. If I use value1 = ina then
    only 4 ticks are needed but then I have to apply a mask to get
    the desired bits. I want to use this 100 times to accumalate
    ADC data which would require variables value1 thru value100. Any
    thoughts as how to do this will be appreciated
  • JonnyMacJonnyMac Posts: 9,235
    edited 2010-03-30 02:14
    Use inline assembly if speed is a concern. Remember, compilers must be generalized and will not always give us the results we would hand-code.

    ASM
        mov     __temp1, ina
        shr     __temp1, #8
        and     __temp1, #$FF
      ENDASM
    


    At the end of this routine __temp1 holds the bits you seek; you can mix this into your PropBASIC code.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon McPhalen
    Hollywood, CA
Sign In or Register to comment.