This library helps to interface Max7912 with Wiznet w7500 and display different character/digit/string on Dot Matrix LED.

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
kulwantt
Date:
Fri Aug 03 06:43:16 2018 +0000
Commit message:
Interfacing LED dotmatrix with W7500 using Max7219 chip.; The documentation for Max7219 is provided in the below link: -; https://datasheets.maximintegrated.com/en/ds/MAX7219-MAX7221.pdf

Changed in this revision

max7219.cpp Show annotated file Show diff for this revision Revisions of this file
max7219.h Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/max7219.cpp	Fri Aug 03 06:43:16 2018 +0000
@@ -0,0 +1,334 @@
+#include "max7219.h"
+
+DigitalOut cs(D8);
+
+SPI spi(PA_08, NC, PA_06);
+
+char max[]={0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08};
+
+char temp[100];
+char ch[]={
+    0x1c,0x22,0x22,0x32,0x2a,0x26,0x22,0x1c,        //0
+    0x3e,0x08,0x08,0x08,0x08,0x0a,0x0c,0x08, //1
+    0x3e,0x02,0x04,0x08,0x10,0x20,0x22,0x1c, //2
+    0x1e,0x20,0x20,0x1c,0x1c,0x20,0x20,0x1e, //3
+    0x20,0x20,0x20,0x3e,0x22,0x24,0x28,0x30,//4
+    0x1c,0x22,0x20,0x20,0x1e,0x02,0x02,0x3e,//5
+    0x1c,0x22,0x22,0x1e,0x02,0x02,0x22,0x1c,//6
+    0x04,0x04,0x08,0x08,0x10,0x10,0x20,0x3e,//7
+    0x1c,0x22,0x22,0x3e,0x3e,0x22,0x22,0x1c,//8
+    0x1c,0x22,0x20,0x20,0x3c,0x22,0x22,0x1c,//9
+    
+    
+      //Symbol needs to be defined  
+     0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+     0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+     0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+     0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+     0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+     0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+     0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+     
+  
+    0x24,0x24,0x24,0x3c,0x3c,0x24,0x24,0x18,//A
+    0x1e,0x22,0x22,0x1e,0x1e,0x22,0x22,0x1e,//B
+    0x3c,0x02,0x02,0x02,0x02,0x02,0x02,0x3c,//C
+    0x1e,0x22,0x22,0x22,0x22,0x22,0x22,0x1e,//D
+    0x3e,0x02,0x02,0x3e,0x3e,0x02,0x02,0x3e,//E
+    0x02,0x02,0x02,0x3e,0x3e,0x02,0x02,0x3e,//F
+    0x2c,0x2a,0x2a,0x3a,0x02,0x02,0x22,0x1c,//G
+    0x22,0x22,0x22,0x3e,0x3e,0x22,0x22,0x22,//H
+    0x3e,0x08,0x08,0x08,0x08,0x08,0x08,0x3e,//I
+    0x1c,0x12,0x10,0x10,0x10,0x10,0x10,0x7c,//J
+    0x22,0x12,0x0a,0x06,0x06,0x0a,0x12,0x22,//K
+    0x3e,0x02,0x02,0x02,0x02,0x02,0x02,0x02,//L
+    0x42,0x42,0x42,0x42,0x5a,0x5a,0x66,0x42,//M
+    0x42,0x62,0x72,0x5a,0x4e,0x46,0x42,0x42,//N
+    0x1c,0x22,0x22,0x22,0x22,0x22,0x22,0x1c,//O
+    0x02,0x02,0x02,0x1e,0x22,0x22,0x22,0x1e,//P
+    0x7c,0x32,0x2e,0x22,0x22,0x22,0x22,0x1c,//Q
+    0x22,0x12,0x0a,0x06,0x1e,0x22,0x22,0x1e,//R
+    0x1c,0x22,0x30,0x18,0x0c,0x06,0x22,0x1c,//S
+    0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x3e,//T
+    0x1c,0x22,0x22,0x22,0x22,0x22,0x22,0x22,//U
+    0x08,0x1c,0x36,0x22,0x22,0x22,0x22,0x22,//V
+    0x36,0x2a,0x2a,0x2a,0x22,0x22,0x22,0x22,//W
+    0x42,0x42,0x24,0x18,0x18,0x24,0x42,0x42,//X
+    0x08,0x08,0x08,0x08,0x1c,0x22,0x22,0x22,//Y
+    0x7e,0x02,0x04,0x08,0x10,0x20,0x40,0x7e,//Z
+     
+       //Symbol needs to be defined  
+     0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+     0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+     0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+     0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+     0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+     0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+     
+     0x38,0x24,0x24,0x38,0x20,0x1c,0x00,0x00,//a
+     0x1e,0x22,0x22,0x1e,0x02,0x02,0x02,0x00,//b
+     0x1c,0x02,0x02,0x02,0x02,0x1c,0x00,0x00,//c
+     0x3c,0x22,0x22,0x3c,0x20,0x20,0x20,0x00,//d
+     0x1c,0x22,0x02,0x1e,0x22,0x1c,0x00,0x00,//e
+     0x04,0x04,0x04,0x0e,0x04,0x14,0x0c,0x00,//f
+     0x1c,0x12,0x10,0x1c,0x12,0x12,0x1c,0x00,//g
+     0x12,0x12,0x12,0x1e,0x02,0x02,0x02,0x00,//h
+     0x18,0x08,0x08,0x08,0x08,0x00,0x08,0x00,//i
+     0x18,0x08,0x08,0x08,0x08,0x00,0x08,0x00,//j
+     0x12,0x0a,0x06,0x0a,0x12,0x02,0x02,0x00,//k
+     0x1c,0x04,0x04,0x04,0x04,0x04,0x04,0x00,//l
+     0x2a,0x2a,0x2a,0x2a,0x36,0x00,0x00,0x00,//m
+     0x22,0x22,0x22,0x26,0x1a,0x00,0x00,0x00,//n
+     0x1c,0x22,0x22,0x22,0x1c,0x00,0x00,0x00,//o
+     0x02,0x02,0x0e,0x12,0x12,0x0e,0x02,0x00,//p
+     0x10,0x30,0x50,0x1c,0x12,0x12,0x1c,0x00,//q
+     0x02,0x02,0x02,0x22,0x26,0x1a,0x00,0x00,//r
+     0x18,0x24,0x10,0x08,0x24,0x18,0x00,0x00,//s
+     0x08,0x14,0x04,0x04,0x1e,0x04,0x04,0x00,//t
+     0x1c,0x22,0x22,0x22,0x22,0x00,0x00,0x00,//u
+     0x08,0x14,0x22,0x22,0x22,0x00,0x00,0x00,//v
+     0x14,0x2a,0x2a,0x2a,0x2a,0x00,0x00,0x00,//w
+     0x22,0x14,0x08,0x14,0x22,0x00,0x00,0x00,//x
+     0x18,0x24,0x20,0x38,0x24,0x24,0x00,0x00,//y
+     0x3e,0x04,0x08,0x10,0x3e,0x00,0x00,0x00,//z
+    };
+
+max7219::max7219()
+{
+    
+    }
+    
+max7219::~max7219()
+{
+        
+        
+ }
+ 
+ 
+ void max7219::init()
+ {
+
+       spi.format(8,3);
+    
+    spi.frequency(1000000);
+       
+    //  max7219_reg_scanLimit
+    cs=0;
+    spi.write(0x0B);
+    spi.write(0x07);
+    cs=1;
+   
+    // max7219_reg_decodeMode
+    cs=0;
+    spi.write(0x09);
+    spi.write(0x00);
+    cs=1;
+    
+    
+    
+    // Disable shutdown mode
+    cs=0;
+    spi.write(0x0C);
+    spi.write(0x01);
+    cs=1;
+    
+    //display test 
+    cs=0;
+    spi.write(0x0F);
+    spi.write(0x01);  
+    cs=1;
+    wait(1);
+    
+    // normal operation  
+    cs=0;
+    spi.write(0x0F);
+    spi.write(0x00);
+    cs=1;
+    
+    cs=0;
+    spi.write(0x0A);
+    spi.write(0x0F); 
+    cs=1;
+  
+  // To blank all the devices
+    for(int i=0;i<8; i++)
+        {
+         cs=0;
+         spi.write(max[i]);
+         spi.write(0x00);
+          cs=1;
+          }
+          
+}
+ 
+void max7219::send(char* read)
+{
+    
+    
+    
+    int k=0,j,c;
+     while(read[k]!='\0')
+{
+    k++;
+    
+    
+}     
+switch(k){
+    
+    
+    case 0:   for(int i=0;i<8; i++)
+        {
+         cs=0;
+         spi.write(max[i]);
+         spi.write(0x00);
+          cs=1;
+          }
+          break;
+          
+    case 1: 
+    for (j=0;j<k;j++){
+
+    for(int i=0;i<8;i++)
+    {
+        cs=0;
+        spi.write(max[i]);
+        spi.write(ch[((read[j]-48)*8)+i]);
+        
+        for (c=j;c>0;c--)
+        {
+            spi.write(0x00);
+            spi.write(0x00);
+            }
+        cs=1;
+
+        }
+}
+for(int y=3;y>0;y--){
+for(int i=0;i<8;i++)
+{   cs=0;
+    spi.write(max[i]);
+    spi.write(0x00);
+    for (int l=y;l>0;l--)
+    {
+        spi.write(0x00);
+        spi.write(0x00);
+        }
+    cs=1;
+    
+    }}
+break;
+
+case 2:
+for (j=0;j<k;j++){
+
+    for(int i=0;i<8;i++)
+    {
+        cs=0;
+        spi.write(max[i]);
+        spi.write(ch[((read[j]-48)*8)+i]);
+        
+        for (c=j;c>0;c--)
+        {
+            spi.write(0x00);
+            spi.write(0x00);
+            }
+        cs=1;
+
+        }
+}
+for(int y=3;y>1;y--){
+for(int i=0;i<8;i++)
+{
+    cs=0;
+    spi.write(max[i]);
+    spi.write(0x00);
+    for (int l=y;l>0;l--)
+    {
+        spi.write(0x00);
+        spi.write(0x00);
+        }
+    
+    cs=1;
+    }}
+break;
+
+case 3:
+for (j=0;j<k;j++){
+    for(int i=0;i<8;i++)
+    {
+        cs=0;
+        spi.write(max[i]);
+        spi.write(ch[((read[j]-48)*8)+i]);
+        
+        for (c=j;c>0;c--)
+        {
+            spi.write(0x00);
+            spi.write(0x00);
+            }
+        cs=1;
+
+        }
+}
+for(int i=0;i<8;i++)
+{
+    cs=0;
+    spi.write(max[i]);
+    spi.write(0x00);
+    for (int l=3;l>0;l--)
+    {
+        spi.write(0x00);
+        spi.write(0x00);
+        }
+    cs=1;
+    
+    }
+break;
+
+
+    case 4:
+for (j=0;j<k;j++){
+
+    for(int i=0;i<8;i++)
+    {
+        cs=0;
+        spi.write(max[i]);
+        spi.write(ch[((read[j]-48)*8)+i]);
+        
+        for (c=j;c>0;c--)
+        {
+            spi.write(0x00);
+            spi.write(0x00);
+            }
+        cs=1;
+
+        }
+}
+break;
+}
+}
+
+
+void max7219::sendstring(char* read)
+{
+ int j=0,o=0;
+ for(int i=0;i<32;i++)
+{
+    
+    cs=0;
+    spi.write(max[j]);
+    spi.write(read[i]);
+    for(int m=o;m>0;m--)
+        {
+        spi.write(0x00);
+        spi.write(0x00);
+        }
+    cs=1;
+ j++;   
+if(j>7)
+{
+    j=0;
+    o++;
+    }
+    
+}
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/max7219.h	Fri Aug 03 06:43:16 2018 +0000
@@ -0,0 +1,87 @@
+/*
+* This library is tested with Wiznet W7500 and Max7219 Chip to interface the LED Dot Matrix
+* We tested with 4 cascaded Max7219 chip.
+* The connections are as follow:
+
+        W7500            Max7219
+            
+         MOSI (PA_08)   -> Din
+         MISO           -> NC
+         SCK  (PA_06)   -> CLK
+         D8(Digital Pin)-> CS
+         Vcc            -> Vcc
+         Gnd            -> Gnd
+            
+
+*To send any string greater than 4 words, it has to be declared in the scope (ex given below- char Hello[])
+*The link given below helps in creating the particular word/string the user wants to display.
+* link - https://xantorohara.github.io/led-matrix-editor/#a2a2a2bea2a2a2a2|df40405f5f40405f|f710101010101010|7984848484848478
+
+*/
+
+
+/* Example program
+*#include "max7219.h"
+*max7219 m; 
+
+//Defining hex code for "HELLO"
+*char Hello[]={0xa2,0xa2,0xa2,0xbe,0xa2,0xa2,0xa2,0xa2,
+*           0xdf,0x40,0x40,0x5f,0x5f,0x40,0x40,0x5f,
+*            0xf7,0x10,0x10,0x10,0x10,0x10,0x10,0x10,
+*            0x79,0x84,0x84,0x84,0x84,0x84,0x84,0x78};      
+*int main() {
+*    m.init();
+*    while(1){
+      //To send 4 or less letters or digits, use the send fuction 
+*       m.send("123"); 
+*       wait(0.5); //Delay
+
+*        m.send("AbCd");
+*        wait(0.5);
+
+        //To send any word/string use the send string function
+*        m.sendstring(Hello);
+*        wait(0.5);
+
+*            }
+*}
+
+*/
+#ifndef MAX7219_H
+#define MAX7219_H
+
+#include "mbed.h"
+
+#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
+
+
+
+class max7219
+{
+public: 
+
+max7219(); // PA_08, NC, PA_06, digital_pin
+
+~max7219();    
+void init();
+
+void send(char*); 
+
+void sendstring(char*);
+
+private:
+PinName mosi;
+PinName miso;
+PinName sclk;
+PinName load;   
+};
+
+#endif
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Fri Aug 03 06:43:16 2018 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/a7c7b631e539
\ No newline at end of file