dot Matrix Led Clock with TLC5940

Dependencies:   Kc_TLC5940 mbed

Committer:
kohacraft
Date:
Tue Jul 28 00:21:58 2015 +0000
Revision:
0:c61e5f0d54c1
Child:
1:7afb65e75dcd
disp hour and add adj sw;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
kohacraft 0:c61e5f0d54c1 1 #include "mbed.h"
kohacraft 0:c61e5f0d54c1 2 #include "TLC5940.h"
kohacraft 0:c61e5f0d54c1 3 SPI driver( dp2 , dp1 , dp6 ); //mosi , miso , sck
kohacraft 0:c61e5f0d54c1 4 DigitalOut vprg = dp4;
kohacraft 0:c61e5f0d54c1 5 DigitalOut xlat = dp9;
kohacraft 0:c61e5f0d54c1 6 DigitalOut blank = dp10;
kohacraft 0:c61e5f0d54c1 7 PwmOut gsclk = dp1;
kohacraft 0:c61e5f0d54c1 8 int num_ics = 1; //何個5940がつながっているか
kohacraft 0:c61e5f0d54c1 9
kohacraft 0:c61e5f0d54c1 10 #include "font.h"
kohacraft 0:c61e5f0d54c1 11
kohacraft 0:c61e5f0d54c1 12 DigitalOut col1 = dp11;
kohacraft 0:c61e5f0d54c1 13 DigitalOut col2 = dp13;
kohacraft 0:c61e5f0d54c1 14 DigitalOut col3 = dp14;
kohacraft 0:c61e5f0d54c1 15 DigitalOut col4 = dp15;
kohacraft 0:c61e5f0d54c1 16 DigitalOut col5 = dp16;
kohacraft 0:c61e5f0d54c1 17 DigitalOut col6 = dp17;
kohacraft 0:c61e5f0d54c1 18 DigitalOut col7 = dp18;
kohacraft 0:c61e5f0d54c1 19 DigitalOut col8 = dp26;
kohacraft 0:c61e5f0d54c1 20
kohacraft 0:c61e5f0d54c1 21 DigitalIn fastSw = dp28;
kohacraft 0:c61e5f0d54c1 22 DigitalIn slowSw = dp25;
kohacraft 0:c61e5f0d54c1 23
kohacraft 0:c61e5f0d54c1 24 #define dispTime 10
kohacraft 0:c61e5f0d54c1 25 #define fastCount 1024
kohacraft 0:c61e5f0d54c1 26 #define slowCount 50
kohacraft 0:c61e5f0d54c1 27
kohacraft 0:c61e5f0d54c1 28 //時間の数字をドッドの数字に変換
kohacraft 0:c61e5f0d54c1 29 unsigned char hourDecfont( int num , int colm )
kohacraft 0:c61e5f0d54c1 30 {
kohacraft 0:c61e5f0d54c1 31 unsigned char fontTemp = 0;
kohacraft 0:c61e5f0d54c1 32 unsigned char fontTemp2 = 0;
kohacraft 0:c61e5f0d54c1 33 int numTemp = 0 ;
kohacraft 0:c61e5f0d54c1 34 numTemp = num / 10;
kohacraft 0:c61e5f0d54c1 35 if( numTemp >0 )
kohacraft 0:c61e5f0d54c1 36 {
kohacraft 0:c61e5f0d54c1 37 fontTemp = font[ numTemp ][ colm ];
kohacraft 0:c61e5f0d54c1 38 fontTemp = fontTemp << 5;
kohacraft 0:c61e5f0d54c1 39 }
kohacraft 0:c61e5f0d54c1 40 numTemp = num - numTemp*10;
kohacraft 0:c61e5f0d54c1 41 fontTemp2 = font[ numTemp ][ colm ];
kohacraft 0:c61e5f0d54c1 42 fontTemp2 = fontTemp2 << 2;
kohacraft 0:c61e5f0d54c1 43 fontTemp = fontTemp | fontTemp2 | font[ 10 ][ colm ];
kohacraft 0:c61e5f0d54c1 44
kohacraft 0:c61e5f0d54c1 45 return fontTemp;
kohacraft 0:c61e5f0d54c1 46 }
kohacraft 0:c61e5f0d54c1 47
kohacraft 0:c61e5f0d54c1 48 //数字をドッドの数字に変換
kohacraft 0:c61e5f0d54c1 49 unsigned char decfont( int num , int colm )
kohacraft 0:c61e5f0d54c1 50 {
kohacraft 0:c61e5f0d54c1 51 unsigned char fontTemp = 0;
kohacraft 0:c61e5f0d54c1 52 int numTemp = 0 ;
kohacraft 0:c61e5f0d54c1 53 numTemp = num / 10;
kohacraft 0:c61e5f0d54c1 54 fontTemp = font[ numTemp ][ colm ];
kohacraft 0:c61e5f0d54c1 55 fontTemp = fontTemp << 4;
kohacraft 0:c61e5f0d54c1 56 numTemp = num - numTemp*10;
kohacraft 0:c61e5f0d54c1 57 fontTemp = fontTemp | font[ numTemp ][ colm ];
kohacraft 0:c61e5f0d54c1 58
kohacraft 0:c61e5f0d54c1 59 return fontTemp;
kohacraft 0:c61e5f0d54c1 60 }
kohacraft 0:c61e5f0d54c1 61
kohacraft 0:c61e5f0d54c1 62
kohacraft 0:c61e5f0d54c1 63 void fontOut( unsigned char font )
kohacraft 0:c61e5f0d54c1 64 {
kohacraft 0:c61e5f0d54c1 65 unsigned char mask = 0x01;
kohacraft 0:c61e5f0d54c1 66 unsigned char temp = font;
kohacraft 0:c61e5f0d54c1 67 col1 = ( temp & mask );
kohacraft 0:c61e5f0d54c1 68 mask = mask << 1;
kohacraft 0:c61e5f0d54c1 69 col2 = ( temp & mask );
kohacraft 0:c61e5f0d54c1 70 mask = mask << 1;
kohacraft 0:c61e5f0d54c1 71 col3 = ( temp & mask );
kohacraft 0:c61e5f0d54c1 72 mask = mask << 1;
kohacraft 0:c61e5f0d54c1 73 col4 = ( temp & mask );
kohacraft 0:c61e5f0d54c1 74 mask = mask << 1;
kohacraft 0:c61e5f0d54c1 75 col5 = ( temp & mask );
kohacraft 0:c61e5f0d54c1 76 mask = mask << 1;
kohacraft 0:c61e5f0d54c1 77 col6 = ( temp & mask );
kohacraft 0:c61e5f0d54c1 78 mask = mask << 1;
kohacraft 0:c61e5f0d54c1 79 col7 = ( temp & mask );
kohacraft 0:c61e5f0d54c1 80 mask = mask << 1;
kohacraft 0:c61e5f0d54c1 81 col8 = ( temp & mask );
kohacraft 0:c61e5f0d54c1 82 }
kohacraft 0:c61e5f0d54c1 83 int main() {
kohacraft 0:c61e5f0d54c1 84
kohacraft 0:c61e5f0d54c1 85 initFont();
kohacraft 0:c61e5f0d54c1 86
kohacraft 0:c61e5f0d54c1 87 setup (driver, vprg, xlat, blank, gsclk, num_ics );
kohacraft 0:c61e5f0d54c1 88
kohacraft 0:c61e5f0d54c1 89 unsigned short LEDS[16];
kohacraft 0:c61e5f0d54c1 90 while(1)
kohacraft 0:c61e5f0d54c1 91 {
kohacraft 0:c61e5f0d54c1 92 for( int l =1 ; l<13 ; l++ )
kohacraft 0:c61e5f0d54c1 93 {
kohacraft 0:c61e5f0d54c1 94 for( int k=0 ; k<60 ; k++)
kohacraft 0:c61e5f0d54c1 95 {
kohacraft 0:c61e5f0d54c1 96 for( int j = 0 ; j < 1024; j+=2 )
kohacraft 0:c61e5f0d54c1 97 {
kohacraft 0:c61e5f0d54c1 98 if( fastSw == 1 )
kohacraft 0:c61e5f0d54c1 99 j+=fastCount;
kohacraft 0:c61e5f0d54c1 100 if( slowSw == 1 )
kohacraft 0:c61e5f0d54c1 101 j+=slowCount;
kohacraft 0:c61e5f0d54c1 102 for( int i=0 ; i<16 ; i++ )
kohacraft 0:c61e5f0d54c1 103 {
kohacraft 0:c61e5f0d54c1 104 //PWMをクリア
kohacraft 0:c61e5f0d54c1 105 for( int h=0; h<16 ; h++ )
kohacraft 0:c61e5f0d54c1 106 LEDS[h] = 0;
kohacraft 0:c61e5f0d54c1 107 LEDS[i] = (unsigned short)j; //必要なピンのみ指定した明るさでON
kohacraft 0:c61e5f0d54c1 108 offDisp(blank, gsclk); //PWM強制OFF
kohacraft 0:c61e5f0d54c1 109 if( i<8 )
kohacraft 0:c61e5f0d54c1 110 fontOut( decfont( k , i ) );
kohacraft 0:c61e5f0d54c1 111 else
kohacraft 0:c61e5f0d54c1 112 fontOut( hourDecfont( l , i-8 ) );
kohacraft 0:c61e5f0d54c1 113 update_led (driver, xlat, blank, gsclk , LEDS);
kohacraft 0:c61e5f0d54c1 114 wait_us(dispTime);
kohacraft 0:c61e5f0d54c1 115 }
kohacraft 0:c61e5f0d54c1 116 }
kohacraft 0:c61e5f0d54c1 117 for( int j = 1024 ; j > 0; j-=2 )
kohacraft 0:c61e5f0d54c1 118 {
kohacraft 0:c61e5f0d54c1 119 if( fastSw == 1 )
kohacraft 0:c61e5f0d54c1 120 j-= fastCount;
kohacraft 0:c61e5f0d54c1 121 if( slowSw == 1 )
kohacraft 0:c61e5f0d54c1 122 j-=slowCount;
kohacraft 0:c61e5f0d54c1 123 for( int i=0 ; i<16 ; i++ )
kohacraft 0:c61e5f0d54c1 124 {
kohacraft 0:c61e5f0d54c1 125 for( int h=0; h<16 ; h++ )
kohacraft 0:c61e5f0d54c1 126 LEDS[h] = 0;
kohacraft 0:c61e5f0d54c1 127 LEDS[i] = (unsigned short)j;
kohacraft 0:c61e5f0d54c1 128 offDisp(blank, gsclk);
kohacraft 0:c61e5f0d54c1 129 if( i<8 )
kohacraft 0:c61e5f0d54c1 130 fontOut( decfont( k , i ) );
kohacraft 0:c61e5f0d54c1 131 else
kohacraft 0:c61e5f0d54c1 132 fontOut( hourDecfont( l , i-8 ) );
kohacraft 0:c61e5f0d54c1 133 update_led (driver, xlat, blank, gsclk , LEDS);
kohacraft 0:c61e5f0d54c1 134 wait_us(dispTime);
kohacraft 0:c61e5f0d54c1 135 }
kohacraft 0:c61e5f0d54c1 136 }
kohacraft 0:c61e5f0d54c1 137 }
kohacraft 0:c61e5f0d54c1 138
kohacraft 0:c61e5f0d54c1 139
kohacraft 0:c61e5f0d54c1 140 }
kohacraft 0:c61e5f0d54c1 141 }
kohacraft 0:c61e5f0d54c1 142 }