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 2 arrays defined in the #include file 

      DIM shiftValues(MAXshiftARRAY)  ' values to be shifted in or out

      DIM shiftCounts(MAXshiftARRAY)

While most other hardware functions use bytes, SHIFTIN is oriented for bit control.  The shiftCounts of each shiftValues defines the number of bits that will be shifted out (1 - 32).  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

shiftValues(0) = 2
shiftCounts(0) = 3

shiftValues(1) = $1b
shiftCounts(1) = 5

shiftValues(2) = y
shiftCounts(2) = 8

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

shiftValues(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 = shiftValues(0)
io(6)=1



Differences from other BASICs

See also