SHIFTIN
 
Syntax


#include <SHIFT.bas>                             ' source in /Program Files/Coridium/BASIClib

SUB SHIFTIN (INpin, CLKpin, LSBfirst, cnt)   

Description


SHIFTIN can be used for devices that are not covered by SPI, I2C or 1-Wire.  Data is shifted in on INpin, and a positive clock is sent on CLKpin for each bit.

Data and shift counts are stored in 3 arrays defined in the #include file 

      DIM listIN(MAXshiftARRAY)       ' values to be shifted in
      DIM listOUT(MAXshiftARRAY)    ' values to be shifted out

      DIM shiftCounts(MAXshiftARRAY)

While most other hardware functions use bytes, SHIFTIN is oriented for bit control.  The shiftCounts defines the number of bits that will be shifted in (1 - 32) for each element of the listOUT array.  If a shiftCounts is 0, it is assumed to be 8. 

Data is shifted in at 300 Kbits/sec.


Example

#include <SHIFT.bas>
 '...

' use SHIFTIN/OUT to control an SPI EN28J60 connected on pins 3,4 -- 6 as CS

listOUT(0) = 2
shiftCounts(0) = 3

listOUT(1) = &H1b
shiftCounts(1) = 5

listOUT(2) = y
shiftCounts(2) = 8

io(6)=0                    ' used asCS
shiftout (3,4,1,3)       ' set reg &H1B to y
io(6)=1

listOUT(0) = reg
shiftCounts(0) = 8

io(6)=0
shiftout (3,4,1,1)                     'select the register
shiftin (5,4,0,1)                       'and read it back
x = listIN(0)
io(6)=1



Differences from other BASICs

See also