Hello everyone
I am trying to retrieve data bits from a shift register. Actually, it is a shift register inside the Super Nintendo Controller. Here is the info regarding its function http://english.cxem.net/pinout/pinout21.php .
I am using the PICAXE 08M. When I read the manual, it stated that I need to use a different method since the 08M does not have a shiftin command. I am actually trying to understand how exactly the alternate method goes about doing this. The past semester (ended about a week and a half ago) I took a class titled "Intro to Digital Design" and learned about D flip flops and how they are used to make shift registers so the concept is not foreign to me.
Here is the manual's code for reference.
I have been looking at this code and am still a little unsure on what it is doing. Here is my understanding:
the "for counter = 1 to bits" line is how many bits I would like to shiftin from the shift register
var_in = var_in * 2 --- it says it shifts left as MSB first, how does it exactly do that. when it starts initially the value will be zero before the first clock.
the pulsout sclk, 1 --- just pulses the clk pin to shift to the next bit to be read
if serdata = 0 then skipMSBPost --- why is it skipping it?
var_in = var_in + 1 ---- not sure
so say I shift in the binary number "1010" using the code above (MSB first and sample data after clock pulse), after cycling four bits, the value of var_in will be 10? if the number is "1111" the value of var_in will be 15? I think so because the decimal value matches the binary after going through the code but I just would like to know HOW and WHY it does this.
I am trying to retrieve data bits from a shift register. Actually, it is a shift register inside the Super Nintendo Controller. Here is the info regarding its function http://english.cxem.net/pinout/pinout21.php .
I am using the PICAXE 08M. When I read the manual, it stated that I need to use a different method since the 08M does not have a shiftin command. I am actually trying to understand how exactly the alternate method goes about doing this. The past semester (ended about a week and a half ago) I took a class titled "Intro to Digital Design" and learned about D flip flops and how they are used to make shift registers so the concept is not foreign to me.
Here is the manual's code for reference.
Code:
' ========================================================================
' ***** Shiftin MSB first, Data Post-Clock *****
' Shift in the data MSB first into variable var_in
' Read data after sending clock pulse
' Using clock output pin sclk
' Using data input pin serdata
shiftin_MSB_Post:
let var_in = 0
for counter = 1 to bits ' number of bits
var_in = var_in * 2 ' shift left as MSB first
pulsout sclk,1 ' pulse clock to get next data bit
if serdata = 0 then skipMSBPost
var_in = var_in + 1 ' set LSB if serdata = 1
skipMSBPost:
next counter
return
' ========================================================================
the "for counter = 1 to bits" line is how many bits I would like to shiftin from the shift register
var_in = var_in * 2 --- it says it shifts left as MSB first, how does it exactly do that. when it starts initially the value will be zero before the first clock.
the pulsout sclk, 1 --- just pulses the clk pin to shift to the next bit to be read
if serdata = 0 then skipMSBPost --- why is it skipping it?
var_in = var_in + 1 ---- not sure
so say I shift in the binary number "1010" using the code above (MSB first and sample data after clock pulse), after cycling four bits, the value of var_in will be 10? if the number is "1111" the value of var_in will be 15? I think so because the decimal value matches the binary after going through the code but I just would like to know HOW and WHY it does this.