Showing use of Maxim LED Driver with DOT matric LCD Modules

Dependencies:   mbed

Shows the use of the Maxim 7219 with the MBED. Based on some Arduino code (must find the original link)

Committer:
jont
Date:
Sat Feb 14 09:19:34 2015 +0000
Revision:
1:ba7a97159510
Parent:
0:0b95cf14c97b
First Public release

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jont 0:0b95cf14c97b 1 #include "mbed.h"
jont 0:0b95cf14c97b 2 /*
jont 0:0b95cf14c97b 3 example of driving maxim chip for Glasgow Uni Projects.
jont 0:0b95cf14c97b 4
jont 0:0b95cf14c97b 5 Dr J.J.Trinder 2013,14
jont 0:0b95cf14c97b 6 jon.trinder@glasgow.ac.uk
jont 1:ba7a97159510 7 jont@ninelocks.com
jont 0:0b95cf14c97b 8
jont 0:0b95cf14c97b 9 */
jont 0:0b95cf14c97b 10
jont 0:0b95cf14c97b 11 #define max7219_reg_noop 0x00
jont 0:0b95cf14c97b 12 #define max7219_reg_digit0 0x01
jont 0:0b95cf14c97b 13 #define max7219_reg_digit1 0x02
jont 0:0b95cf14c97b 14 #define max7219_reg_digit2 0x03
jont 0:0b95cf14c97b 15 #define max7219_reg_digit3 0x04
jont 0:0b95cf14c97b 16 #define max7219_reg_digit4 0x05
jont 0:0b95cf14c97b 17 #define max7219_reg_digit5 0x06
jont 0:0b95cf14c97b 18 #define max7219_reg_digit6 0x07
jont 0:0b95cf14c97b 19 #define max7219_reg_digit7 0x08
jont 0:0b95cf14c97b 20 #define max7219_reg_decodeMode 0x09
jont 0:0b95cf14c97b 21 #define max7219_reg_intensity 0x0a
jont 0:0b95cf14c97b 22 #define max7219_reg_scanLimit 0x0b
jont 0:0b95cf14c97b 23 #define max7219_reg_shutdown 0x0c
jont 0:0b95cf14c97b 24 #define max7219_reg_displayTest 0x0f
jont 0:0b95cf14c97b 25
jont 0:0b95cf14c97b 26 #define LOW 0
jont 0:0b95cf14c97b 27 #define HIGH 1
jont 0:0b95cf14c97b 28
jont 0:0b95cf14c97b 29 SPI max72_spi(PTD2, NC, PTD1);
jont 0:0b95cf14c97b 30 DigitalOut load(PTD0); //will provide the load signal
jont 0:0b95cf14c97b 31
jont 0:0b95cf14c97b 32
jont 0:0b95cf14c97b 33 char pattern_diagonal[8] = { 0x01, 0x2,0x4,0x08,0x10,0x20,0x40,0x80};
jont 0:0b95cf14c97b 34 char pattern_square[8] = { 0xff, 0x81,0x81,0x81,0x81,0x81,0x81,0xff};
jont 0:0b95cf14c97b 35 char pattern_star[8] = { 0x04, 0x15, 0x0e, 0x1f, 0x0e, 0x15, 0x04, 0x00};
jont 0:0b95cf14c97b 36
jont 0:0b95cf14c97b 37
jont 0:0b95cf14c97b 38 /*
jont 0:0b95cf14c97b 39 Write to the maxim via SPI
jont 0:0b95cf14c97b 40 args register and the column data
jont 0:0b95cf14c97b 41 */
jont 0:0b95cf14c97b 42 void write_to_max( int reg, int col)
jont 0:0b95cf14c97b 43 {
jont 0:0b95cf14c97b 44 load = LOW; // begin
jont 0:0b95cf14c97b 45 max72_spi.write(reg); // specify register
jont 0:0b95cf14c97b 46 max72_spi.write(col); // put data
jont 0:0b95cf14c97b 47 load = HIGH; // make sure data is loaded (on rising edge of LOAD/CS)
jont 0:0b95cf14c97b 48 }
jont 0:0b95cf14c97b 49
jont 0:0b95cf14c97b 50 //writes 8 bytes to the display
jont 0:0b95cf14c97b 51 void pattern_to_display(char *testdata){
jont 0:0b95cf14c97b 52 int cdata;
jont 0:0b95cf14c97b 53 for(int idx = 0; idx <= 7; idx++) {
jont 0:0b95cf14c97b 54 cdata = testdata[idx];
jont 0:0b95cf14c97b 55 write_to_max(idx+1,cdata);
jont 0:0b95cf14c97b 56 }
jont 0:0b95cf14c97b 57 }
jont 0:0b95cf14c97b 58
jont 0:0b95cf14c97b 59
jont 0:0b95cf14c97b 60 void setup_dot_matrix ()
jont 0:0b95cf14c97b 61 {
jont 0:0b95cf14c97b 62 // initiation of the max 7219
jont 0:0b95cf14c97b 63 // SPI setup: 8 bits, mode 0
jont 0:0b95cf14c97b 64 max72_spi.format(8, 0);
jont 0:0b95cf14c97b 65
jont 0:0b95cf14c97b 66
jont 0:0b95cf14c97b 67
jont 0:0b95cf14c97b 68 max72_spi.frequency(100000); //down to 100khx easier to scope ;-)
jont 0:0b95cf14c97b 69
jont 0:0b95cf14c97b 70
jont 0:0b95cf14c97b 71 write_to_max(max7219_reg_scanLimit, 0x07);
jont 0:0b95cf14c97b 72 write_to_max(max7219_reg_decodeMode, 0x00); // using an led matrix (not digits)
jont 0:0b95cf14c97b 73 write_to_max(max7219_reg_shutdown, 0x01); // not in shutdown mode
jont 0:0b95cf14c97b 74 write_to_max(max7219_reg_displayTest, 0x00); // no display test
jont 0:0b95cf14c97b 75 for (int e=1; e<=8; e++) { // empty registers, turn all LEDs off
jont 0:0b95cf14c97b 76 write_to_max(e,0);
jont 0:0b95cf14c97b 77 }
jont 0:0b95cf14c97b 78 // maxAll(max7219_reg_intensity, 0x0f & 0x0f); // the first 0x0f is the value you can set
jont 1:ba7a97159510 79 write_to_max(max7219_reg_intensity, 0x08);
jont 0:0b95cf14c97b 80
jont 0:0b95cf14c97b 81 }
jont 0:0b95cf14c97b 82
jont 0:0b95cf14c97b 83 void clear(){
jont 0:0b95cf14c97b 84 for (int e=1; e<=8; e++) { // empty registers, turn all LEDs off
jont 0:0b95cf14c97b 85 write_to_max(e,0);
jont 0:0b95cf14c97b 86 }
jont 0:0b95cf14c97b 87 }
jont 0:0b95cf14c97b 88
jont 0:0b95cf14c97b 89
jont 0:0b95cf14c97b 90 int main()
jont 0:0b95cf14c97b 91 {
jont 0:0b95cf14c97b 92 setup_dot_matrix (); /* setup matric */
jont 0:0b95cf14c97b 93 while(1){
jont 0:0b95cf14c97b 94 //da_star();
jont 0:0b95cf14c97b 95 pattern_to_display(pattern_diagonal);
jont 0:0b95cf14c97b 96 wait_ms(1000);
jont 0:0b95cf14c97b 97 pattern_to_display(pattern_square);
jont 0:0b95cf14c97b 98 wait_ms(1000);
jont 0:0b95cf14c97b 99 pattern_to_display(pattern_star);
jont 0:0b95cf14c97b 100 wait_ms(1000);
jont 0:0b95cf14c97b 101 clear();
jont 0:0b95cf14c97b 102
jont 0:0b95cf14c97b 103 }
jont 0:0b95cf14c97b 104 }