problem with the max7219
Jtracy
Posts: 6
I'm new to using the max7219 and have built a simple circuit that simply adds to a number according to the button i push. what i wanted to do was make two different variables that couldn't affect each other on the same chip each with only 3 digits. the first 4 digits work fine, but digit 5 and 6 will display strange segments. can someone help me.
here is the program
DataPin CON 0 'datain on max7219
Clock CON 2 'clock on max7219
Load CON 1 'Load on max7219
'
constants
Decode CON $09 ' bcd decode register
Brite CON $0A ' intensity register
Scan CON $0B ' scan limit register this desides how many
'digits are goinG TO be used
ShutDn CON $0C ' shutdown register (1 = on)
'
varables
total2 VAR Word
total VAR Word 'this word is what the value of all the segements
parts VAR Nib 'this nib is the indivdual digits of display
index VAR Nib 'this will be used for the for loop
idxOdd VAR index.BIT0 'used to initialize chip
' Initialization
'
Initialize:
DIRL = %0000111 ' data, clock and load as outs
FOR index = 0 TO 7
LOOKUP index, [noparse][[/noparse]Scan, 5, Brite, 15, Decode, $0F, ShutDn, 1], parts 'initializeing chip
SHIFTOUT DataPin, Clock, MSBFIRST, [noparse][[/noparse]parts]
IF (idxOdd = 0) THEN No_Load
PULSOUT Load, 5 ' load parameter
No_Load:
NEXT
'
main code
INPUT 15 'set port 15 to input
INPUT 14 'set port 14 to input
INPUT 13 'set port 13 to input
INPUT 12 'set port 12 to input
Main:
DEBUG ? total, CR
DEBUG ? total2, CR
PAUSE 500 'short stop
'IF total > 9999 THEN total = 0 'makes it so total cant equal over 9999
IF IN15 = 0 THEN Digit1 'if button to 15 pushed goto address Digit1
IF IN14 = 0 THEN Digit2 'if button to 14 pushed goto address Digit2
IF IN13 = 0 THEN Digit3 'if button to 13 pushed goto address Digit3
IF IN12 = 0 THEN Digit4 'if button to 12 pushed goto address Digit4
GOTO Main 'if no button pressed goto address Main
Digit1:
RANDOM total
'total = total + 1 'add 1 to total
total2 = total2 + 1
GOTO Show_Total 'goto address Show_Total
Digit2:
RANDOM total2
'total = total + 10 'add 10 to total
total2 = total2 + 10
GOTO Show_Total 'goto address Show_Total
Digit3:
total = total + 100 'add 100 to total
total2 = total2 + 100
GOTO Show_Total 'goto address Show_Total
Digit4:
total = total + 1000 'add 1000 to total
total2 = total2 + 1000
GOTO Show_Total 'goto address Show_Total
Show_Total:
FOR index = 5 TO 0 'go through 6 digits
IF index < 3 THEN parts1
IF index >= 3 THEN parts2
parts1:
parts = total DIG (index) 'this sets partss to the digit that index is on
GOTO put_digit
parts2:
parts = total2 DIG (index-3)
GOTO put_digit
put_digit:
SHIFTOUT DataPin, Clock, MSBFIRST, [noparse][[/noparse]index+1, parts] 'this shifts out current
'digit of index with index+1
'and then tells what that digit
'should be with parts
PULSOUT Load, 5 'pulses Load to load the digits
NEXT 'if not last digit goes back to beginning of for
GOTO Main 'go back to Main
here is the program
DataPin CON 0 'datain on max7219
Clock CON 2 'clock on max7219
Load CON 1 'Load on max7219
'
constants
Decode CON $09 ' bcd decode register
Brite CON $0A ' intensity register
Scan CON $0B ' scan limit register this desides how many
'digits are goinG TO be used
ShutDn CON $0C ' shutdown register (1 = on)
'
varables
total2 VAR Word
total VAR Word 'this word is what the value of all the segements
parts VAR Nib 'this nib is the indivdual digits of display
index VAR Nib 'this will be used for the for loop
idxOdd VAR index.BIT0 'used to initialize chip
' Initialization
'
Initialize:
DIRL = %0000111 ' data, clock and load as outs
FOR index = 0 TO 7
LOOKUP index, [noparse][[/noparse]Scan, 5, Brite, 15, Decode, $0F, ShutDn, 1], parts 'initializeing chip
SHIFTOUT DataPin, Clock, MSBFIRST, [noparse][[/noparse]parts]
IF (idxOdd = 0) THEN No_Load
PULSOUT Load, 5 ' load parameter
No_Load:
NEXT
'
main code
INPUT 15 'set port 15 to input
INPUT 14 'set port 14 to input
INPUT 13 'set port 13 to input
INPUT 12 'set port 12 to input
Main:
DEBUG ? total, CR
DEBUG ? total2, CR
PAUSE 500 'short stop
'IF total > 9999 THEN total = 0 'makes it so total cant equal over 9999
IF IN15 = 0 THEN Digit1 'if button to 15 pushed goto address Digit1
IF IN14 = 0 THEN Digit2 'if button to 14 pushed goto address Digit2
IF IN13 = 0 THEN Digit3 'if button to 13 pushed goto address Digit3
IF IN12 = 0 THEN Digit4 'if button to 12 pushed goto address Digit4
GOTO Main 'if no button pressed goto address Main
Digit1:
RANDOM total
'total = total + 1 'add 1 to total
total2 = total2 + 1
GOTO Show_Total 'goto address Show_Total
Digit2:
RANDOM total2
'total = total + 10 'add 10 to total
total2 = total2 + 10
GOTO Show_Total 'goto address Show_Total
Digit3:
total = total + 100 'add 100 to total
total2 = total2 + 100
GOTO Show_Total 'goto address Show_Total
Digit4:
total = total + 1000 'add 1000 to total
total2 = total2 + 1000
GOTO Show_Total 'goto address Show_Total
Show_Total:
FOR index = 5 TO 0 'go through 6 digits
IF index < 3 THEN parts1
IF index >= 3 THEN parts2
parts1:
parts = total DIG (index) 'this sets partss to the digit that index is on
GOTO put_digit
parts2:
parts = total2 DIG (index-3)
GOTO put_digit
put_digit:
SHIFTOUT DataPin, Clock, MSBFIRST, [noparse][[/noparse]index+1, parts] 'this shifts out current
'digit of index with index+1
'and then tells what that digit
'should be with parts
PULSOUT Load, 5 'pulses Load to load the digits
NEXT 'if not last digit goes back to beginning of for
GOTO Main 'go back to Main
Comments
This is just the beginning, the variable setup, but I suspect you can take it from there.
Is this what you're looking to do?
'First Set
total VAR Word 'this word is what the value of all the segements
parts VAR Nib 'this nib is the indivdual digits of display
index VAR Nib 'this will be used for the for loop
idxOdd VAR index.BIT0 'used to initialize chip
'Second Set
total2 VAR Word
parts2 VAR Nib 'this nib is the indivdual digits of display
index2 VAR Nib 'this will be used for the for loop
idxOdd2 VAR index2.BIT0 'used to initialize chip
Regards,
Bruce Bates
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When all else fails, try inserting a new battery.
Your code appears to be set to decode only digits 0-3…you should set the $0F in your Initialize routine to $FF to decode all digits. I hope this helps. Take care.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Engineering
There is some demo code for the MAX7219 here:
http://forums.parallax.com/forums/default.aspx?f=5&m=308913
Post Edited (awesomeduck) : 12/3/2008 9:50:40 PM GMT
http://forums.parallax.com/showthread.php?p=552892
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Engineering