Shop OBEX P1 Docs P2 Docs Learn Events
sending serial data, bit by bit, to a specific pin in pasm — Parallax Forums

sending serial data, bit by bit, to a specific pin in pasm

Yes, I know this is a beginner question, but my brain locked up

in pasm, I have a long with various bits

test_bit_mask long %10101010_11110001_11110000_11110001

and I want to send this to a specific pin on the prop1 (in pasm), which happens to be what I am using, one bit at a time, shifting right to left

so the output to the pin would go

1,0,1,0,1,0,10,1,1,1,1,0,0,0,0,1,1,1,1,0,0,0,0,1,1,1,1,0,0,0,1

say for example my pin that I want to send the data to is pin 15,

:Pin_looper xor outa, pin_15 'toggle pin 15
djnz pin_length, #:Pin_looper 'return to caller pin_length is set to 32, the xor simply toggles the pin

but if I want to send a random set of bits to the pin, I don't know

it would be something like: (in c ish)
array_of_bits long {1,0,1,0,1,0,10,1,1,1,1,0,0,0,0,1,1,1,1,0,0,0,0,1,1,1,1,0,0,0,1}

for (int i= 0;i<32;i++)
pin15 = array_of_bits[i]

I'm thinking it has something to do with
test pinMask, ina wc
rcl readbit,#1

any help would be appreciated, if this has already been done a million times, a link would be fine.

thank you

Jeff

Comments

  • I may have explained this wrong, the output of the above bitmask (1,0,1,0,1,0,1,0,1,1,1,1,0,0,0,0,1,1,1,1,0,0,0,0,1,1,1,1,0,0,0,1)

    would be on the pin as
    High,low,high,low,high,low,high,low,high,high,high,high,low,low,low,low,high,high,high,high,low,low,low,high

    currently it looks like this, (since it is xor'ed)

    Jeff

  • AribaAriba Posts: 2,690
    edited 2022-05-04 21:21

    This can be done with the help of the Carry flag. The shift instructions can shift the bits into the Carry, and there is the MUXC instruction to set specific bits in a register to the state of the Carry. If this register is OUTA, you set port bits.

               or     dira, portbitmask          'set port pin to output
               mov    bitcounter, #32
    
    pin_loop   shl    test_bit_mask, #1   wc      'shift left by 1, shifted out bit goes into Carry Flag
               muxc   outa, portbitmask           'set pin (15 here) to the state of the Carry Flag
               djnz   bitcounter, #pin_loop
    
    
    test_bit_mask  long   %10101010_11110001_11110000_11110001
    portbitmask    long   1<<15                   'bit mask for pin 15
    
    bitcounter     long   0
    

    Andy

  • works nicely, thanks

    Here is the data:
    test_bit_mask long %10000001_01111110_11110001_11001100

Sign In or Register to comment.