This library helps to interface Max7912 with Wiznet w7500 and display different character/digit/string on Dot Matrix LED.
Diff: max7219.cpp
- Revision:
- 0:2c4e3799881a
--- /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++; + } + +} +}