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 
Revision:
2:828c62cc1861
Parent:
1:d8589d1f368c
diff -r d8589d1f368c -r 828c62cc1861 MAX7221/Max7221.h
--- a/MAX7221/Max7221.h	Tue Aug 06 08:18:53 2013 +0000
+++ b/MAX7221/Max7221.h	Wed Aug 07 02:15:17 2013 +0000
@@ -1,6 +1,51 @@
+/**
+* @file Max7221.h
+* @brief This file contains the class defnition of Max7221 and define statements related to the class, and max7221 device
+* The methods in this class are derived from posts on the mbed forum written by Igor Skochinsky on October 2009
+* 
+* @author Dwayne S. Dilbeck
+*
+* @date 8/6/2013
+*/
 #ifndef Max7221_H
 #define Max7221_H
 
+/** Max7221 Example
+ * @code
+ * #include "mbed.h"
+ * #include "Max7221.h"
+ *  
+ * 
+ * // p5: DIN, p7: CLK, p8: LOAD/CS
+ * Max7221 max7221disp1(p5, p7, p8);
+ * //Max7221 max7221disp2(p5, p7, p8);
+ * //Max7221 max7221disp3(p11, p13, p14);
+ * //Max7221 max7221disp4(p11, p13, p14);
+ * 
+ * int count=-99;
+ * 
+ * void loop(void) {
+ *    max7221disp1.WriteInt(count);
+ *    if (count < 100)
+ *       count=count+1;
+ *    else 
+ *      count=-99; 
+ * }
+ * 
+ * int main() {  
+ *     max7221disp1.Setup();
+ *     //Max7221::SetupALl();
+ *     max7221disp1.WriteFloat(123.125);
+ *     wait(1.0);  
+ * 
+ *     while (1) {
+ *         loop(); 
+ *         wait(1.0);
+ *     }
+ * }
+ * @endcode
+ */
+
 // define max7219/max7221 registers
 #define max7219_reg_noop         0x00
 #define max7219_reg_digit0       0x01
@@ -29,40 +74,106 @@
 
 class Max7221 {
 public:
+/**
+*  Constructor. This is the default constructor
+*  @author Dwayne S. Dilbeck
+*  @param msoi  The SPI pin used as input to the device.       Valid values for LPC1768 are p5 or p11
+*  @param mclk  The SPI pin used as clock for the device.      Valid values for LPC1768 are p7 or p13
+*  @param load  The pin used to control load for the device.   Any pin capable for DigitalOut can be used, but the same load pin must be used for 
+*    device that share the same msoi and mclk pins
+*  @date 8/6/2013
+*/
    Max7221(PinName msoi=p5, PinName mclk=p7, PinName load=p8);
    
-   void Write( unsigned int reg, unsigned int col);
+/**
+*  This method is used to write a byte of data to a specified register for only the device defined in this class instance
+*  @author Dwayne S. Dilbeck
+*  @param reg  The register to write to.
+*  @param data The value to be written.
+*  @date 8/6/2013   
+*/
+   void Write( unsigned int reg, unsigned int data);
+
+/**
+*  This method is used to display an integer to the specified device instance. Underflow and overflow result in '-' written to all digits
+*  @author Dwayne S. Dilbeck
+*  @param value  An integer value to display
+*  @date 8/6/2013   
+*/   
+   void WriteInt( int value );
+
+/**
+*  This method is used to display a floating point number to the specified device instance. 
+*   Underflow and overflow result in '-' written to all digits. The digits after the decimal 
+*   point are truncated to fit the display.
+*  @author Dwayne S. Dilbeck
+*  @param value  A float value to display
+*  @date 8/6/2013   
+*/   
+   void WriteFloat( float value);
    
-   void WriteInt( int value );
-   void WriteFloat( float value);
+/**
+*  Overload of the EQUALS operator to provide easy use of the class.
+*  @author Dwayne S. Dilbeck
+*  @param value  An integer value to display
+*  @date 8/6/2013   
+*/   
+   
    Max7221& operator= (int value){ 
         WriteInt(value); 
         return *this;
         };
+/**
+*  Overload of the EQUALS operator to provide easy use of the class.
+*  @author Dwayne S. Dilbeck
+*  @param value  A float value to display
+*  @date 8/6/2013   
+*/   
+
    Max7221& operator= (float value){ 
         WriteFloat(value); 
         return *this; 
         };
-   
+/**
+*  This method is used to write an  intial set off values to the device to prepare it for use.
+*  @author Dwayne S. Dilbeck
+*  @date 8/6/2013   
+*/   
    void Setup (void);
-   
-   static void WriteAll (unsigned int reg, unsigned int col);
+
+/**
+*  This method is used to write a byte of data to a specified register for all the devices instantiated.
+*  @author Dwayne S. Dilbeck
+*  @param reg  The register to write to.
+*  @param data The value to be written.
+*  @date 8/6/2013   
+*/   
+   static void WriteAll (unsigned int reg, unsigned int data);
+
+/**
+*  This method is used to write an intial set off values to ALL device to prepare them for use.
+*  @author Dwayne S. Dilbeck
+*  @date 8/6/2013   
+*/   
    static void SetupAll (void);
    
 private:
+   /// Pointer for the class instance to a particular SPI bus
    SPI *max72_spi;
+   /// pointer for the class instance of a particular load signal
    DigitalOut *load;
+   ///  id of the class instance
    int id;
+   /// pointer to the number of devices connected to the SPI bus instance this device instance is connected to.
    int *maxInUse;
    
-   
+   ///For the class we have a static set of values.  There are 2 SPI buses, 2 load signals, and 2 counters of the number of devices connected to a SPI bus.
    static SPI *spi1;
    static SPI *spi2;
    static DigitalOut *load1;
    static DigitalOut *load2;
    static int maxInUseSPI1;
    static int maxInUseSPI2;
-   
 };
 
 #endif
\ No newline at end of file