Shop OBEX P1 Docs P2 Docs Learn Events
problem with the max7219 — Parallax Forums

problem with the max7219

JtracyJtracy Posts: 6
edited 2008-12-04 03:14 in BASIC Stamp
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

Comments

  • Bruce BatesBruce Bates Posts: 3,045
    edited 2008-12-02 23:25
    JTracy -

    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.
  • JtracyJtracy Posts: 6
    edited 2008-12-02 23:39
    the problem i see with that is that i want the same index so that it knows what digit to go to. such as if index is on it's second loop then it will go to digit two, or if index is on loop 5 it will go to digit 6. then i just change what i want parts to be. So i don't think that setting up to differnt sets is going to work
  • JtracyJtracy Posts: 6
    edited 2008-12-02 23:40
    i ment to say if index is one loop 5 it will go to digit 5
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2008-12-03 16:22
    Hello,

    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
  • awesomeduckawesomeduck Posts: 87
    edited 2008-12-03 21:43
    I think Chris is dead on with the problem, Decode Mode Register is a bit mask, not an integer value.

    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
  • JtracyJtracy Posts: 6
    edited 2008-12-03 22:15
    thanks, I wasn't able to test it today, but that sounds like the problem. i'm also thinking of adding in two LED bar displays. Do you think the best way to do that would to change it by by binary like the adding a decimal point by doing %10000000.
  • JtracyJtracy Posts: 6
    edited 2008-12-03 22:15
    thanks, I wasn't able to test it today, but that sounds like the problem. i'm also thinking of adding in two LED bar displays. Do you think the best way to do that would to change it by by binary like the adding a decimal point by doing %10000000.
  • awesomeduckawesomeduck Posts: 87
    edited 2008-12-03 22:33
    I don't follow what you are asking about the decimal points. Since the 7219 support 8 "characters" you could configure the digits 6 and 7 to be in non decode mode, then attach 8 segment bar LEDs to those digits. Could then easily control the bar graphs with no extra logic.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2008-12-03 23:30
    Check out the following project to see how you can use the decimal points independently of the digits…in this case they are being used as the colons for the clock, however they are easy to set individually so you could use them for just about any indication.

    http://forums.parallax.com/showthread.php?p=552892



    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Engineering
  • JtracyJtracy Posts: 6
    edited 2008-12-04 03:14
    sorry, what i meant to say was that early in this project i put in a decimal point on the 7 segment display by doing DecPnt CON %10000000 then adding that on to the digit i wanted the decimal point to be on. What i was asking was would that be the way to go to control any one LED in the 8 LED bar, but i should be fine now, since i know how initializing chip right. thanks for the help
Sign In or Register to comment.