; Encoder SSI read routine
bank0
movlw d'12' ; bit count
movwf count
bsf portA,EncClk ; start with clock high
bcf intcon,gie ; disable interrupts during read
bcf portA,EncCS ; clear SSI chip select to init read
bcf portA,EncClk ; set clock low
goto $+1 ;this is a 2 cycle nop
nop
bsf portA,EncClk ; set clock high for 4 cycles
goto $+1
nop ;the above toggle discards the start bit
SSIreadloop
bcf portA,EncClk ; set clock low for 4 cycles
rrf portA,w ; read data bit (portA.0) by rotating it into carry bit
rlf psnL,f ; and shift into position register
rlf psnH,f
bsf portA,EncClk ; set clock high for 4 cycles
decfsz count,f
goto SSIreadloop
bsf portA,EncCS ;set chip select high
movlw 0x0F
andwf psnH,f ;Clear any extraneous high bits
bsf intcon,gie ; re-enable interrupts