Using MAX 7221 LED driver


Closed Thread
Results 1 to 16 of 16
  1. #1
    Nick's Avatar
    Nick Guest

    Default Using MAX 7221 LED driver

    Hi all,

    Can anyone point me to some code samples on how to interface MAX 7221
    with a PIC microcontroller to be able to control 64 LEDs in non-decode mode?
    I need to know how to initialize the 7221, how to access each one of the
    64 LEDs and the steps to refresh the output.

  2. #2
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  3. #3
    Nick's Avatar
    Nick Guest


    Did you find this post helpful? Yes | No

    Default

    Thanks Steve.
    My MAX 7221 is still on order.
    I'll get back to the forum with my findings.

  4. #4
    achuri's Avatar
    achuri Guest


    Did you find this post helpful? Yes | No

    Smile Using 7221 in nodecode mode

    here is some code wrote for this purpose. Works well.


    decode VAR byte
    decode = %00001001
    intens VAR byte
    intens = %00001010
    limit VAR byte
    limit = %00001011
    shutdn VAR byte
    shutdn = %00001100
    test VAR byte
    test = $0F

    intense (set to max)
    LOW PORTD.3
    SHIFTOUT PORTD.2, PORTC.4, 1, [intens\8, %00000111\8]
    SHIFTOUT PORTD.2, PORTC.4, 1, [intens\8, %00001111\8]
    SHIFTOUT PORTD.2, PORTC.4, 1, [intens\8, %00001111\8]
    SHIFTOUT PORTD.2, PORTC.4, 1, [intens\8, %00001111\8]
    HIGH PORTD.3
    'limit (set to scan only 4 of 8 rows) better change this if you want more
    LOW PORTD.3
    SHIFTOUT PORTD.2, PORTC.4, 1, [limit\8, %00000011\8]
    SHIFTOUT PORTD.2, PORTC.4, 1, [limit\8, %00000011\8]
    SHIFTOUT PORTD.2, PORTC.4, 1, [limit\8, %00000011\8]
    SHIFTOUT PORTD.2, PORTC.4, 1, [limit\8, %00000011\8]
    HIGH PORTD.3
    'shutdown (shutdown is not in effect)
    LOW PORTD.3
    SHIFTOUT PORTD.2, PORTC.4, 1, [shutdn\8, %00000001\8]
    SHIFTOUT PORTD.2, PORTC.4, 1, [shutdn\8, %00000001\8]
    SHIFTOUT PORTD.2, PORTC.4, 1, [shutdn\8, %00000001\8]
    SHIFTOUT PORTD.2, PORTC.4, 1, [shutdn\8, %00000001\8]
    HIGH PORTD.3
    'test (testing. all LEDs on.)
    LOW PORTD.3
    SHIFTOUT PORTD.2, PORTC.4, 1, [test\8, %00000001\8]
    SHIFTOUT PORTD.2, PORTC.4, 1, [test\8, %00000001\8]
    SHIFTOUT PORTD.2, PORTC.4, 1, [test\8, %00000001\8]
    SHIFTOUT PORTD.2, PORTC.4, 1, [test\8, %00000001\8]
    HIGH PORTD.3
    pause 1000
    'test (not testing)
    LOW PORTD.3
    SHIFTOUT PORTD.2, PORTC.4, 1, [test\8, %00000000\8]
    SHIFTOUT PORTD.2, PORTC.4, 1, [test\8, %00000000\8]
    SHIFTOUT PORTD.2, PORTC.4, 1, [test\8, %00000000\8]
    SHIFTOUT PORTD.2, PORTC.4, 1, [test\8, %00000000\8]
    HIGH PORTD.3

    row0Var = %01111110
    row1Var = %10000001
    row2Var = %10100101
    row3Var = %10000001
    row4Var = %10100101
    row5Var = %10011001
    row6Var = %10000001
    row7Var = %01111110


    for i = 0 to 7
    LOOKUP i, [%00000001 , %00000010 , %00000011 , %00000100, %00000101, %00000111, %00001000, %00001001 ], rownum

    LOOKUP2 i, [row0Var, row1Var, row2Var, row3Var, row4Var, row5Var, row6Var, row7Var], rowbits

    low porta.0
    low porta.1
    SHIFTOUT porta.2, porta.0, 1, [rownum\8, rowbits\8]
    high porta.1
    next




    _________________________
    _ariel

  5. #5
    JDM160's Avatar
    JDM160 Guest


    Did you find this post helpful? Yes | No

    Red face Help please

    I am trying to use the code achuri posted to better understand how to interface the MaX 7219 with my PIC (18F2331).

    I am having a hard time compiling it because of errors, namely with the rowxVar statements. Obviously what was posted is not complete code, but I need help putting it to use for me.

    Ultimately what I'm trying to do is display a 3 digit number on a 3 digit LED display using the 18F2331. How exactly do I update or write the number to each digit? Any help would be greatly appreciated...

  6. #6
    Join Date
    Nov 2006
    Location
    Tulare CA
    Posts
    4


    Did you find this post helpful? Yes | No

    Default 7219 Code

    The following is code that I wrote for the MAX 7219. This is only the sub that I call to initialize and test the display. This was written for a 16F877 but can be ported to just about anything. I am far from a programmer so if anyone out there can clean this up or make it better please let me know. I know this code works, as we have shipped many units running it. You must, of course, setup your ports and outputs. Hope this helps - if anyone finds this usefull I would love to hear from you! Feel free to cut and paste this but please pass on help to others - we all must stick together!

    LEData VAR PORTC.1
    CLK VAR PORTC.5
    Load VAR PORTC.0




    Max_init:

    ShiftOut LEData,clk,MSBFIRST,[%0000100111111111\16] ' Reg. 9 Decode
    PulsOut Load,10


    ShiftOut LEData,clk,MSBFIRST,[%0000101000001111\16] ' Reg. A Intensity
    PulsOut Load,10


    ShiftOut LEData,clk,MSBFIRST,[%0000101100000111\16] ' Reg. B Scan Limit
    PulsOut Load,10



    ShiftOut LEData,clk,MSBFIRST,[%0000110000000001\16] ' Reg. C Shutdown
    PulsOut Load,10



    ShiftOut LEData,clk,MSBFIRST,[%000011110000000\16] ' Reg. F Display Test
    PulsOut Load,10



    ' Blank the display
    digit = 8
    For x = 1 TO 8

    ShiftOut LEData,clk,MSBFIRST,[digit,$F]
    PulsOut Load,10
    digit = digit - 1

    Next

    ' Test the display by writting 8's to each digit and scrolling them across

    digit = 8
    For x = 1 TO 8

    ShiftOut LEData,clk,MSBFIRST,[digit,8]
    PulsOut Load,10
    Pause 500
    ShiftOut LEData,clk,MSBFIRST,[digit,$F]
    PulsOut Load,10
    digit = digit - 1


    Next





    ' Write H
    digit = 1
    ShiftOut LEData,clk,MSBFIRST,[digit,$C]
    PulsOut Load,10


    ' Write E
    digit = 2
    ShiftOut LEData,clk,MSBFIRST,[digit,$B]
    PulsOut Load,10

    ' Write L
    digit = 3
    ShiftOut LEData,clk,MSBFIRST,[digit,$D]
    PulsOut Load,10
    digit = 4

    ' Write L
    digit = 4
    ShiftOut LEData,clk,MSBFIRST,[digit,$D]
    PulsOut Load,10
    digit = 4

    ' Write 0
    digit = 5
    ShiftOut LEData,clk,MSBFIRST,[digit,0]
    PulsOut Load,10
    digit = 4

    Pause 250

    ' Blink it 5 times

    For x = 1 TO 4

    ShiftOut LEData,clk,MSBFIRST,[%0000110000000000\16] ' Reg. C Shutdown ON
    PulsOut Load,10

    Pause 150


    ShiftOut LEData,clk,MSBFIRST,[%0000110000000001\16] ' Reg. C Shutdown OFF
    PulsOut Load,10

    Pause 200

    Next

    Pause 1000

    Return

  7. #7
    Join Date
    Feb 2010
    Posts
    6


    Did you find this post helpful? Yes | No

    Default does not work

    Unfortunaly none of these projects does not work.
    The program of using the PROTEUS to check.
    I want to do a project with a running line is from PIC 16f877 and driver MAX 7221.

    We also managed if someone let the finished project + program

    I apologize for my English, I am from Ukraine and use a translator Google.

  8. #8
    Join Date
    Feb 2010
    Posts
    6


    Did you find this post helpful? Yes | No

  9. #9
    Join Date
    Nov 2006
    Location
    Tulare CA
    Posts
    4


    Did you find this post helpful? Yes | No

    Default Max 7221

    What about the code does not work? We have shipped many units running this code??
    Have you actually compiled and ran it?
    Plasma Jocky

  10. #10
    Join Date
    Feb 2010
    Posts
    6


    Did you find this post helpful? Yes | No

    Default

    У МЕНЯ НЕ работает код. что-то не так

  11. #11
    Join Date
    Feb 2010
    Posts
    6


    Did you find this post helpful? Yes | No

    Default

    sorry.

    I did not have working code. something wrong

  12. #12
    Join Date
    Nov 2006
    Location
    Tulare CA
    Posts
    4


    Did you find this post helpful? Yes | No

    Default Max 7221

    Did you get the code working?
    Plasma Jocky

  13. #13
    Join Date
    Feb 2010
    Posts
    6


    Did you find this post helpful? Yes | No

    Default

    code received thanks.
    But I can only check on Tuesday, as How many will check immediately write.

    hope to earn.

  14. #14
    Join Date
    Nov 2006
    Location
    Tulare CA
    Posts
    4


    Did you find this post helpful? Yes | No

    Default MAX Display

    I am not sure I understand but you have my email address if you need to contact me. Let me know if you require help.
    Plasma Jocky

  15. #15
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    I guess I am having a hard time figuring why anyone would use this dedicated $12.95 per each chip, when for the same money you can buy a nice spi display or for less use a cheap PIC to do this chips job, that's why I ordered a "sample" so I can learn what you all seem to know.
    http://cgi.ebay.com/1-5-Character-He...item19b9ac644b
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  16. #16
    Join Date
    May 2004
    Posts
    81


    Did you find this post helpful? Yes | No

    Thumbs up

    Ok, here goes my first attempt at a "write up"

    I am currently working on a project using this chip. Most of the information you need to know can be found in the data sheet. Unfortunatly the datasheet can be vauge in some parts so here are the basics:

    The first thing you need to know is that on initial power up, all control registers are reset, the display is blanked, and the IC enters shutdown mode. The chip may be programed while in shutdown mode.

    The first steps to get the IC to work correctly are initializing the IC. here are the key things you need to tell the chip in your intialization routine.

    - how many digits will you be displaying (1 - 8)*
    - which digits will use the internal decoder
    - intensity of display

    * there are special circumstances to take into account if you are using 3 or less digits. Refer to the data sheet.

    The next thing (and most important) people are going to want to know is how to actually send the data to the chip. You will need 3 lines from your PIC. A data line, a clock, and a latch enable. To address the IC you need to send 16 bits of data, MSB first, with the upper 8 bits being the address, and the lower bits being the data. Here is an example of how to send out the data to the chip:

    Code:
    ' In your pics initialization code define the pins for Sout, Clk, and LE where:
    ' Sout = pin for sending data to the data in pin on the max 7219
    ' Clk = pin for clock
    ' LE = pin for Load/Enable 
    
    
    SendCommand:
        ' the spec sheet states "The last 16 bits of data are latched on LOAD's rising edge"
        ' It also states for the 7221 chip that LOAD/CE must be held low to clock in data
        ' So for best practice and compatibility the first step is to bring LE low.
      
        ' The next step is to clock out the 16 bits of data MSBFIRST. This is easily accomplished 
        ' with the shiftout command. Please be sure to include the "modedefs.bas" file at the 
        ' begining of your code for this code to execute correctly.
        ' In this example there are two 8 bit variables named Addr, and cmd. Addr is the address
        ' of the register we want to address. cmd is the data we want to send to the register.
    
        ' Finaly, we need to latch the data sent by bringing LE high
    
    
        Low LE                                      ' Serial data latches on LE high
        shiftout Sout,Clk,MSBFIRST, [Addr,cmd]      ' Shift out cmd address
        High LE                                     ' Latch Data
        
    Return

    Now that we know how to send the register/data commands to the MAX7219, Lets examine the registers. The first register we will want to define is how many digits we are using. Looking at the spec sheet we see that the ScanLimit register is where we define the number of digits, and its address is hex 0B (or 11 decimal). Lets say we want to use 4 digits. We will need to send the value of 3 to address hex 0B (Digits are numbered 0 - 7). We can accomplish this with the following code:

    Code:
    Addr = $0B
    cmd = $03
    Gosub SendCommand
    Lets take another example. This time we will tell the IC which digits we want to use the internal decoder. We will have all 4 digits display numeric data so we look up the value in table 4. We can see by the table we will need to send an 8 bit value from 0 - 255. Each bit in the value represents a digit, and to have the digit use the decoder we set the bit for that digit to 1. To use direct LED addressing, we set the bit for that digit to 0. For clearity, we will write this value in binary format. Since we want the first 4 digits to use the decoder we will send a value of %00001111 to Register $09

    Code:
    Addr = $09
    cmd = %00001111
    Gosub SendCommand

    So as you can see, the chip is farily simple to use. Its simply a matter of telling the chip what address you want to load what value into and sending the 16 bit data.


    To actually display a value, address that digits register and send the value as the data. so for instance, to display a value on our 4 digit example we could use the following routine:

    Code:
    UpdateDisplay:
        ' X must contain value to display.
        ' Y is a byte value    
        For y = 0 to 3         ' address digits 1 - 4
                addr = Y + 1         ' Compensate for address value to digit number drift
                Cmd = X Dig y      ' Get the numerical value of place value in X
                Gosub SendCommand ' Send the command
        Next y
    Return
    The above code will update all 4 digits of the display. Keep in mind that the digits may be addressed individually. For instance, lets say you are displaying a value of 3856 and you want to display a new value of 3456. You would only need to update address 2 (digit 3) to the number 4. the spec sheet also states that these values will be retained so long as V+ exceedes +2VDC

    There is a built in lamp test function. VERY usefull for verifying hardware connections. Please see the data sheet for its register and data information

    Before the chip will display information you will need to address the ShutDown register and bring it out of shutdown mode. Applying a value of 1 to this register will put the device in normal operation while applying a value of 0 will put the device in shutdown. This is somewhat counter-intuitive based on the name of the register.

    Finaly, one more area where people may trip up on the hardware end is the value of Rset. If this is not set correctly you may end up with unpredictable or undesireable results. Looking at table 11 you are presented with values based on segment current and LED Forward Voltage. The values in the chart are resistance values in K-ohms. For example, if our display has a Forward voltage of 2.0 volts, and the desired current is 20mA, we would select a value of
    28K for the Rset resistor value. You can determine this if you are aware the spec sheet states Rset should not be less than 9.53K, however with the table alone this is not very clear.

    I hope this helps clear up the basics of how to use this IC. Using the chip as a basic numeric display driver is fairly straight forward. I myself have been running into issues with using combined decoder and direct LED addressing modes. I will attempt to do another write up specificaly on this subject when I figure it out myself.
    Attached Images Attached Images

Similar Threads

  1. Conway's Game Of Life
    By wellyboot in forum mel PIC BASIC Pro
    Replies: 45
    Last Post: - 28th May 2020, 06:14
  2. Help with LED driver fade on/off
    By dfort in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 25th July 2009, 00:39
  3. new and need help
    By smeghead in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 3rd November 2008, 20:19
  4. Alegro 6276 LED driver?
    By [email protected] in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 2nd August 2007, 00:25
  5. LCD will not start
    By btaylor in forum mel PIC BASIC Pro
    Replies: 49
    Last Post: - 24th May 2007, 02:30

Members who have read this thread : 1

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