max7219 and readadc and DIG command

Kecked

Member
Ok so I got talking to the max7219 down and I can send digits to it to display. So I thought ok I'll try reading in a value from an adc and use the DIG command to isolate and display the digits. HELP...is this another math problem? It won't work

Code:
#picaxe 28x2
	setfreq m16
	dirsb = %00010000			'b.5 will be a pwm output
	dirsc = %10111111			'c.1 and c.2 will be pwm outputs
	let adcsetup = %00000000	'let inputs be inputs
	hspisetup spimode00,spifast    ' set up hspi
	
	
' Register addresses for the MAX7219
	symbol decode =  9 ' decode register; specify digits to decode
	symbol brite  = 10 ' intensity (brightness) register; 15 = 100%
	symbol scan   = 11 ' scan-limit register; specify how many digits
	symbol on_off = 12 ' 1 = display on; 0 = display off
	symbol blank  = 15 ' used by MAX7219 to blank a digit
	symbol load = C.0  


	

' Initialize MAX7219
	hspiout (scan,5)         	' set scan limit for digits 0-5
	pulsout load,2

  	hspiout (brite,5)        	' set brightness to 5 (15 = 100%)
	pulsout load,2

  	hspiout (decode,%00111111)  	' set BCD decoding for digits 0-5
	pulsout load,2

  	hspiout (on_off,1)       	' turn display on
	pulsout load,2

main:
						'readadc value into byte
readadc b.1,b1
						'isolate digits
	let b2= b1 dig 2 

	let b3= b1 dig 1

	let b4= b1 dig 0
						'send digits to display	
		hspiout (1,b2)
		pulsout load,2
		
		hspiout (2,b3)
		pulsout load,2
	
		hspiout (3,b4)
		pulsout load,2
		
readadc b.2, b5

	let b6= b1 dig 2 

	let b7= b1 dig 1

	let b8= b1 dig 0

		hspiout (4,b6)
		pulsout load,2
		
		hspiout (5,b7)
		pulsout load,2
	
		hspiout (6,b8)
		pulsout load,2
goto main
 

g6ejd

Senior Member
From the look of the code, your sending binary data not ASCII characters to the display BINTOASCII might be what you need. e.g. reading is HEX 23 or BINARY 00200011 so to convert 2x16 bit values to ASCII use BINTOASCII so it sends "2" then "3", etc

BINTOASCII variable, hundreds, tens, units in my example BINTOASCII 23,b2,b3,b4 woudl then print "0", "2", "3" for the values in bytes b2, b3, b4... check the manual.

So read your value then convert it to ASCII for onward display. A greater explanation of your circuit would help or a diagram.
 

PaulRB

Senior Member
@g6ejd: no, I don't think that's it. The max7219 does not understand ASCII.

@kecked: I can't immediately see anything wrong with your code. When you say "it won't work", what exactly do you see?

Paul
 

PaulRB

Senior Member
Have you tried:

sertxd("b1=", #b1, CR, LF)

after the readadc? What do see on the terminal window?
 

Kecked

Member
what mean to do is read the adc into b1 and then dig b1 into the individual digits that I then send to the max chip. It is my understanding that the dig command outputs a decimal number which the max chip should then display. What I see is just some random numbers that don't change with the adc (got a pot across vcc and ground into an adc input. Doing it in vsm for now. I'll try the serial command to see if what I have. If I put a number into the slot to go to the display it works fine so its not the max code but how i'm reading the adc and separating the digits I think.

Once this works the values will go to pwm to control rgb leds. This lets me set colors precisely to gel filter rgb numbers.

http://downloads.goapollo.com/Multiform Gel to LEDsv2.pdf
 
Top