Ben Kirkpatrick - 2010-07-25

I realize I'm 3+ years late with the answer… but I found a problem in ShiftIn code above…  the BIT type isn't needed.  The below code can do ShiftIn LSB_first or MSB_first.  I've done more testing on the MSB_first, but they should be very similar.

Function ShiftIn(Mode)
   Dim ReceiveData as Byte  
   ReceiveData = 0 'Set Receive Data to 0
    Set DataPin off
    Dir DataPin in
        Set ClkPin off
    Dir ClkPin out
    If Mode = 1 Then
       '-- LSB first; sample bits before clock pulse
       Set ClkPin off
                         Wait 1 us
       For clocks = 1 to 8
              Rotate ReceiveData Right
              ReceiveData.0 = Datapin
          Wait 1 us
              Set ClkPin on
          Wait 1 us
          Set ClkPin off
       Next
    End If  
    If Mode = 2 Then
       '-- MSB first; sample bits before clock pulse
           Set ClkPin off
              Wait 1 us
       For clocks = 1 to 8
              Rotate ReceiveData Left
          ReceiveData.0 = Datapin
          Wait 1 us
          Set ClkPin on
          Wait 1 us
          Set ClkPin off
       Next
    End If  
    'Return value
    ShiftIn = ReceiveData
End function