I have built a keypad decoding circuit around the MM74C922 decoder IC and a 74HC165 parallel IN, serial OUT shift register. After searching through the forums for coding the Picaxe to read from the 74HC165 and how it works, I got the circuit working correctly. I just want some clarification on the process for clocking in the bits from the shift register. I understand fully how the 74HC595 works in terms of the code, but am finding it difficult to wrap my hear around the 74HC165 operation. Here is my code:
I am looking more specifically for step by step explanation of the counter loop. Why add 1 to "thedata" if serindata value is 0? Also, what is the difference between sampling before the clock and after the clock? Lastly, why shift the data right (multiply by 2) before clocking out the bit. Wouldn't that discard the MSB before storing it into a variable? Any explanations would be greatly appreciated.
Code:
setfreq m16
setint %00100000, %00100000
symbol CLOCK=b.1
symbol PL=b.2
symbol CE=b.3
symbol counter=b10
symbol thedata=b11
symbol SerIndata= pinb.0
main:
LOW CLOCK
LOW CE
HIGH PL
goto main
interrupt:
serout c.0, t9600_16,("Entered Interrupt Routine",cr,lf)
do while pinC.5=1:loop
pause 10
pulsout PL, 10
for counter = 0 to 7
thedata=thedata * 2
'serout c.0, t9600_16,(#serindata,cr,lf)
if serIndata=0 then skipMSBPre
thedata=thedata + 1
skipMSBPre:
pulsout CLOCK,10
next counter
serout c.0, t9600_16,(#thedata,cr,lf)
setint %00100000, %00100000
return