Shop OBEX P1 Docs P2 Docs Learn Events
How do I setup DIRA when pins are scattard around? — Parallax Forums

How do I setup DIRA when pins are scattard around?

xsmokerxsmoker Posts: 9
edited 2008-04-04 05:17 in Propeller 1
I need to have pins that are not grouped together set as output for a byte. I need P9,10,11,15,24,25,28,29 set with DIRA command with P9 the lowbit. How would I use the DIRA command with staggard pins?

Thanks,

X

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2008-04-04 04:38
    You can't do it directly. You'll have to shift the bits into position and use XOR (^) if you want to change all the bits at the same time. Since you sound like you want to just set them for output, you can just use a logical OR (|) with a constant like:

    DIRA |= %00_11_00_11_00000000_1_000_111_000000000
  • xsmokerxsmoker Posts: 9
    edited 2008-04-04 05:07
    Thanks Mike, One more ??

    Ok, that works for DIRA, but how about for OUTA? How do I get data from a variable out to these pins? Unfortunately I'm using all the pins so I can't just group them together.

    In other words, I can't use:
    outa[noparse][[/noparse]29,28,25,24,15,11,10,9]:= data
    

    Post Edited (xsmoker) : 4/4/2008 5:12:22 AM GMT
  • Mike GreenMike Green Posts: 23,101
    edited 2008-04-04 05:17
    Like I said, you'll have to shift the bits into position in a 32 bit value. You should extract the "current" value in OUTA using the bitmask above and XOR it with the new bits. Take that result and XOR it with OUTA. You can do this all in one statement if you want.

    If an OUTA bit is 1 and you want to change it to 0, OUTA = OLD ^ (OLD ^ NEW) = 1 ^ (1 ^ 0) = 0

    If an OUTA bit is 0 and you want to change it to 1, OUTA = OLD ^ (OLD ^ NEW) = 0 ^ (0 ^ 1) = 1

    If an OUTA bit is 1 and it's to be left unchanged, OUTA = OLD ^ (OLD ^ NEW) = 1 ^ (1 ^ 1) = 1

    If an OUTA bit is 0 and it's to be left unchanged, OUTA = OLD ^ (OLD ^ NEW) = 0 ^ (0 ^ 0) = 0

    See if you can work out the Spin statement for the whole thing.
Sign In or Register to comment.