LT-5016M1を74HC595で制御します。文字スクロールなどの参考にどうぞ。

Dependencies:   mbed

制作の過程はNotebookに書いています。

Committer:
p4ken
Date:
Thu Nov 17 12:00:40 2016 +0000
Revision:
29:eb77dcbcd1e3
Parent:
28:4b4682ad3b17
??????????????

Who changed what in which revision?

UserRevisionLine numberNew contents of line
p4ken 29:eb77dcbcd1e3 1
p4ken 0:679fb5e8a0b4 2 #include "mbed.h"
p4ken 0:679fb5e8a0b4 3
p4ken 29:eb77dcbcd1e3 4 //DigitalOut led2(LED2);
p4ken 13:83c703e6e843 5 DigitalOut RCK(PB_12);// 74595
p4ken 13:83c703e6e843 6 DigitalOut G(PB_1); // 74595
p4ken 13:83c703e6e843 7 DigitalOut SER(PC_6); // 74164
p4ken 13:83c703e6e843 8 DigitalOut CLK(PC_5); // 74164
p4ken 21:bbb751c5d846 9 DigitalIn BUTTON(USER_BUTTON); // 点灯・消灯ボタン
p4ken 29:eb77dcbcd1e3 10 //Serial pc(USBTX, USBRX); // USBシリアル通信
p4ken 29:eb77dcbcd1e3 11 //Timer timer; // 経過時間のカウンター
p4ken 16:cd36324730ad 12
p4ken 16:cd36324730ad 13 // 点灯パターン 手前赤、手前緑...
p4ken 29:eb77dcbcd1e3 14 unsigned short pattern[2][16][32*11/16] =
p4ken 29:eb77dcbcd1e3 15 {
p4ken 29:eb77dcbcd1e3 16 // 849空きあり
p4ken 29:eb77dcbcd1e3 17 {{0,0,0,0,0,0,0,0,0,0,0,0,0,32896,0,0,0,0,0,0,0,0},
p4ken 29:eb77dcbcd1e3 18 {0,0,0,0,0,0,61440,768,0,3072,63488,256,0,32896,0,24672,0,8224,0,2056,1028,0},
p4ken 29:eb77dcbcd1e3 19 {0,0,0,0,0,0,6144,1536,0,3584,3072,768,0,65535,32639,16448,3084,16448,0,4112,2056,0},
p4ken 29:eb77dcbcd1e3 20 {0,0,0,0,0,0,3072,3072,0,3840,1536,1536,0,8481,16962,50372,771,16448,1542,4112,2056,0},
p4ken 29:eb77dcbcd1e3 21 {0,0,0,0,0,0,3072,35840,33024,3328,1536,1536,0,8481,8738,30840,0,58082,257,4112,2056,0},
p4ken 29:eb77dcbcd1e3 22 {0,0,0,0,0,0,3072,35840,33024,3072,1536,1536,0,4112,8738,32896,6168,15420,0,2056,2056,0},
p4ken 29:eb77dcbcd1e3 23 {0,0,0,0,0,0,6144,1536,49152,3072,1536,1536,0,3084,15420,514,1799,8224,0,2056,2056,0},
p4ken 29:eb77dcbcd1e3 24 {0,0,0,0,0,0,61440,768,16384,3072,1536,1536,0,771,0,64764,257,41120,1799,10280,2056,0},
p4ken 29:eb77dcbcd1e3 25 {0,0,0,0,0,0,6144,1536,24576,3072,1536,1536,0,0,4112,0,514,28784,2570,10280,2056,0},
p4ken 29:eb77dcbcd1e3 26 {0,0,0,0,0,0,3072,3072,8192,3072,3072,1792,0,64764,7967,0,1028,10280,4626,4112,2056,0},
p4ken 29:eb77dcbcd1e3 27 {0,0,0,0,0,0,3072,35840,12544,3072,63488,1536,0,32896,0,57568,2827,9252,8481,4112,2056,0},
p4ken 29:eb77dcbcd1e3 28 {0,0,0,0,0,0,3072,35840,61696,16128,0,1536,0,32896,0,6168,3084,17476,8481,0,1028,0},
p4ken 29:eb77dcbcd1e3 29 {0,0,0,0,0,0,3072,3072,0,3072,1536,1536,0,32896,0,1028,0,49858,8224,0,1028,0},
p4ken 29:eb77dcbcd1e3 30 {0,0,0,0,0,0,6144,1536,0,3072,3072,768,0,32896,16448,1028,0,25186,8224,0,514,0},
p4ken 29:eb77dcbcd1e3 31 {0,0,0,0,0,0,61440,768,0,16128,63488,256,0,65535,32639,6168,0,7196,6168,32896,257,0},
p4ken 29:eb77dcbcd1e3 32 {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,57568,3855,0,1799,24672,0,0}},
p4ken 29:eb77dcbcd1e3 33 // 849満員
p4ken 29:eb77dcbcd1e3 34 {{0,0,0,0,0,0,0,0,0,0,0,0,0,0,130,8,0,0,252,31,0,0},
p4ken 29:eb77dcbcd1e3 35 {0,0,0,0,0,0,61440,768,0,3072,63488,256,0,0,132,40,0,0,4,16,0,0},
p4ken 29:eb77dcbcd1e3 36 {0,0,0,0,0,0,6144,1536,0,3584,3072,768,0,0,232,63,0,0,4,16,0,0},
p4ken 29:eb77dcbcd1e3 37 {0,0,0,0,0,0,3072,3072,0,3840,1536,1536,0,0,128,8,0,0,252,31,0,0},
p4ken 29:eb77dcbcd1e3 38 {0,0,0,0,0,0,3072,35840,33024,3328,1536,1536,0,0,129,72,0,0,0,0,0,0},
p4ken 29:eb77dcbcd1e3 39 {0,0,0,0,0,0,3072,35840,33024,3072,1536,1536,0,0,250,127,0,0,254,63,0,0},
p4ken 29:eb77dcbcd1e3 40 {0,0,0,0,0,0,6144,1536,49152,3072,1536,1536,0,0,8,2,0,0,2,32,0,0},
p4ken 29:eb77dcbcd1e3 41 {0,0,0,0,0,0,61440,768,16384,3072,1536,1536,0,0,4,34,0,0,254,63,0,0},
p4ken 29:eb77dcbcd1e3 42 {0,0,0,0,0,0,6144,1536,24576,3072,1536,1536,0,0,228,127,0,0,2,32,0,0},
p4ken 29:eb77dcbcd1e3 43 {0,0,0,0,0,0,3072,3072,8192,3072,3072,1792,0,0,34,34,0,0,254,63,0,0},
p4ken 29:eb77dcbcd1e3 44 {0,0,0,0,0,0,3072,35840,12544,3072,63488,1536,0,0,163,42,0,0,2,32,0,0},
p4ken 29:eb77dcbcd1e3 45 {0,0,0,0,0,0,3072,35840,61696,16128,0,1536,0,0,162,42,0,0,2,32,0,0},
p4ken 29:eb77dcbcd1e3 46 {0,0,0,0,0,0,3072,3072,0,3072,1536,1536,0,0,162,42,0,0,254,63,0,0},
p4ken 29:eb77dcbcd1e3 47 {0,0,0,0,0,0,6144,1536,0,3072,3072,768,0,0,162,47,0,0,16,4,0,0},
p4ken 29:eb77dcbcd1e3 48 {0,0,0,0,0,0,61440,768,0,16128,63488,256,0,0,34,32,0,0,12,56,0,0},
p4ken 29:eb77dcbcd1e3 49 {0,0,0,0,0,0,0,0,0,0,0,0,0,0,34,56,0,0,3,64,0,0}}
p4ken 29:eb77dcbcd1e3 50 };
p4ken 29:eb77dcbcd1e3 51
p4ken 29:eb77dcbcd1e3 52
p4ken 29:eb77dcbcd1e3 53
p4ken 29:eb77dcbcd1e3 54
p4ken 1:9f6c6dcdd8d7 55 char scan = 16; // 点灯中の行
p4ken 6:f72e87d03ab0 56 int round = 0; // スキャンを何周したか
p4ken 3:68075c4a9ab4 57 int scroll = 0; // 左スクロールした量
p4ken 0:679fb5e8a0b4 58
p4ken 29:eb77dcbcd1e3 59 //void receive() { // シリアル受信割り込み
p4ken 29:eb77dcbcd1e3 60 // if(pc.getc() == 0b00000001) pc.printf("received!\r\n");
p4ken 2:75c7836a6ff4 61 // pc.putc(pc.getc() + 1); // echo
p4ken 29:eb77dcbcd1e3 62 //}
p4ken 2:75c7836a6ff4 63
p4ken 0:679fb5e8a0b4 64 int main() {
p4ken 21:bbb751c5d846 65 SPI spi(PB_15, PB_14, PB_13); // SPIピンを指定
p4ken 29:eb77dcbcd1e3 66 spi.format(16, 0); // 74595へ?ビットずつ送る
p4ken 29:eb77dcbcd1e3 67 spi.frequency(1*1000*1000); // 74595へのクロック周波数 最高96 初期1
p4ken 29:eb77dcbcd1e3 68 // pc.attach(receive, Serial::RxIrq); // シリアル受信割り込み
p4ken 29:eb77dcbcd1e3 69 // pc.baud(9600); // シリアル通信のクロックレート デフォルト9600
p4ken 29:eb77dcbcd1e3 70 // timer.start(); // 経過時間のカウントを開始
p4ken 0:679fb5e8a0b4 71
p4ken 0:679fb5e8a0b4 72 while(1) {
p4ken 29:eb77dcbcd1e3 73 // timer.reset(); // 経過時間0秒
p4ken 9:4efad95ffa53 74
p4ken 9:4efad95ffa53 75 // 行選択
p4ken 9:4efad95ffa53 76 scan++; // 一行進む
p4ken 29:eb77dcbcd1e3 77 if(scan == 17){ // 16行目の次
p4ken 29:eb77dcbcd1e3 78 scan = 1; // 1行目に戻る
p4ken 1:9f6c6dcdd8d7 79 SER = 0; // 点灯
p4ken 9:4efad95ffa53 80 round++; // スキャンが1周した
p4ken 9:4efad95ffa53 81 } else if(scan == 2) { // 2行目
p4ken 1:9f6c6dcdd8d7 82 SER = 1; // 消灯
p4ken 0:679fb5e8a0b4 83 }
p4ken 9:4efad95ffa53 84
p4ken 9:4efad95ffa53 85 // 表示パターン送り込み
p4ken 29:eb77dcbcd1e3 86 // for(int i=0; i<2*11; i++){
p4ken 29:eb77dcbcd1e3 87 // spi.write(0b0000000000000000);
p4ken 29:eb77dcbcd1e3 88 // }
p4ken 29:eb77dcbcd1e3 89 // RCK = 0;
p4ken 29:eb77dcbcd1e3 90 // RCK = 1;
p4ken 29:eb77dcbcd1e3 91
p4ken 29:eb77dcbcd1e3 92 for(int i=0; i<32*11/16; i++){ // iは最大で32*11文字/bit数
p4ken 29:eb77dcbcd1e3 93 if(round < 500) {
p4ken 29:eb77dcbcd1e3 94 spi.write(pattern[0][scan-1][32*11/16-1-i%(32*11/16)]);
p4ken 26:a370873304d9 95 // } else if(round < 1000) {
p4ken 29:eb77dcbcd1e3 96 // spi.write(pattern[1][scan-1][32*11/16-1-i%(32*11/16)]);
p4ken 29:eb77dcbcd1e3 97 } else {
p4ken 29:eb77dcbcd1e3 98 spi.write(pattern[1][scan-1][32*11/16-1-i%(32*11/16)]);
p4ken 29:eb77dcbcd1e3 99 }
p4ken 6:f72e87d03ab0 100 }
p4ken 9:4efad95ffa53 101
p4ken 9:4efad95ffa53 102 // スクロール
p4ken 24:5c85cd80f5fa 103 if(round > 1500) { // スクロール速度
p4ken 6:f72e87d03ab0 104 scroll++; // 1ドットスクロールする
p4ken 6:f72e87d03ab0 105 round = 0; // スキャン周回カウントリセット
p4ken 6:f72e87d03ab0 106 }
p4ken 7:d9681a6487d4 107 if(scroll > 32) { // スクロール幅
p4ken 6:f72e87d03ab0 108 scroll = 0; // スクロール数リセット
p4ken 5:95590a89eb9f 109 }
p4ken 1:9f6c6dcdd8d7 110
p4ken 29:eb77dcbcd1e3 111 G = 1; // 消灯
p4ken 0:679fb5e8a0b4 112 RCK = 0;
p4ken 1:9f6c6dcdd8d7 113 CLK = 0;
p4ken 0:679fb5e8a0b4 114 RCK = 1;
p4ken 1:9f6c6dcdd8d7 115 CLK = 1;
p4ken 8:496a1ba31a68 116
p4ken 8:496a1ba31a68 117 // ここまでの処理時間が長いほど明るくなる
p4ken 27:c49fd2b1279a 118 // while(timer.read_us()<0) { // 数字のぶんだけ暗くする
p4ken 27:c49fd2b1279a 119 // wait_us(10);
p4ken 27:c49fd2b1279a 120 // }
p4ken 29:eb77dcbcd1e3 121
p4ken 24:5c85cd80f5fa 122 G = !BUTTON; // ボタン押すと!点灯
p4ken 8:496a1ba31a68 123
p4ken 8:496a1ba31a68 124 // ダイナミック点灯のパルス幅を決める
p4ken 27:c49fd2b1279a 125 // while(timer.read_us()<100) { // 100*2500でゆっくり
p4ken 27:c49fd2b1279a 126 // wait_us(10);
p4ken 27:c49fd2b1279a 127 // }
p4ken 15:5cec652070ca 128 // pc.printf("%d\r\n", timer.read_us());
p4ken 15:5cec652070ca 129 // pc.printf("%d\r\n", round/100);
p4ken 0:679fb5e8a0b4 130 }
p4ken 0:679fb5e8a0b4 131 }