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 
Committer:
jakowisp
Date:
Tue Aug 06 08:18:53 2013 +0000
Revision:
1:d8589d1f368c
Child:
2:828c62cc1861
Library mostly complete. Need to clean up code and document.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jakowisp 1:d8589d1f368c 1 #ifndef Max7221_H
jakowisp 1:d8589d1f368c 2 #define Max7221_H
jakowisp 1:d8589d1f368c 3
jakowisp 1:d8589d1f368c 4 // define max7219/max7221 registers
jakowisp 1:d8589d1f368c 5 #define max7219_reg_noop 0x00
jakowisp 1:d8589d1f368c 6 #define max7219_reg_digit0 0x01
jakowisp 1:d8589d1f368c 7 #define max7219_reg_digit1 0x02
jakowisp 1:d8589d1f368c 8 #define max7219_reg_digit2 0x03
jakowisp 1:d8589d1f368c 9 #define max7219_reg_digit3 0x04
jakowisp 1:d8589d1f368c 10 #define max7219_reg_digit4 0x05
jakowisp 1:d8589d1f368c 11 #define max7219_reg_digit5 0x06
jakowisp 1:d8589d1f368c 12 #define max7219_reg_digit6 0x07
jakowisp 1:d8589d1f368c 13 #define max7219_reg_digit7 0x08
jakowisp 1:d8589d1f368c 14 #define max7219_reg_decodeMode 0x09
jakowisp 1:d8589d1f368c 15 #define max7219_reg_intensity 0x0a
jakowisp 1:d8589d1f368c 16 #define max7219_reg_scanLimit 0x0b
jakowisp 1:d8589d1f368c 17 #define max7219_reg_shutdown 0x0c
jakowisp 1:d8589d1f368c 18 #define max7219_reg_displayTest 0x0f
jakowisp 1:d8589d1f368c 19
jakowisp 1:d8589d1f368c 20 #define LOW 0
jakowisp 1:d8589d1f368c 21 #define HIGH 1
jakowisp 1:d8589d1f368c 22 #define MHZ 1000000
jakowisp 1:d8589d1f368c 23 #define NUMDIGITS 8
jakowisp 1:d8589d1f368c 24
jakowisp 1:d8589d1f368c 25 #ifdef NUMDIGITS
jakowisp 1:d8589d1f368c 26 #define UPPERBOUND 99999999
jakowisp 1:d8589d1f368c 27 #define LOWERBOUND -9999999
jakowisp 1:d8589d1f368c 28 #endif
jakowisp 1:d8589d1f368c 29
jakowisp 1:d8589d1f368c 30 class Max7221 {
jakowisp 1:d8589d1f368c 31 public:
jakowisp 1:d8589d1f368c 32 Max7221(PinName msoi=p5, PinName mclk=p7, PinName load=p8);
jakowisp 1:d8589d1f368c 33
jakowisp 1:d8589d1f368c 34 void Write( unsigned int reg, unsigned int col);
jakowisp 1:d8589d1f368c 35
jakowisp 1:d8589d1f368c 36 void WriteInt( int value );
jakowisp 1:d8589d1f368c 37 void WriteFloat( float value);
jakowisp 1:d8589d1f368c 38 Max7221& operator= (int value){
jakowisp 1:d8589d1f368c 39 WriteInt(value);
jakowisp 1:d8589d1f368c 40 return *this;
jakowisp 1:d8589d1f368c 41 };
jakowisp 1:d8589d1f368c 42 Max7221& operator= (float value){
jakowisp 1:d8589d1f368c 43 WriteFloat(value);
jakowisp 1:d8589d1f368c 44 return *this;
jakowisp 1:d8589d1f368c 45 };
jakowisp 1:d8589d1f368c 46
jakowisp 1:d8589d1f368c 47 void Setup (void);
jakowisp 1:d8589d1f368c 48
jakowisp 1:d8589d1f368c 49 static void WriteAll (unsigned int reg, unsigned int col);
jakowisp 1:d8589d1f368c 50 static void SetupAll (void);
jakowisp 1:d8589d1f368c 51
jakowisp 1:d8589d1f368c 52 private:
jakowisp 1:d8589d1f368c 53 SPI *max72_spi;
jakowisp 1:d8589d1f368c 54 DigitalOut *load;
jakowisp 1:d8589d1f368c 55 int id;
jakowisp 1:d8589d1f368c 56 int *maxInUse;
jakowisp 1:d8589d1f368c 57
jakowisp 1:d8589d1f368c 58
jakowisp 1:d8589d1f368c 59 static SPI *spi1;
jakowisp 1:d8589d1f368c 60 static SPI *spi2;
jakowisp 1:d8589d1f368c 61 static DigitalOut *load1;
jakowisp 1:d8589d1f368c 62 static DigitalOut *load2;
jakowisp 1:d8589d1f368c 63 static int maxInUseSPI1;
jakowisp 1:d8589d1f368c 64 static int maxInUseSPI2;
jakowisp 1:d8589d1f368c 65
jakowisp 1:d8589d1f368c 66 };
jakowisp 1:d8589d1f368c 67
jakowisp 1:d8589d1f368c 68 #endif