serial communication with HV5812

airton65

Member
Hi All,
I had a bit of a breakthrough last night and I "THINK" I've worked out how to send the 20 bits of data to the HV5812 in 2 lots of 10 bits which is perfect for nixies and VFD tubes.
I'm interested in what others think of this code (glaring mistakes etc) and whether i could do it more efficiently.
Regards
Tony

Code:
symbol sclk = B.7 ; clock (output pin)
symbol sdata = B.5 ; data (output pin for shiftout)
symbol counter = b17 ; variable used during loop
symbol mask = w4 ; bit masking variable
symbol var_out2 = w5 ; data variable used durig shiftin
symbol var_out = w6 ; data variable used during shiftout
symbol bits = 10 ; number of bits
symbol MSBvalue = 512 ; MSBvalue ;(=128 for 8 bits, 512 for 10 bits, 2048 for 12 bits)



	Main:

		let var_out = 9
		let var_out2= 10
			let var_out2 = var_out2 + 1024
				gosub shiftout_MSBFirst
				pause 50

	goto Main

 
shiftout_MSBFirst:
		
		for counter = 1 to 10 		; number of bits
		mask = var_out & 1		; 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 right for LSB
		  	next counter
		
		
					
			
			
			
Vari2:

		for counter = 1 to 10 		; number of bits
		mask = var_out2 & 1		; mask MSB
		high sdata 				; data high
		if mask = 0 then skipMSB2
		low sdata 				; data low

skipMSB2:
		pulsout sclk,1 			; pulse clock for 10us
		var_out2 = var_out2 / 2 	; shift variable right for LSB
		next counter
		pulsout B.6,10
							; I added this strobe output
			return
 
Last edited:
Top