![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Programme de démo pour la gestion de 4 afficheurs 64 leds
Diff: main.cpp
- Revision:
- 2:675b923da5d2
- Parent:
- 1:61f61158c345
--- 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