Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp
00001 /* 06_spi_max7219_led8x8 00002 * 00003 * Simple demo to drive a 8x8-as LED matrix by a MAX7219 LED driver IC 00004 * After initialisation two characters (H and W) are displayed alternatively. 00005 * The MAX7219 IC is driven by hardware SPI: SPI0 module at PTD1, PTD2, PTD3. 00006 */ 00007 00008 #include "mbed.h" 00009 #include "lib_matrix.h" 00010 #include "ascii_char_h.h" 00011 00012 SPI spi(D11,D12,D13); // Arduino compatible MOSI, MISO, SCLK 00013 DigitalOut cs(D14); 00014 00015 void MAX7219_init(char noChips) 00016 { 00017 cs = 1; // CS initially High 00018 spi.format(8,0); // 8-bit format, mode 0,0 00019 spi.frequency(1000000); // SCLK = 1 MHz 00020 while(noChips) 00021 MAX7219_config(--noChips); 00022 } 00023 //------------------------------------------------------------------------------ 00024 void MAX7219_config(char chip) 00025 { 00026 MAX7219_write(DECODE_MODE_REG,DISABLE_DECODE,chip); 00027 MAX7219_write(INTESITY_REG,BRIGHTNESS,chip); 00028 MAX7219_write(SCAN_LIMIT_REG,SCAN_ALL_DIGITS,chip); 00029 MAX7219_write(SHUTDOWN_REG,NORMAL_OPERATION,chip); 00030 MAX7219_write(DISPLAY_TEST_REG,DISABLE_TEST,chip); 00031 } 00032 //------------------------------------------------------------------------------ 00033 void MAX7219_write(char regName,char data,char chip) 00034 { 00035 cs = 0; 00036 00037 spi.write(regName); 00038 spi.write(data); 00039 while(chip--) 00040 MAX7219_NoOperation(); //Used for daisy chained (Cascaded) arrangements 00041 00042 cs = 1; 00043 } 00044 //------------------------------------------------------------------------------ 00045 void MAX7219_displayText(char* text) 00046 { 00047 char chip = 0; 00048 00049 while(*text) { 00050 char row = (*text++) - 32;//(Text-32)...because the first 32 ASCII character codes are none Printable (control chars) 00051 00052 for(int col = 0; col < 8; col++) { 00053 MAX7219_write( col+1, symbol_h[row][col], chip ); 00054 } 00055 00056 chip++; 00057 } 00058 } 00059 void MAX7219_displayText(char* text, char indice, char nb_chip) 00060 { 00061 char chip = 0; 00062 char * current_pointer; 00063 current_pointer=text+indice; 00064 while(chip<nb_chip) { 00065 char row = (*current_pointer++) - 32;//(Text-32)...because the first 32 ASCII character codes are none Printable (control chars) 00066 for(int col = 0; col < 8; col++) { 00067 MAX7219_write( col+1, symbol_h[row][col], chip ); 00068 } 00069 chip++; 00070 } 00071 } 00072 void MAX7219_display(unsigned const char led[], char no_chip) 00073 { 00074 for(int col = 0; col < 8; col++) { 00075 MAX7219_write( col+1, led[col], no_chip ); 00076 } 00077 } 00078 //-----------Passes the data to the adjacent MAX7219 in the Daisy Chain--------- 00079 void MAX7219_NoOperation() 00080 { 00081 spi.write(NO_OP_REG); 00082 spi.write(0x00); //Don't care (Can be any arbitrary value) 00083 } 00084 00085 int main() 00086 { 00087 MAX7219_init(4); 00088 while(1) { 00089 MAX7219_displayText("ABCD"); 00090 wait(2); 00091 MAX7219_displayText("HELL"); 00092 wait(2); 00093 MAX7219_display(led_blank,0); 00094 MAX7219_display(led_heart,1); 00095 MAX7219_display(led_heart,2); 00096 MAX7219_display(led_blank,3); 00097 wait(2); 00098 for(int i=0;i<7;i++){ 00099 MAX7219_displayText("HELLO WORLD",i,4); 00100 wait(2); 00101 } 00102 } 00103 00104 }
Generated on Wed Aug 3 2022 05:57:10 by
1.7.2