18X and ShiftOut

Simmicht

Senior Member
A quick question, does the 18X support shiftout, spiout?

I get a syntax error when I try it.

From reading the forum, it seems to be the case, I did want a definit answer, before I go bit-banging.

Oh, the manual does say YES, well, it has the 18X bolded on the manual pages for SHIFTOUT & SHIFTIN.

Cheers
 

srnet

Senior Member
Oh, the manual does say YES, well, it has the 18X bolded on the manual pages for SHIFTOUT & SHIFTIN.

Cheers
Does this apply ?

"Information:
The spiout (shiftout is also accepted by the compiler) command is a bit-bang of SPI communication on the X1 and X2 parts ONLY. All other parts must use the sample program included overleaf to duplicate this behaviour.
For a hardware solution for X1/X2 parts see the ‘hspiout’ command"
 

Andrew Cowan

Senior Member
You'll need to add the following at the end of your code:
Code:
‘***** 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)


‘ ***** Shiftout MSB first *****
shiftout_MSBFirst:
	for counter = 1 to bits 	‘ number of bits
	mask = var_out & MSBValue 	‘ mask MSB
	high sdata 			‘ data high
	if mask = 0 then skipMSB
	low sdata 			‘ data low
skipMSB: pulsout sclk,1 		‘ pulse clock for 10us
	var_out = var_out * 2 		‘ shift variable left for MSB
	next counter
	return
And then call the gosub shiftout_MSBFirst to shift out data.
 
Top