‘ ~~~~~ SYMBOL DEFINITIONS ~~~~~
‘ Required for all routines. Change pin numbers/bits as required.
‘ Uses variables b7-b13 (i.e. b7,w4,w5,w6). If only using 8 bits
‘ all the word variables can be safely changed to byte variables.
‘
‘***** Sample symbol definitions *****
symbol sclk = 5 ‘ clock (output pin)
symbol sdata = 7 ‘ data (output pin for shiftout)
symbol serdata = input7 ‘ data (input pin for shiftin, note input7
symbol counter = b7 ‘ variable used during loop
symbol mask = w4 ‘ bit masking variable
symbol var_in = w5 ‘ data variable used durig shiftin
symbol var_out = w6 ‘ data variable used during shiftout
symbol bits = 8 ‘ number of bits
symbol MSBvalue = 128 ‘ MSBvalue
‘(=128 for 8 bits, 512 for 10 bits, 2048 for 12 bits)
‘========================================================================
‘ ~~~~~ SHIFTIN ROUTINES ~~~~~
‘ [B][COLOR="#FF0000"]Only one of these 4 is required - see your IC requirements
‘ It is recommended you delete the others to save space[/COLOR][/B]
‘========================================================================
‘ ***** Shiftin LSB first, Data Pre-Clock *****
shiftin_LSB_Pre:
let var_in = 0
for counter = 1 to bits ‘ number of bits
var_in = var_in / 2 ‘ shift right as LSB first
if serdata = 0 then skipLSBPre
var_in = var_in + MSBValue ‘ set MSB if serdata = 1
skipLSBPre: pulsout sclk,1 ‘ pulse clock to get next data bit
next counter
return
‘========================================================================
‘ ***** Shiftin MSB first, Data Pre-Clock *****
shiftin_MSB_Pre:
let var_in = 0
for counter = 1 to bits ‘ number of bits
var_in = var_in * 2 ‘ shift left as MSB first
if serdata = 0 then skipMSBPre
var_in = var_in + 1 ‘ set LSB if serdata = 1
skipMSBPre: pulsout sclk,1 ‘ pulse clock to get next data bit
next counter
return
‘========================================================================
‘ ***** Shiftin LSB first, Data Post-Clock ***** ‘
shiftin_LSB_Post: let var_in = 0
for counter = 1 to bits ‘ number of bits
var_in = var_in / 2 ‘ shift right as LSB first
pulsout sclk,1 ‘ pulse clock to get next data bit
if serdata = 0 then skipLSBPost
var_in = var_in + MSBValue ‘ set MSB if serdata = 1
skipLSBPost: next counter
return
‘========================================================================
‘ ***** Shiftin MSB first, Data Post-Clock *****
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
‘========================================================================