HW-179 8-Digit 7-Segment LED Display (MAX7219 Driver)


+ Reply to Thread
Results 1 to 11 of 11
  1. #1
    Join Date
    Nov 2019
    Posts
    20

    Default HW-179 8-Digit 7-Segment LED Display (MAX7219 Driver)

    This sample code demonstrates writing to an 8-digit 7-segment LED display (the HW-179 module) that uses the MAX7219 driver device. The MAX7219 is fully SPI compliant, and as such does not require the bit-banging exercises that were present in my earlier posts on LED displays equipped with the TM1637 and TM1638 drivers. Furthermore, the MAX7219 provides for BCD decoding that eliminates the necessity of code that converts numerical digits into their corresponding 7-segment 8-bit codes (although this mode of operation is possible with the MAX7219). The objective of this code sample is only to illustrate initialization of the MAX7219 display, and to show how the 16-bit address+data sequences can be sent as either 16-bit constants, 8-bit variable + 8-bit constant, or by two 8-bit variables, using PBP's SHIFTOUT command.

    The MAX7219 driver provides for cascading configurations, thus allowing the HW-179 modules to be chained together to provide 16, 24, 32, etc. digit displays. An example of this will be provided in a subsequent code sample post.

    Code:
    '****************************************************************
    '*  Name    : MAX7219_8-Digit_7-Segment_Demo.BAS                *
    '*  Author  : Roberts                                           *
    '*  Notice  : Copyright (c) 2021 Copyright (c) 2019             *
    '*          : All Rights Reserved                               *
    '*  Date    : 10/6/2021                                         *
    '*  Version : 1.0                                               *
    '*  Notes   : Developed on Microchip Curiosity Board with       *
    '*          : PIC16F183456 uC and the HW-179 8-digit/7-segment  *
    '*          : display driven by the MAX7219 driver via 3-wire   *
    '*          : SPI interface, set to operate at 5 VDC.           *
    '****************************************************************
    '
    ' This brief demo program writes the digits 0 thru 9 and "-" to the HW-179 8-digit 7-segment LED display based on the
    ' MAX7219 interface driver.  The code includes the initialization sequence that (a) sets the decode mode to BCD,
    ' (b) sets the LED intensity to half-scale (8/16), (c) sets all 8 digits active, and (d) activates the display.
    ' After initialization, the code sets the test mode active for 1 second (e.g., all digits and all segments lit).  Then
    ' all digits are cleared, and counting begins with the right-hand most digit.  Each digit counts from 0 to 9 and then
    ' "-", and the counting progresses to the left one digit at a time.  Once all 8 digits are showing "-", the program
    ' cycles back to clearing the display and repeating.
    ' Data is sent to the display using PBP's SHIFTOUT command.  The code demonstrates how these 16-bit address + data
    ' commands can be constructed as either a single 16-bit constant, by an 8-bit variable + 8-bit constant, and by two 8-bit
    ' variables.  While the MAX7219 data registers are blanked upon power on, a microcontroller reset requires a procedure
    ' that writes 0x0F to all 8 digits in order to blank the digits.
    '
    '****************************************** PIC16F18346 Initialization *************************************************                                                 
    '************************************** Configuration File for the PIC 16F18346 ****************************************
    #CONFIG
        __config _CONFIG1, _FEXTOSC_OFF & _RSTOSC_HFINT32 & _CLKOUTEN_OFF & _CSWEN_ON & _FCMEN_ON
        __config _CONFIG2, _MCLRE_ON & _PWRTE_OFF & _WDTE_ON & _LPBOREN_OFF & _BOREN_ON & _BORV_LOW & _PPS1WAY_OFF & _STVREN_ON & _DEBUG_OFF
        __config _CONFIG3, _WRT_OFF & _LVP_OFF
        __config _CONFIG4, _CP_OFF & _CPD_OFF
    
    #ENDCONFIG
    @ ERRORLEVEL -306   ; turn off crossing page boundary message
    
    OSCFRQ = 000100    ' Set internal osc to 16MHz
    DEFINE OSC 16        ' Tell PBP that the device will clock at 16MHz (necessary for uSec pauses used in bit-banging)
    
    ANSELA = 000000    ' PortA all digital / available pins are A0 through A5 (6 I/O's)
    TRISA = 000000   ' PortA all outputs
    '
    '************************** Initialization and Variable Declarations *****************************************
    '
    ' SPI signals use LATx.x assignments to prevent read/modify/write conflicts on a single I/O port
    CS  Var LATA.2  ' uC chip select output pin
    SCK Var LATA.4  ' uC clock out pin
    SI  Var LATA.5  ' uC data out / LCD Data in pin
    '
    '
    i VAR WORD       ' loop counter variable
    j VAR byte       ' loop counter variable
    CS = 1           ' Disable SPI device select CS for OLED 
    '
    '************************* Initialize the display parameters by sending 16-bit constants **********************
    '                (See MAX7219 spec sheet for tables listing full range of initialization values)
    
        CS = 0
        SHIFTOUT SI, SCK, 1, [$0F01\16]         'Test display - illuminate all segments & all digits     
        CS = 1    
        PAUSE 1000                              'hold for 1 second
        
        CS = 0
        SHIFTOUT SI, SCK, 1, [$0F00\16]         'Return to normal display mode
        CS = 1    
        PAUSE 1000                              'Pause 1 second
    
        CS = 0
        SHIFTOUT SI, SCK, 1, [$09FF\16]         'Set decode mode for BCD
        CS = 1                                  '($0900 for no decoding - see MAX7219 spec sheet)
        PAUSE 10
        
        CS = 0
        SHIFTOUT SI, SCK, 1, [$0A07\16]         'Set display intensity to half scale
        CS = 1                                  '($0A00 for minimum brightness / $0A0F for maximum brightness)
        PAUSE 10
        
        CS = 0
        SHIFTOUT SI, SCK, 1, [$0B07\16]         'All 8 digits active
        CS = 1                                  '($0B01 for only digit 1 active - see MAX7219 spec sheet)
        PAUSE 10
        
        CS = 0
        SHIFTOUT SI, SCK, 1, [$0C01\16]         'Activate display
        CS = 1                                  '($0C00 for powering down the display - see MAX7219 spec sheet)
        PAUSE 10
    
    '********************************************* Main Program ********************************************************** 
    main:                                       
      For i = 1 to 8                            'Clear all 8 digit registers to blank
        CS = 0
        Shiftout SI, SCK, 1, [i,$0F]            'Clear each digit "i" by sending the blank character constant 0x0F
        CS = 1
        Pause 10
      Next i                                    'hold the display blank for 1 second
      Pause 1000
    
     For j = 1 to 8                             'the variable j is the 8-bit digit address register
      For i = 0 to 10                           'the variable i is the 8-bit data register
        CS = 0
        SHIFTOUT SI, SCK, 1, [j,i]              'Display 0 through 9 in digit 1 position (r/h most digit)
        CS = 1
        PAUSE 500                               'pause 1/2 second for counting
      Next i 
     Next j 
                                                
     Pause 2000                                 'hold the display for 2 seconds
                                              
    Goto main

  2. #2
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,596


    Did you find this post helpful? Yes | No

    Default Re: HW-179 8-Digit 7-Segment LED Display (MAX7219 Driver)

    Hi Chuck,

    Awesome work! Have you figured out how many MAX7219 we can daisy-chain?

    I saw posts elsewhere mentioning a "capacitance limitation" with SPI, and that bit-banging permitted more drivers in a chain (or vice-versa).

    I'm chaining 10 drivers with total wire length under 7-8 inches.

    Name:  Max7219 chain.png
Views: 92
Size:  18.1 KB


    EDIT: These guys got me thinking.

    https://forum.arduino.cc/t/max7219-s...ngth/250346/14


    I can just as easily use 2 chains of 5 drivers. I've got the pins.
    Last edited by Demon; - 14th February 2024 at 07:16.
    My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.

    Not as dumb as yesterday, but stupider than tomorrow!

  3. #3
    Join Date
    May 2013
    Location
    australia
    Posts
    2,386


    Did you find this post helpful? Yes | No

    Default Re: HW-179 8-Digit 7-Segment LED Display (MAX7219 Driver)

    henrik has joined shit loads of them together into a string

    why would a pic o/p pin perform differently when it's a spi pin ?

    see this about post #19
    https://www.picbasic.co.uk/forum/sho...hlight=max7219
    Warning I'm not a teacher

  4. #4
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,802


    Did you find this post helpful? Yes | No

    Default Re: HW-179 8-Digit 7-Segment LED Display (MAX7219 Driver)

    The data out of each MAX is buffered internally. I see no problem cascading here.

    But LOAD (/CS) and CLOCK are connected in parallel for all chips and this may be a problem. In this case you can use a buffer like this SN74LVC1G126-Q1.

    Also take a note of Cascading Drivers page 11 of the datasheet.

    Ioannis

  5. #5
    Join Date
    May 2013
    Location
    australia
    Posts
    2,386


    Did you find this post helpful? Yes | No

    Default Re: HW-179 8-Digit 7-Segment LED Display (MAX7219 Driver)

    LOAD (/CS) and CLOCK are connected in parallel for all chips and this may be a problem
    after the first 1000 or so chips, the max load of a max7219 logic i/p pin is 1uA. cable capacitance is the limit [meters of it at least ]
    Warning I'm not a teacher

  6. #6
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,802


    Did you find this post helpful? Yes | No

    Default Re: HW-179 8-Digit 7-Segment LED Display (MAX7219 Driver)

    Well, not exactly. Each input is 1 micro Amp, so 1000 is 1mA.

    But still within driving capabilities of a PIC.

    Cable capacitance is different matter and may lead to problems. So a buffer is not big thing to include.

    Ioannis

  7. #7
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,596


    Did you find this post helpful? Yes | No

    Default Re: HW-179 8-Digit 7-Segment LED Display (MAX7219 Driver)

    How to use MAX7219 with common anode 7-segment displays:

    https://forum.arduino.cc/t/max7219-a...control/118609


    I'm writing lyrics for a song called 7-Segment Roller-Coaster Ride. So far my song outline goes like this:

    - 2 days ago in the morning, disappointed it was so complicated to drive dozens of displays.
    - 2 days ago later that day, discovers MAX7219 can drive up to 8 digits and can be chained.
    - yesterday morning, finds out Digikey sells them for $20.
    - yesterday afternoon, finds out JLCPCB has them in stock for $1.30.
    - this morning, realizes my displays are common anode and Maxim specifically says "for common cathode".
    - this afternoon, finds thread on arduino forums how to use MAX7219 "backwards" with common anode.
    - tomorrow, everything crashes down cause of some other reason.

    I'm thinking of having a husky singing back-up vocals.




    Edit: ....AAAAAND..... POOF!

    Reversing the matrix only supports numbers 0 to 7. I need to display 8 and 9 as well.


    ... AAAAAND ... reversal!

    So these guys apparently figured out how by turning off the decode mode on the MAX7219, but someone in the comments raised a concern over current limitations (a cathode is capable of withstanding the current of 7 segments + decimal point, but reversing the polarity of the circuitry means a segment will support the current from all 8 digits):

    https://www.plingboot.com/max7219-an...node-displays/
    Last edited by Demon; - 14th February 2024 at 20:05.
    My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.

    Not as dumb as yesterday, but stupider than tomorrow!

  8. #8
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,596


    Did you find this post helpful? Yes | No

    Default Re: HW-179 8-Digit 7-Segment LED Display (MAX7219 Driver)

    Quote Originally Posted by richard View Post
    henrik has joined shit loads of them together into a string

    why would a pic o/p pin perform differently when it's a spi pin ?

    see this about post #19
    https://www.picbasic.co.uk/forum/sho...hlight=max7219

    Yeah, but they're strung out end-to-end.

    There seems to be a concern about wire length. I just wonder how much of a concern that might be.

    Note that my enclosures aren't bigger than a sheet of letter-size paper.
    My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.

    Not as dumb as yesterday, but stupider than tomorrow!

  9. #9
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,802


    Did you find this post helpful? Yes | No

    Default Re: HW-179 8-Digit 7-Segment LED Display (MAX7219 Driver)

    I would use what Maxim suggest for the displays and would not bother with mods to drive common anodes.

    As for the capacitance, well, few centimeters more will not do an harm. Do not worry about that. A 20 meter or more sure is of concern.

    Ioannis

  10. #10
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,596


    Did you find this post helpful? Yes | No

    Default Re: HW-179 8-Digit 7-Segment LED Display (MAX7219 Driver)

    (my rambling about PWM moved here https://www.picbasic.co.uk/forum/sho...7-segment-LEDs)
    My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.

    Not as dumb as yesterday, but stupider than tomorrow!

  11. #11
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,596


    Did you find this post helpful? Yes | No

    Default Re: HW-179 8-Digit 7-Segment LED Display (MAX7219 Driver)

    Anyone know about Tayda Electronics? I just found about them now.

    They're out of stock on the MAX7219 at $1.99 :O

    https://www.taydaelectronics.com/max...r-pdip-24.html


    I signed up for a NOTIFY when that's gonna be in stock.

    EDIT: I just noticed they are cleaned out on 7-segment LEDs.
    My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.

    Not as dumb as yesterday, but stupider than tomorrow!

Similar Threads

  1. Replies: 4
    Last Post: - 6th November 2014, 15:11
  2. Replies: 2
    Last Post: - 14th July 2008, 22:11
  3. Replies: 2
    Last Post: - 22nd January 2008, 14:25
  4. Using a MAX7219 (LED digit multiplexer) with a 16F88
    By flotulopex in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 11th March 2007, 21:11
  5. Driver code for 14 segment LED display
    By Durward Searcy in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 12th December 2004, 20:08

Members who have read this thread : 12

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts