Shop OBEX P1 Docs P2 Docs Learn Events
How to send one bit at a time — Parallax Forums

How to send one bit at a time

QAHQAH Posts: 13
edited 2009-07-16 05:21 in BASIC Stamp
Hello all! I am using the Basic Stamp 2 homework board and I would like to know, how can I output 1 bit at a time of a 16 bit word variable? I know how to use SHIFTOUT, but that sends all of the data. I need to send data, wait for an input pulse and if it gets it, send another bit. Can this be done? If so, how?

Thanks

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2009-07-15 23:25
    You can access the individual bits of a variable by treating it as a bit array. Say you have a 16 bit variable called FOO declared "FOO VAR WORD". You can reference the individual bits by writing "FOO.BIT(i)" where "i" is a value from 0 to 15 (for the number of the bit).

    Let's say you have your I/O pin defined as "SIGNAL PIN 6". You can have a FOR / NEXT loop that does "SIGNAL = FOO.BIT(i)" then waits for your input pulse before going on to the next bit.
  • Ron CzapalaRon Czapala Posts: 2,418
    edited 2009-07-15 23:58
    Mike,
    ·Actually you get "Expected a variable modifier"· using FOO.BIT(I) -·you need to reference FOO.BIT0(i) or .... BIT15(i)


    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    
     
    FOO VAR Byte
    i VAR Nib
    FOO = %11001001
     
    FOR i = 7 TO 0
      DEBUG BIN1 FOO.BIT0(i)
    NEXT
    




    Post Edited (ronczap) : 7/16/2009 12:50:57 AM GMT
  • Mike GreenMike Green Posts: 23,101
    edited 2009-07-16 00:50
    Sorry, I didn't really try it. Try this instead: FOO.BIT0(i)

    Look at the BASIC Stamp Syntax and Reference Manual, pages 85-91.
  • QAHQAH Posts: 13
    edited 2009-07-16 05:21
    Ok. Thanks for that info guys. I have another question reguarding bits. I will ask it here instead of creating an new thread. I am trying to get data from an N64 controller. On a diagram page it said that the controller sends out bits up to 4us wide. Is there a way I can set to recive data from a pulse that quick?

    Thanks
Sign In or Register to comment.