Shop OBEX P1 Docs P2 Docs Learn Events
MAX7219 Secrets — Parallax Forums

MAX7219 Secrets

G McMurryG McMurry Posts: 134
edited 2009-10-16 02:58 in BASIC Stamp
OK -- I am doing a project with the MAX7129 Display Driver. I have had great luck working with Stampworks Experiment #29 for the sample code, but.... I need to write to the upper 4 digits. My application uses two 4 digit groups. I need to be able to write two separate values to the upper 4 and the lower 4.

Experiment #29 only writes to the Lower 4 digits. I have messed with everything I can think of with no luck so far. Can anyone give me a hint?

Greg

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
AUTOMATE EVERYTHING
http://www.trainyard.net

Comments

  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2009-10-14 20:10
    Greg,

    The following project should offer some insight...basically you need to turn on scanning for all 8 digits. At that point it is a matter of simply indexing the correct digit and sending the data to it. There's a tiny bit more to it but I tried to make the subroutines really friendly by simply setting a digit number and the data and calling the update routine.

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

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage

    Parallax Engineering
    50 72 6F 6A 65 63 74 20 53 69 74 65
    ·
  • G McMurryG McMurry Posts: 134
    edited 2009-10-15 13:56
    OK Chris -- Im on to it. There's loads of other stuff in your clock so it will take me a bit of time to filter out just the display routine. HOWEVER -- good for me to do. I enjoy looking at other's code.

    Greg

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    AUTOMATE EVERYTHING
    http://www.trainyard.net
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2009-10-15 19:06
    Greg,
    I have the code open so I can address this with you in more detail...the important stuff is of course being able to talk to the display and you seem to have that down.· My code has the I/O, constant and variable declarations at the beginning, in that order.· The first part of any of my programs is Initialization...this makes sure the I/O lines are setup and that and of the hardware connected is setup as well.· The section in Initialization that applies to the MAX7219 is as follows:
    FOR index = 0 TO 7                      ' Initialize MAX7219
      LOOKUP index, [noparse][[/noparse]Scan, 5, Brite, 9, Decode, $FF, ShutDn, 1], d7219
      SHIFTOUT DataIO, Clock, MSBFIRST, [noparse][[/noparse]d7219]
      IF (idxOdd = No) THEN No_Load
      PULSOUT MAX7219, 5                    ' Latch The Data
    No_Load:
    NEXT
    
    


    This does four things in one routine that may not necessarily be easy to see for everyone.· First it sets the Scan Limit Regsiter to 5.· This tells the MAX7219 to update digits 0 through 5 (6 digits).· Next the Intensity Regsiter is set to 9.· This value can be from 0 (dimmest) to 15 (brightest).· Next the Decode-Mode Register is set to $FF, which sets decoding for all 8 digits (there is a table for these settings).· Finally, the Shutdown Regsiter is set to·one (1)·for normal operation.· A zero (0) here would disable the display.

    So the most obvious change you would need to make would be to set the Scan Limit Register to 7.· The rest of these settings would apply.

    The Show_Time subroutine is what updates the display.· So all you need to do is call it to update the entire display.· Notice the use of 1 - 6 for the digits rather than 0 -5 as the datasheet indicates.
    Show_Time:
      index = 1                             ' Select Digit 1
      d7219 = secs.LOWNIB                   ' Seconds (Ones Digit)
      d7219 = d7219 | DecPnt                ' Enable Decimal Point
      GOSUB Show_Max_Time
      index = 2                             ' Select Digit 2
      d7219 = secs.HIGHNIB                  ' Seconds (Tens Digit)
      d7219 = d7219 | DecPnt                ' Enable Decimal Point
      GOSUB Show_Max_Time
      index = 3                             ' Select Digit 3
      d7219 = mins.LOWNIB                   ' Minutes (Ones Digit)
      d7219 = d7219 | DecPnt                ' Enable Decimal Point
      GOSUB Show_Max_Time
      index = 4                             ' Select Digit 4
      d7219 = mins.HIGHNIB                  ' Minutes (Tens Digit)
      d7219 = d7219 | DecPnt                ' Enable Decimal Point
      GOSUB Show_Max_Time
      index = 5                             ' Select Digit 5
      d7219 = hrs.LOWNIB                    ' Hours (Ones Digit)
      IF (modeFlag = Hr12) AND (ampmFlag = 1) THEN d7219 = d7219 | DecPnt
      GOSUB Show_Max_Time                   ' ^ PM Indicator
      index = 6                             ' Select Digit 6
      d7219 = Blank                         ' Blank Digit
      IF hrs.HIGHNIB <> $00 THEN d7219 = hrs.HIGHNIB
                                            ' If Not Zero Display
      IF (modeFlag = Hr12) AND (ampmFlag = 0) THEN d7219 = d7219 | DecPnt
      GOSUB Show_Max_Time                   ' ^ AM Indicator
      GOSUB Out_595                         ' Send Digits To Binary Display
      RETURN
    
    


    If we break this routine down we can see that for each digit the index is set (this is the digit we're going to update), the value of that digit is set (d7219) and then the value is OR'd with the constant DecPnt, which has the effect of setting bit 7.· This is how each decimal point is enabled for each digit.· On this clock I am using the decimal points for the first four digits as colons between the hours minutes and seconds.· This allows them to dim with the display.· The decimal points for the last two digits (5 and 6) are used to indicate AM/PM mode (when enabled).

    Notice that after each digit is set the subroutine Show_Max_Time is called.· This sets that digit on the MAX7219.· So, as you can see, each digit can be set completely independent of each other.· You could easily create a subroutine that allows you to set the digits one at a time by specifying the index value before calling the subroutine, as shown below.
    Show_Time:
      d7219 = secs.LOWNIB                   ' Seconds (Ones Digit)
      d7219 = d7219 | DecPnt                ' Enable Decimal Point
      GOSUB Show_Max_Time
      RETURN
    

    Using this routine you would set the variable index with the digit number you wanted, set d7219 with the value you wanted, DecPnt could be a variable instead that if set causes bit 7 to be turned on.· It would·only need to be a bit variable to do this.· You'd call the subroutine and your digit would appear.· Note that·d7219 contains the value (not ASCII value) of the number since decode mode is on.· You can optionally blank a digit by setting d7219 to %1111.· I hope this helps.· Take care.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage

    Parallax Engineering
    50 72 6F 6A 65 63 74 20 53 69 74 65
    ·
  • G McMurryG McMurry Posts: 134
    edited 2009-10-16 01:02
    Chris,

    This is WAY beyond the call of duty. I am extremely grateful for your help...

    I am using BASIC STAMP to control my 8th scale locomotive. It has been an interesting project.

    These are trains that are large enough to haul dozens of people on track that is 7.5 inches apart. Many of the locomotives are powered by live steam but mine is an 18 hp gasoline engine driving a 10kw power plant. The locomotive has 12 wheels and two 2.5 hp electric motors (1 motor per 6 wheels).

    I control all the functions with a BS2 including a hobby servo for throttle and choke. Analog voltage outputs control the air brakes and there are relay interfaces for forward / reverse / etc.

    All control functions travel over 19.2 baud serial to a control panel that has A to D converters for a throttle control and the brake controls.

    All of this has been working for many months. I am now adding a speedometer, tachometer and monitors for voltage and current. I am using 4ea 4 digit 7-segment displays driven by two MAX7219 chips. Again, all this is working but I have not been able to split up my data into 4 different 4 digit displays. Currently I just am able to write to my two MAX7219 chips and only the lower 4 digits...

    I haven't been too good at photographing everything as I go but here are a few pictures of what I have been working with. No pictures of my display panel yet but I will add them soon.

    http://trainyard.net/gregtrain/090909_nautilus/index.htm

    Your sample code should get me over the top on this one...

    Thanks Again..

    Greg

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    AUTOMATE EVERYTHING
    http://www.trainyard.net
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2009-10-16 02:58
    Greg,

    Someone reminded me today that I used to provide more descriptive answers to questions, especially when referring to a piece of code I wrote. I realized that I pointed you to the code without really explaining what I was wanting you to gain from it. The problem is time it seems...I'm going to have to start making time to answer things more clearly. So my answer was really what it used to be. Someone called me on it today and for that I am thankful. I don't remember how or why I stopped being as helpful with my code. If you have any more questions, just follow up here. I hope this helps. Take care.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage

    Parallax Engineering
    50 72 6F 6A 65 63 74 20 53 69 74 65
    ·
Sign In or Register to comment.