Shop OBEX P1 Docs P2 Docs Learn Events
Setting output bits in Pasm — Parallax Forums

Setting output bits in Pasm

Hello readers of the forum.

I have a question about setting output bits in Pasm. When i set or reset 1 bit I use the example in Part_1 of my code snippet below. But when I want to set more bit's, but stil not touch other bit's, I use the code snippet of Part_2. Are I am right, is this the right way or is there an other way to set/reset for example a nibble to the output pin's in Pasm.

Greeting Abraham
dat

'example data = %00000000_00000000_00001010_00000000 or %00000000_00000000_00001101_00000000 

Start         mov       dira,   Pin_out         ' Set the output's   

Part_1        or        outa,   Clk_2           ' Set a bit
              andn      outa,   Clk_2           ' Reset a bit

Part_2        andn      outa,   mask_nibb       ' Clear a nibble
              or        outa,   data            ' Set data nibble

Pin_out    long         %00000000_00011111_11111111_00000000 
Clk_2      long         %00000000_00010000_00000000_00000000     
mask_nibb  long         %00000000_00000000_00001111_00000000

Comments

  • ElectrodudeElectrodude Posts: 1,657
    edited 2016-08-22 17:56
    That's the usual way to do it on the P1.

    You can also use "or" and "andn" to modify dira if you need to change pin directions at runtime, but a "mov dira, whatever" is fine for setup.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2016-08-22 18:49
    Your Part_2 code will cause a glitch on the pins you're trying to change. If that's not acceptable, you can do this instead:
    Part_2        mov       temp,outa
                  andn      temp,mask_nibb       ' Clear a nibble
                  or        temp,data            ' Set data nibble
                  mov       outa,temp
    

    -Phil
  • Your Part_2 code will cause a glitch on the pins you're trying to change. If that's not acceptable, you can do this instead:
    Part_2        mov       temp,outa
                  andn      temp,mask_nibb       ' Clear a nibble
                  or        temp,data            ' Set data nibble
                  mov       outa,temp
    

    -Phil

    Phil.

    Thanks for this suggestion. I go use it.

    Abraham.
  • Phil:

    Thanks for pointing out the glitching problem with the original Part_2 code. That pointed out a fastspin bug; the optimizer wasn't special casing OUTA or DIRA, and so the code generated did look like that original one. I've added a special case for OUTA[a..b] and DIRA[a..b] to use the second form, so it's fixed in fastspin 3.1.2.

    Eric
Sign In or Register to comment.