A generic library to support Max7221 chip for 8 digit 7 segment displays

Dependencies:   mbed

Dependents:   Example_Max7221

MAXIM SPI interfaced, 8 digit LED display Driver

MAX221

  • The image below was my initial development setup. The top of the image shows a wire wrap connection to a Max7221 to an 8 digit 7 segment display.
  • The small board below it is the new max7221 board that was created with surface mount chips and using a toaster oven to do reflow soldering. /media/uploads/jakowisp/img_0012.jpg

Example of using a single Max7221 on SPI p5,p6,p7

Import program

00001  #include "mbed.h"
00002  #include "Max7221.h"
00003  
00004 
00005 // p5: DIN, p7: CLK, p8: LOAD/CS
00006 Max7221 max7221disp1(p5, p7, p8);
00007 //Max7221 max7221disp2(p5, p7, p8);
00008 //Max7221 max7221disp3(p11, p13, p14);
00009 //Max7221 max7221disp4(p11, p13, p14);
00010 
00011 int count=-99;
00012 
00013 void loop(void) {
00014    max7221disp1=count;
00015    if (count < 100)
00016       count=count+1;
00017    else 
00018       count=-99; 
00019 }
00020 
00021 int main() {  
00022     max7221disp1.Setup();
00023     //Max7221::SetupALl();
00024     max7221disp1.WriteFloat(123.125);
00025     wait(1.0);  
00026 
00027     while (1) {
00028         loop();
00029         wait(1.0);
00030     }
00031 }
00032 
00033 

MAX7221/Max7221.h

Committer:
jakowisp
Date:
2013-08-06
Revision:
1:d8589d1f368c
Child:
2:828c62cc1861

File content as of revision 1:d8589d1f368c:

#ifndef Max7221_H
#define Max7221_H

// define max7219/max7221 registers
#define max7219_reg_noop         0x00
#define max7219_reg_digit0       0x01
#define max7219_reg_digit1       0x02
#define max7219_reg_digit2       0x03
#define max7219_reg_digit3       0x04
#define max7219_reg_digit4       0x05
#define max7219_reg_digit5       0x06
#define max7219_reg_digit6       0x07
#define max7219_reg_digit7       0x08
#define max7219_reg_decodeMode   0x09
#define max7219_reg_intensity    0x0a
#define max7219_reg_scanLimit    0x0b
#define max7219_reg_shutdown     0x0c
#define max7219_reg_displayTest  0x0f

#define LOW 0
#define HIGH 1
#define MHZ 1000000
#define NUMDIGITS 8

#ifdef NUMDIGITS 
#define UPPERBOUND 99999999
#define LOWERBOUND -9999999
#endif

class Max7221 {
public:
   Max7221(PinName msoi=p5, PinName mclk=p7, PinName load=p8);
   
   void Write( unsigned int reg, unsigned int col);
   
   void WriteInt( int value );
   void WriteFloat( float value);
   Max7221& operator= (int value){ 
        WriteInt(value); 
        return *this;
        };
   Max7221& operator= (float value){ 
        WriteFloat(value); 
        return *this; 
        };
   
   void Setup (void);
   
   static void WriteAll (unsigned int reg, unsigned int col);
   static void SetupAll (void);
   
private:
   SPI *max72_spi;
   DigitalOut *load;
   int id;
   int *maxInUse;
   
   
   static SPI *spi1;
   static SPI *spi2;
   static DigitalOut *load1;
   static DigitalOut *load2;
   static int maxInUseSPI1;
   static int maxInUseSPI2;
   
};

#endif