LEDマトリックス 1枚 その4 スクロール文字表示

Dependencies:   mbed

Committer:
takeuchi
Date:
Fri May 27 06:57:55 2016 +0000
Revision:
0:62ea25b8c31d
LED???????1-4

Who changed what in which revision?

UserRevisionLine numberNew contents of line
takeuchi 0:62ea25b8c31d 1 // LedMatrix 1mai
takeuchi 0:62ea25b8c31d 2
takeuchi 0:62ea25b8c31d 3 #include "mbed.h"
takeuchi 0:62ea25b8c31d 4
takeuchi 0:62ea25b8c31d 5 DigitalOut led(dp28);
takeuchi 0:62ea25b8c31d 6
takeuchi 0:62ea25b8c31d 7 // spi(mosi,miso,sck)
takeuchi 0:62ea25b8c31d 8 SPI max72_spi(dp2, NC, dp6);
takeuchi 0:62ea25b8c31d 9 DigitalOut load(dp14);//spi load
takeuchi 0:62ea25b8c31d 10
takeuchi 0:62ea25b8c31d 11 // CPU MT7219
takeuchi 0:62ea25b8c31d 12 // dp1 mosi(Master In Salve Out) => DIN
takeuchi 0:62ea25b8c31d 13 // dp2 miso(Master OutSlave) => nc
takeuchi 0:62ea25b8c31d 14 // dp6 sck (Serial Clock) => clk
takeuchi 0:62ea25b8c31d 15 // dp14 =>(Slave Select) load
takeuchi 0:62ea25b8c31d 16
takeuchi 0:62ea25b8c31d 17 int maxInUse = 1; //change this variable to set how many MAX7219's you'll use
takeuchi 0:62ea25b8c31d 18
takeuchi 0:62ea25b8c31d 19 // define max7219 registers
takeuchi 0:62ea25b8c31d 20 #define max7219_reg_noop 0x00
takeuchi 0:62ea25b8c31d 21 #define max7219_reg_digit0 0x01
takeuchi 0:62ea25b8c31d 22 #define max7219_reg_digit1 0x02
takeuchi 0:62ea25b8c31d 23 #define max7219_reg_digit2 0x03
takeuchi 0:62ea25b8c31d 24 #define max7219_reg_digit3 0x04
takeuchi 0:62ea25b8c31d 25 #define max7219_reg_digit4 0x05
takeuchi 0:62ea25b8c31d 26 #define max7219_reg_digit5 0x06
takeuchi 0:62ea25b8c31d 27 #define max7219_reg_digit6 0x07
takeuchi 0:62ea25b8c31d 28 #define max7219_reg_digit7 0x08
takeuchi 0:62ea25b8c31d 29 #define max7219_reg_decodeMode 0x09
takeuchi 0:62ea25b8c31d 30 #define max7219_reg_intensity 0x0a
takeuchi 0:62ea25b8c31d 31 #define max7219_reg_scanLimit 0x0b
takeuchi 0:62ea25b8c31d 32 #define max7219_reg_shutdown 0x0c
takeuchi 0:62ea25b8c31d 33 #define max7219_reg_displayTest 0x0f
takeuchi 0:62ea25b8c31d 34
takeuchi 0:62ea25b8c31d 35 #define LOW 0
takeuchi 0:62ea25b8c31d 36 #define HIGH 1
takeuchi 0:62ea25b8c31d 37 #define MHZ 1000000
takeuchi 0:62ea25b8c31d 38 #define ON 1
takeuchi 0:62ea25b8c31d 39 #define OFF 0
takeuchi 0:62ea25b8c31d 40
takeuchi 0:62ea25b8c31d 41 void maxSingle( int reg, int col) {
takeuchi 0:62ea25b8c31d 42 //maxSingle is the "easy" function to use for a
takeuchi 0:62ea25b8c31d 43 //single max7219
takeuchi 0:62ea25b8c31d 44 load = LOW; // begin
takeuchi 0:62ea25b8c31d 45 max72_spi.write(reg); // specify register
takeuchi 0:62ea25b8c31d 46 max72_spi.write(col); // put data
takeuchi 0:62ea25b8c31d 47 load = HIGH; // make sure data is loaded (on rising edge of LOAD/CS)
takeuchi 0:62ea25b8c31d 48 }
takeuchi 0:62ea25b8c31d 49
takeuchi 0:62ea25b8c31d 50 void maxAll (int reg, int col) { // initialize all MAX7219's in the system
takeuchi 0:62ea25b8c31d 51 load = LOW; // begin
takeuchi 0:62ea25b8c31d 52 for ( int c=1; c<= maxInUse; c++) {
takeuchi 0:62ea25b8c31d 53 max72_spi.write(reg); // specify register
takeuchi 0:62ea25b8c31d 54 max72_spi.write(col); // put data
takeuchi 0:62ea25b8c31d 55 }
takeuchi 0:62ea25b8c31d 56 load = HIGH;
takeuchi 0:62ea25b8c31d 57 }
takeuchi 0:62ea25b8c31d 58
takeuchi 0:62ea25b8c31d 59 void maxOne(int maxNr, int reg, int col) {
takeuchi 0:62ea25b8c31d 60 //maxOne is for adressing different MAX7219's,
takeuchi 0:62ea25b8c31d 61 //while having a couple of them cascaded
takeuchi 0:62ea25b8c31d 62 int c = 0;
takeuchi 0:62ea25b8c31d 63 load = LOW;
takeuchi 0:62ea25b8c31d 64
takeuchi 0:62ea25b8c31d 65 for ( c = maxInUse; c >= maxNr; c--) {
takeuchi 0:62ea25b8c31d 66 max72_spi.write(0); // no-op
takeuchi 0:62ea25b8c31d 67 max72_spi.write(0); // no-op
takeuchi 0:62ea25b8c31d 68 }
takeuchi 0:62ea25b8c31d 69
takeuchi 0:62ea25b8c31d 70 max72_spi.write(reg); // specify register
takeuchi 0:62ea25b8c31d 71 max72_spi.write(col); // put data
takeuchi 0:62ea25b8c31d 72
takeuchi 0:62ea25b8c31d 73 for ( c=maxNr-1; c >= 1; c--) {
takeuchi 0:62ea25b8c31d 74 max72_spi.write(0); // no-op
takeuchi 0:62ea25b8c31d 75 max72_spi.write(0); // no-op
takeuchi 0:62ea25b8c31d 76 }
takeuchi 0:62ea25b8c31d 77 load = HIGH;
takeuchi 0:62ea25b8c31d 78 }
takeuchi 0:62ea25b8c31d 79
takeuchi 0:62ea25b8c31d 80 void setup () {
takeuchi 0:62ea25b8c31d 81 // initiation of the max 7219
takeuchi 0:62ea25b8c31d 82 // SPI setup: 8 bits, mode 0
takeuchi 0:62ea25b8c31d 83 max72_spi.format(8, 0);
takeuchi 0:62ea25b8c31d 84
takeuchi 0:62ea25b8c31d 85 // going by the datasheet, min clk is 100ns so theoretically 10MHz should work...
takeuchi 0:62ea25b8c31d 86 // max72_spi.frequency(10*MHZ);
takeuchi 0:62ea25b8c31d 87
takeuchi 0:62ea25b8c31d 88 maxAll(max7219_reg_scanLimit, 0x07);
takeuchi 0:62ea25b8c31d 89 maxAll(max7219_reg_decodeMode, 0x00); // using an led matrix (not digits)
takeuchi 0:62ea25b8c31d 90 maxAll(max7219_reg_shutdown, 0x01); // not in shutdown mode
takeuchi 0:62ea25b8c31d 91 maxAll(max7219_reg_displayTest, 0x00); // no display test
takeuchi 0:62ea25b8c31d 92 for (int e=1; e<=8; e++) { // empty registers, turn all LEDs off
takeuchi 0:62ea25b8c31d 93 maxAll(e,0);
takeuchi 0:62ea25b8c31d 94 }
takeuchi 0:62ea25b8c31d 95 maxAll(max7219_reg_intensity, 0x0f & 0x0f); // the first 0x0f is the value you can set
takeuchi 0:62ea25b8c31d 96 // range: 0x00 to 0x0f
takeuchi 0:62ea25b8c31d 97 }
takeuchi 0:62ea25b8c31d 98
takeuchi 0:62ea25b8c31d 99 void led_flash(){
takeuchi 0:62ea25b8c31d 100 int i;
takeuchi 0:62ea25b8c31d 101 for(i=0;i<3;i++){
takeuchi 0:62ea25b8c31d 102 led=ON;
takeuchi 0:62ea25b8c31d 103 wait(0.1);
takeuchi 0:62ea25b8c31d 104 led=OFF;
takeuchi 0:62ea25b8c31d 105 wait(0.1);
takeuchi 0:62ea25b8c31d 106 }
takeuchi 0:62ea25b8c31d 107 }
takeuchi 0:62ea25b8c31d 108
takeuchi 0:62ea25b8c31d 109 int main(void) {
takeuchi 0:62ea25b8c31d 110
takeuchi 0:62ea25b8c31d 111 const uint64_t moji_font[] = {// bold font , kagami moji font
takeuchi 0:62ea25b8c31d 112 0x3c66666e76663c00,//0~9
takeuchi 0:62ea25b8c31d 113 0x7e1818181c181800,
takeuchi 0:62ea25b8c31d 114 0x7e060c3060663c00,
takeuchi 0:62ea25b8c31d 115 0x3c66603860663c00,
takeuchi 0:62ea25b8c31d 116 0x30307e3234383000,
takeuchi 0:62ea25b8c31d 117 0x3c6660603e067e00,
takeuchi 0:62ea25b8c31d 118 0x3c66663e06663c00,
takeuchi 0:62ea25b8c31d 119 0x1818183030667e00,
takeuchi 0:62ea25b8c31d 120 0x3c66663c66663c00,
takeuchi 0:62ea25b8c31d 121 0x3c66607c66663c00,
takeuchi 0:62ea25b8c31d 122 };
takeuchi 0:62ea25b8c31d 123
takeuchi 0:62ea25b8c31d 124 int i,j,k;
takeuchi 0:62ea25b8c31d 125 uint8_t bitsum[1][8],bit1gyou,bitline[80];
takeuchi 0:62ea25b8c31d 126 uint64_t moji1;
takeuchi 0:62ea25b8c31d 127
takeuchi 0:62ea25b8c31d 128 setup();
takeuchi 0:62ea25b8c31d 129 led_flash();
takeuchi 0:62ea25b8c31d 130 wait(0.1);
takeuchi 0:62ea25b8c31d 131
takeuchi 0:62ea25b8c31d 132 while(1){
takeuchi 0:62ea25b8c31d 133
takeuchi 0:62ea25b8c31d 134 for(i=0;i<10;i++){
takeuchi 0:62ea25b8c31d 135 moji1=moji_font[i];// 0~9
takeuchi 0:62ea25b8c31d 136 for(j=0;j<8;j++){
takeuchi 0:62ea25b8c31d 137 bitsum[i][j]=0;
takeuchi 0:62ea25b8c31d 138 }
takeuchi 0:62ea25b8c31d 139 for(j=0;j<8;j++){
takeuchi 0:62ea25b8c31d 140 bit1gyou=moji1 & 0xff;
takeuchi 0:62ea25b8c31d 141 for(k=0;k<8;k++){// kagamimoji no font
takeuchi 0:62ea25b8c31d 142 //for(k=8;k>=1;k--){ // futuu no font
takeuchi 0:62ea25b8c31d 143 bitsum[i][k]=bitsum[i][k]+(bit1gyou & 0x01)*pow((double)2,(double)(j));
takeuchi 0:62ea25b8c31d 144 bit1gyou=bit1gyou >> 1;
takeuchi 0:62ea25b8c31d 145 }//i
takeuchi 0:62ea25b8c31d 146 moji1=moji1 >> 8;
takeuchi 0:62ea25b8c31d 147 }//j
takeuchi 0:62ea25b8c31d 148 }
takeuchi 0:62ea25b8c31d 149
takeuchi 0:62ea25b8c31d 150 k=0;
takeuchi 0:62ea25b8c31d 151 for(i=0;i<10;i++){// scroll data henkan
takeuchi 0:62ea25b8c31d 152 for(j=0;j<8;j++){
takeuchi 0:62ea25b8c31d 153 bitline[k]=bitsum[i][j];
takeuchi 0:62ea25b8c31d 154 k++;
takeuchi 0:62ea25b8c31d 155 }
takeuchi 0:62ea25b8c31d 156 }
takeuchi 0:62ea25b8c31d 157
takeuchi 0:62ea25b8c31d 158 for(i=0;i<80-8;i++){ //scroll hyouji
takeuchi 0:62ea25b8c31d 159 maxSingle(1,bitline[i+0]);
takeuchi 0:62ea25b8c31d 160 maxSingle(2,bitline[i+1]);
takeuchi 0:62ea25b8c31d 161 maxSingle(3,bitline[i+2]);
takeuchi 0:62ea25b8c31d 162 maxSingle(4,bitline[i+3]);
takeuchi 0:62ea25b8c31d 163 maxSingle(5,bitline[i+4]);
takeuchi 0:62ea25b8c31d 164 maxSingle(6,bitline[i+5]);
takeuchi 0:62ea25b8c31d 165 maxSingle(7,bitline[i+6]);
takeuchi 0:62ea25b8c31d 166 maxSingle(8,bitline[i+7]);
takeuchi 0:62ea25b8c31d 167 wait(0.1);
takeuchi 0:62ea25b8c31d 168 }
takeuchi 0:62ea25b8c31d 169
takeuchi 0:62ea25b8c31d 170 }//while
takeuchi 0:62ea25b8c31d 171 }//main
takeuchi 0:62ea25b8c31d 172
takeuchi 0:62ea25b8c31d 173