SHIFTIN and SHIFTOUT
Action

Shifts a bit stream in or out a variable.

Syntax

SHIFTIN pin , pclock , var , option [PRE]

SHIFTOUT pin , pclock , var , option

Remarks

pin The port pin which serves as input/output.
pclock The port pin which generates the clock.
var The variable that is assigned.
option Option can be :
0 - MSB shifted in/out first when clock goes low
1 - MSB shifted in/out first when clock goes high
2 - LSB shifted in/out first when clock goes low
3 - LSB shifted in/out first when clock goes high
For the SHIFTIN statement you can add 4 to the parameter to use the external clock signal for shifting.
PRE Add this additional parameter (no comma) to sample the input pin before the clock signal is generated.
It depends on the type of the variable, how many shifts will occur.
When you use a byte, 8 shifts will occur and for an integer, 16 shifts will occur.

See also


Example


Dim a as byte
SHIFTIN P1.0 , P1.1 , a , 0
SHIFTOUT P1.2 , P1.1 , a , 0

'For the SHIFTIN example the following code is generated:
Setb P1.1
Mov R0,#h'21
Mov r2,#h'01
__UNQLBL1:
Mov r3,#8
__UNQLBL2:
Clr P1.1
Nop
Nop

Mov c,P1.0
Rlc a
Setb P1.1
Nop
Nop
Djnz
r3,__UNQLBL2

Mov @r0,a
Dec r0
Djnz r2,__UNQLBL1

Of course, it depends on the parameter, which code will be generated.
To shift with an external clock signal:

SHIFTIN P1.0, P1.1 , a , 4 'add 4 for external clock

Generated code:

Mov R0,#h'21
Mov r2,#h'01
__UNQLBL1:
Mov r3,#8
__UNQLBL2:
Jnb P1.1,*+0
Mov c,P1.0
Rlc a
Jb
P1.1,*+0
Djnz r3,__UNQLBL2
Mov @r0,a
Dec
r0
Djnz r2,__UNQLBL1