Programme de démo pour la gestion de 4 afficheurs 64 leds

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
vermaelen
Date:
Wed Jun 08 07:11:52 2022 +0000
Parent:
1:61f61158c345
Commit message:
V1

Changed in this revision

ascii_char.h Show annotated file Show diff for this revision Revisions of this file
lib_matrix.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 61f61158c345 -r 675b923da5d2 ascii_char.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ascii_char.h	Wed Jun 08 07:11:52 2022 +0000
@@ -0,0 +1,104 @@
+#ifndef ASCII_CHART_H
+#define ASCII_CHART_H
+//------------------------------------------------------------------------------
+unsigned const char symbol[97][8] =
+{
+     { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }, //Ascii-32
+     { 0x00,0x00,0x00,0x5F,0x5F,0x00,0x00,0x00 }, //Ascii-33
+     { 0x00,0x07,0x07,0x00,0x00,0x07,0x07,0x00 }, //Ascii-34
+     { 0x24,0x7E,0x7E,0x24,0x7E,0x7E,0x24,0x00 }, //Ascii-35
+     { 0x00,0x24,0x2E,0x6B,0x6B,0x3A,0x12,0x00 }, //Ascii-36
+     { 0x00,0x66,0x36,0x18,0x0C,0x66,0x62,0x00 }, //Ascii-37
+     { 0x30,0x7A,0x4F,0x5D,0x37,0x72,0x50,0x00 }, //Ascii-38
+     { 0x00,0x00,0x00,0x07,0x07,0x00,0x00,0x00 }, //Ascii-39
+     { 0x00,0x00,0x00,0x3E,0x7F,0x63,0x41,0x00 }, //Ascii-40
+     { 0x00,0x41,0x63,0x7F,0x3E,0x00,0x00,0x00 }, //Ascii-41
+     { 0x08,0x2A,0x3E,0x1C,0x1C,0x3E,0x2A,0x08 }, //Ascii-42
+     { 0x00,0x08,0x08,0x3E,0x3E,0x08,0x08,0x00 }, //Ascii-43
+     { 0x00,0x80,0xE0,0x60,0x00,0x00,0x00,0x00 }, //Ascii-44
+     { 0x00,0x08,0x08,0x08,0x08,0x08,0x08,0x00 }, //Ascii-45
+     { 0x00,0x00,0x00,0x60,0x60,0x00,0x00,0x00 }, //Ascii-46
+     { 0x00,0x60,0x30,0x18,0x0C,0x06,0x03,0x00 }, //Ascii-47
+     { 0x00,0x3E,0x7F,0x49,0x45,0x7F,0x3E,0x00 }, //Ascii-48
+     { 0x00,0x40,0x42,0x7F,0x7F,0x40,0x40,0x00 }, //Ascii-49
+     { 0x00,0x42,0x63,0x71,0x59,0x4F,0x46,0x00 }, //Ascii-50
+     { 0x00,0x21,0x61,0x45,0x4F,0x7B,0x31,0x00 }, //Ascii-51
+     { 0x00,0x18,0x1C,0x16,0x7F,0x7F,0x10,0x00 }, //Ascii-52
+     { 0x00,0x27,0x67,0x45,0x45,0x7D,0x39,0x00 }, //Ascii-53
+     { 0x00,0x3E,0x7F,0x49,0x49,0x79,0x30,0x00 }, //Ascii-54
+     { 0x00,0x01,0x71,0x79,0x0D,0x07,0x03,0x00 }, //Ascii-55
+     { 0x00,0x36,0x7F,0x49,0x49,0x7F,0x36,0x00 }, //Ascii-56
+     { 0x00,0x06,0x4F,0x49,0x69,0x3F,0x1E,0x00 }, //Ascii-57
+     { 0x00,0x00,0x00,0x36,0x36,0x00,0x00,0x00 }, //Ascii-58
+     { 0x00,0x00,0x40,0x76,0x36,0x00,0x00,0x00 }, //Ascii-59
+     { 0x00,0x00,0x08,0x1C,0x36,0x63,0x41,0x00 }, //Ascii-60
+     { 0x00,0x24,0x24,0x24,0x24,0x24,0x24,0x00 }, //Ascii-61
+     { 0x00,0x41,0x63,0x36,0x1C,0x08,0x00,0x00 }, //Ascii-62
+     { 0x00,0x02,0x03,0x51,0x59,0x0F,0x06,0x00 }, //Ascii-63
+     { 0x00,0x3E,0x7F,0x41,0x5D,0x57,0x5E,0x00 }, //Ascii-64
+     { 0x00,0x7C,0x7E,0x13,0x13,0x7E,0x7C,0x00 }, //Ascii-65
+     { 0x00,0x7F,0x7F,0x49,0x49,0x7F,0x36,0x00 }, //Ascii-66
+     { 0x00,0x3E,0x7F,0x41,0x41,0x63,0x22,0x00 }, //Ascii-67
+     { 0x00,0x7F,0x7F,0x41,0x63,0x3E,0x1C,0x00 }, //Ascii-68
+     { 0x00,0x7F,0x7F,0x49,0x49,0x49,0x41,0x00 }, //Ascii-69
+     { 0x00,0x7F,0x7F,0x09,0x09,0x09,0x01,0x00 }, //Ascii-70
+     { 0x00,0x3E,0x7F,0x41,0x49,0x79,0x79,0x00 }, //Ascii-71
+     { 0x00,0x7F,0x7F,0x08,0x08,0x7F,0x7F,0x00 }, //Ascii-72
+     { 0x00,0x00,0x41,0x7F,0x7F,0x41,0x00,0x00 }, //Ascii-73
+     { 0x00,0x20,0x60,0x40,0x40,0x7F,0x3F,0x00 }, //Ascii-74
+     { 0x00,0x7F,0x7F,0x1C,0x36,0x63,0x41,0x00 }, //Ascii-75
+     { 0x00,0x7F,0x7F,0x40,0x40,0x40,0x40,0x00 }, //Ascii-76
+     { 0x7F,0x7F,0x06,0x0C,0x06,0x7F,0x7F,0x00 }, //Ascii-77
+     { 0x00,0x7F,0x7F,0x0E,0x1C,0x7F,0x7F,0x00 }, //Ascii-78
+     { 0x00,0x3E,0x7F,0x41,0x41,0x7F,0x3E,0x00 }, //Ascii-79
+     { 0x00,0x7F,0x7F,0x09,0x09,0x0F,0x06,0x00 }, //Ascii-80
+     { 0x00,0x3E,0x7F,0x51,0x21,0x7F,0x5E,0x00 }, //Ascii-81
+     { 0x00,0x7F,0x7F,0x09,0x19,0x7F,0x66,0x00 }, //Ascii-82
+     { 0x00,0x26,0x6F,0x49,0x49,0x7B,0x32,0x00 }, //Ascii-83
+     { 0x00,0x01,0x01,0x7F,0x7F,0x01,0x01,0x00 }, //Ascii-84
+     { 0x00,0x3F,0x7F,0x40,0x40,0x7F,0x7F,0x00 }, //Ascii-85
+     { 0x00,0x1F,0x3F,0x60,0x60,0x3F,0x1F,0x00 }, //Ascii-86
+     { 0x7F,0x7F,0x30,0x18,0x30,0x7F,0x7F,0x00 }, //Ascii-87
+     { 0x00,0x63,0x77,0x1C,0x1C,0x77,0x63,0x00 }, //Ascii-88
+     { 0x00,0x07,0x0F,0x78,0x78,0x0F,0x07,0x00 }, //Ascii-89
+     { 0x00,0x61,0x71,0x59,0x4D,0x47,0x43,0x00 }, //Ascii-90
+     { 0x00,0x00,0x00,0x7F,0x7F,0x41,0x41,0x00 }, //Ascii-91
+     { 0x00,0x03,0x06,0x0C,0x18,0x30,0x60,0x00 }, //Ascii-92
+     { 0x00,0x41,0x41,0x7F,0x7F,0x00,0x00,0x00 }, //Ascii-93
+     { 0x08,0x0C,0x06,0x03,0x06,0x0C,0x08,0x00 }, //Ascii-94
+     { 0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x00 }, //Ascii-95
+     { 0x02,0x06,0x0C,0x08,0x00,0x00,0x00,0x00 }, //Ascii-96
+     { 0x00,0x20,0x74,0x54,0x54,0x7C,0x78,0x00 }, //Ascii-97
+     { 0x00,0x7F,0x7F,0x44,0x44,0x7C,0x38,0x00 }, //Ascii-98
+     { 0x00,0x38,0x7C,0x44,0x44,0x44,0x00,0x00 }, //Ascii-99
+     { 0x00,0x38,0x7C,0x44,0x44,0x7F,0x7F,0x00 }, //Ascii-100
+     { 0x00,0x38,0x7C,0x54,0x54,0x5C,0x18,0x00 }, //Ascii-101
+     { 0x00,0x04,0x7E,0x7F,0x05,0x05,0x00,0x00 }, //Ascii-102
+     { 0x00,0x98,0xBC,0xA4,0xA4,0xFC,0x7C,0x00 }, //Ascii-103
+     { 0x00,0x7F,0x7F,0x04,0x04,0x7C,0x78,0x00 }, //Ascii-104
+     { 0x00,0x00,0x44,0x7D,0x7D,0x40,0x00,0x00 }, //Ascii-105
+     { 0x00,0x80,0x80,0xFD,0x7D,0x00,0x00,0x00 }, //Ascii-106
+     { 0x00,0x7F,0x7F,0x10,0x38,0x6C,0x44,0x00 }, //Ascii-107
+     { 0x00,0x00,0x41,0x7F,0x7F,0x40,0x00,0x00 }, //Ascii-108
+     { 0x7C,0x7C,0x0C,0x18,0x0C,0x7C,0x78,0x00 }, //Ascii-109
+     { 0x00,0x7C,0x7C,0x04,0x04,0x7C,0x78,0x00 }, //Ascii-110
+     { 0x00,0x38,0x7C,0x44,0x44,0x7C,0x38,0x00 }, //Ascii-111
+     { 0x00,0xFC,0xFC,0x44,0x44,0x7C,0x38,0x00 }, //Ascii-112
+     { 0x00,0x38,0x7C,0x44,0x44,0xFC,0xFC,0x00 }, //Ascii-113
+     { 0x00,0x7C,0x7C,0x04,0x04,0x0C,0x08,0x00 }, //Ascii-114
+     { 0x00,0x48,0x5C,0x54,0x54,0x74,0x24,0x00 }, //Ascii-115
+     { 0x00,0x04,0x04,0x3E,0x7E,0x44,0x44,0x00 }, //Ascii-116
+     { 0x00,0x3C,0x7C,0x40,0x40,0x7C,0x7C,0x00 }, //Ascii-117
+     { 0x00,0x1C,0x3C,0x60,0x60,0x3C,0x1C,0x00 }, //Ascii-118
+     { 0x1C,0x7C,0x60,0x30,0x60,0x7C,0x1C,0x00 }, //Ascii-119
+     { 0x00,0x44,0x6C,0x38,0x38,0x6C,0x44,0x00 }, //Ascii-120
+     { 0x00,0x9C,0xBC,0xA0,0xA0,0xFC,0x7C,0x00 }, //Ascii-121
+     { 0x00,0x44,0x64,0x74,0x5C,0x4C,0x44,0x00 }, //Ascii-122
+     { 0x00,0x00,0x08,0x3E,0x77,0x41,0x41,0x00 }, //Ascii-123
+     { 0x00,0x00,0x00,0xFF,0xFF,0x00,0x00,0x00 }, //Ascii-124
+     { 0x00,0x41,0x41,0x77,0x3E,0x08,0x00,0x00 }, //Ascii-125
+     { 0x0C,0x06,0x06,0x0C,0x18,0x18,0x0C,0x00 }, //Ascii-126
+     { 0x00,0x60,0x78,0x5E,0x46,0x58,0x60,0x00 }  //Ascii-127
+};
+//------------------------------------------------------------------------------
+#endif
\ No newline at end of file
diff -r 61f61158c345 -r 675b923da5d2 lib_matrix.h
--- a/lib_matrix.h	Mon Mar 28 10:11:31 2022 +0000
+++ b/lib_matrix.h	Wed Jun 08 07:11:52 2022 +0000
@@ -1,25 +1,29 @@
-const unsigned char led_H[]= {
-    0xFF,0x18,0x18,0x18,0x18,0x18,0x18,0xFF
-};  //H
-const unsigned char led_E[]= {
-    0xFF,0xFF,0x99,0x99,0x99,0x99,0x99,0x99
-};  //E
-const unsigned char led_L[]= {
-    0xFF,0xFF,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0
-};  //L
-const unsigned char led_O[]= {
-    0x7E,0x81,0x81,0x81,0x81,0x81,0x81,0x7E
-};  //O
-const unsigned char led_W[]= {
-    0x1F,0x60,0x80,0x40,0x40,0x80,0x60,0x1F
-};  //W
-const unsigned char led_blank[]= {
+//------------------------------------------------------------------------------
+#define NO_OP_REG           0x00     //Used for Max7219 Cascading purposes
+#define DECODE_MODE_REG     0x09
+#define INTESITY_REG        0x0A
+#define SCAN_LIMIT_REG      0x0B
+#define SHUTDOWN_REG        0x0C
+#define DISPLAY_TEST_REG    0x0F
+//------------------------------------------------------------------------------
+#define DISABLE_DECODE      0x00
+#define BRIGHTNESS          0x05
+#define SCAN_ALL_DIGITS     0x07
+#define SHUTDOWN_MODE       0x00
+#define NORMAL_OPERATION    0x01
+#define DISABLE_TEST        0x00
+
+
+unsigned const char led_blank[]= {
     0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
 };  //blank
-const unsigned char led_heart[]= {
+unsigned const char led_heart[]= {
     0x18,0x7E,0x7E,0xF8,0xF8,0x7E,0x7E,0x18
 };  //heart
 
-void disp(char c);
-void SPI_Write2(unsigned char MSB, unsigned char LSB);
-void Init_MAX7219(void);
+void MAX7219_NoOperation();
+void MAX7219_write(char regName,char data,char chip);
+void MAX7219_displayText(char* text);
+void MAX7219_init(char noChips);
+void MAX7219_config(char chip);
+void MAX7219_display(unsigned const char led[], char no_chip);
diff -r 61f61158c345 -r 675b923da5d2 main.cpp
--- a/main.cpp	Mon Mar 28 10:11:31 2022 +0000
+++ b/main.cpp	Wed Jun 08 07:11:52 2022 +0000
@@ -7,87 +7,98 @@
 
 #include "mbed.h"
 #include "lib_matrix.h"
+#include "ascii_char.h"
 
 SPI spi(D11,D12,D13);          // Arduino compatible MOSI, MISO, SCLK
-DigitalOut cs(D14);                // Chip select
+DigitalOut cs(D14);
 
-int main()
+void MAX7219_init(char noChips)
 {
     cs = 1;                         // CS initially High
     spi.format(8,0);                // 8-bit format, mode 0,0
     spi.frequency(1000000);         // SCLK = 1 MHz
-    Init_MAX7219();                 // Initialize the LED controller
-    char tab[20]="HELLOWO&&&";
-    int i=0;
-    while (1) {
-        disp(tab[i]);
-        i=(i+1)%10;
-        wait(0.5);
-        disp(' ');
-        wait(0.1);        // 1 sec delay
+    while(noChips)
+        MAX7219_config(--noChips);
+}
+//------------------------------------------------------------------------------
+void MAX7219_config(char chip)
+{
+    MAX7219_write(DECODE_MODE_REG,DISABLE_DECODE,chip);
+    MAX7219_write(INTESITY_REG,BRIGHTNESS,chip);
+    MAX7219_write(SCAN_LIMIT_REG,SCAN_ALL_DIGITS,chip);
+    MAX7219_write(SHUTDOWN_REG,NORMAL_OPERATION,chip);
+    MAX7219_write(DISPLAY_TEST_REG,DISABLE_TEST,chip);
+}
+//------------------------------------------------------------------------------
+void MAX7219_write(char regName,char data,char chip)
+{
+    cs = 0;
+
+    spi.write(regName);
+    spi.write(data);
+    while(chip--)
+        MAX7219_NoOperation();        //Used for daisy chained (Cascaded) arrangements
+
+    cs = 1;
+}
+//------------------------------------------------------------------------------
+void MAX7219_displayText(char* text)
+{
+    char chip = 0;
+
+    while(*text) {
+        char row = (*text++) - 32;//(Text-32)...because the first 32 ASCII character codes are none Printable (control chars)
 
+        for(int col = 0; col < 8; col++) {
+            MAX7219_write( col+1, symbol[row][col], chip );
+        }
+
+        chip++;
     }
 }
+void MAX7219_displayText(char* text, char indice, char nb_chip)
+{
+    char chip = 0;
+    char * current_pointer;
+    current_pointer=text+indice;
+    while(chip<nb_chip) {
+        char row = (*current_pointer++) - 32;//(Text-32)...because the first 32 ASCII character codes are none Printable (control chars)
+        for(int col = 0; col < 8; col++) {
+            MAX7219_write( col+1, symbol[row][col], chip );
+        }
+        chip++;
+    }
+}
+void MAX7219_display(unsigned const char led[], char no_chip)
+{
+    for(int col = 0; col < 8; col++) {
+        MAX7219_write( col+1, led[col], no_chip );
+    }
+}
+//-----------Passes the data to the adjacent MAX7219 in the Daisy Chain---------
+void MAX7219_NoOperation()
+{
+    spi.write(NO_OP_REG);
+    spi.write(0x00);                //Don't care (Can be any arbitrary value)
+}
 
-void disp(char c)
+int main()
 {
-    switch(c) {
-        case 'E' :
-            for(int i=1; i<9; i++)      // Write first character (8 rows)
-                SPI_Write2(i,led_E[i-1]);
-            break;
-        case 'H' :
-            for(int i=1; i<9; i++)      // Write first character (8 rows)
-                SPI_Write2(i,led_H[i-1]);
-            break;
-        case 'L' :
-            for(int i=1; i<9; i++)      // Write first character (8 rows)
-                SPI_Write2(i,led_L[i-1]);
-            break;
-        case 'O' :
-            for(int i=1; i<9; i++)      // Write first character (8 rows)
-                SPI_Write2(i,led_O[i-1]);
-            break;
-        case 'W' :                   // 1 sec delay
-            for(int i=1; i<9; i++)      // Write second character
-                SPI_Write2(i,led_W[i-1]);
-            break;
-        case ' ' :                   // 1 sec delay
-            for(int i=1; i<9; i++)      // Write second character
-                SPI_Write2(i,led_blank[i-1]);
-            break;
-        case '&' :                   // 1 sec delay
-            for(int i=1; i<9; i++)      // Write second character
-                SPI_Write2(i,led_heart[i-1]);
-            break;
+    MAX7219_init(4);
+    while(1) {
+        MAX7219_displayText("ABCD");
+        wait(2);
+        MAX7219_displayText("HELL");
+        wait(2);
+        MAX7219_display(led_blank,0);
+        MAX7219_display(led_heart,1);
+        MAX7219_display(led_heart,2);
+        MAX7219_display(led_blank,3);
+        wait(2);
+        for(int i=0;i<7;i++){
+            MAX7219_displayText("HELLO WORLD",i,4);
+            wait(2);
+        }
     }
-}
-/// Send two bytes to SPI bus
-void SPI_Write2(unsigned char MSB, unsigned char LSB)
-{
-    cs = 0;                         // Set CS Low
-    spi.write(MSB);                 // Send two bytes
-    spi.write(LSB);
-    cs = 1;                         // Set CS High
-}
 
-/// MAX7219 initialisation
-void Init_MAX7219(void)
-{
-    SPI_Write2(0x09, 0x00);         // Decoding off
-    SPI_Write2(0x0A, 0x08);         // Brightness to intermediate
-    SPI_Write2(0x0B, 0x07);         // Scan limit = 7
-    SPI_Write2(0x0C, 0x01);         // Normal operation mode
-    SPI_Write2(0x0F, 0x0F);         // Enable display test
-    wait_ms(500);                   // 500 ms delay
-    SPI_Write2(0x01, 0x00);         // Clear row 0.
-    SPI_Write2(0x02, 0x00);         // Clear row 1.
-    SPI_Write2(0x03, 0x00);         // Clear row 2.
-    SPI_Write2(0x04, 0x00);         // Clear row 3.
-    SPI_Write2(0x05, 0x00);         // Clear row 4.
-    SPI_Write2(0x06, 0x00);         // Clear row 5.
-    SPI_Write2(0x07, 0x00);         // Clear row 6.
-    SPI_Write2(0x08, 0x00);         // Clear row 7.
-    SPI_Write2(0x0F, 0x00);         // Disable display test
-    wait_ms(500);                   // 500 ms delay
-}
+}
\ No newline at end of file