このライブラリは1桁から8桁までのSeven segment Numeric LEDを制御します。 LEDはanode commonとcathode common を使用することができます。 LEDの表示は1秒で表示をスムースに切り替えるモードと、直ぐに切り替えるモードの2つのモードを選択することができます。 This library to control the Seven segment Numeric LED 8 digit of 1. You can use the LED cathode common and anode common. Switch mode LED display and a second displayed a smooth, you can choose two modes to switch modes quickly.

Dependents:   kitchenTimer_Clock kitchenTimer LPC1114FN28_kitchenTimer_Clock SevenSegmentLedSample ... more

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers SevenSegLed.cpp Source File

SevenSegLed.cpp

00001 /**********************************************************
00002 
00003 *    SevenSegLed.cpp
00004 *    dynamic control of seven segment led
00005 *
00006 **********************************************************/
00007 #define _SEVENSEGLED_C
00008 
00009 #include "types.h"
00010 #include "mbed.h"
00011 #include "SevenSegLed.h"
00012 
00013 
00014 
00015 
00016 /** Create a seven segment led object connected to the specified DigtalOutput pin
00017  */
00018 #ifdef USECOM4
00019 SevenSegLed::SevenSegLed(uint8_t commonPole, uint8_t smooth, PinName seg_a, PinName seg_b, PinName seg_c, PinName seg_d, PinName seg_e, PinName seg_f, PinName seg_g, PinName seg_p,
00020                          PinName com_1, PinName com_2, PinName com_3, PinName com_4):
00021     _seg_a(seg_a), _seg_b(seg_b), _seg_c(seg_c), _seg_d(seg_d), _seg_e(seg_e), _seg_f(seg_f), _seg_g(seg_g), _seg_p(seg_p),
00022      _com_1(com_1), _com_2(com_2), _com_3(com_3), _com_4(com_4){
00023 #else // ~USECOM4
00024 SevenSegLed::SevenSegLed(uint8_t commonPole, uint8_t smooth, PinName seg_a, PinName seg_b, PinName seg_c, PinName seg_d, PinName seg_e, PinName seg_f, PinName seg_g, PinName seg_p,
00025                          PinName com_1, PinName com_2, PinName com_3, PinName com_4, PinName com_5, PinName com_6, PinName com_7, PinName com_8):
00026     _seg_a(seg_a), _seg_b(seg_b), _seg_c(seg_c), _seg_d(seg_d), _seg_e(seg_e), _seg_f(seg_f), _seg_g(seg_g), _seg_p(seg_p),
00027      _com_1(com_1), _com_2(com_2), _com_3(com_3), _com_4(com_4), _com_5(com_5), _com_6(com_6), _com_7(com_7), _com_8(com_8){
00028 #endif // USECOM4
00029     
00030 //@SS131223    timer.attach_us(this, &SevenSegLed::segmentGrayDataKosin, 10000);       // led smooth control 10ms timer inttruupt   //@SS131223
00031     timer.attach_us(this, &SevenSegLed::output, 1000);       // led output process 1ms timer inttruupt      //@SS131223
00032     // data table set of Brightness
00033     // DT_pwmGray[] = i ^ 2
00034     for(uint32_t i = 0; i < Z_grayMax + 1; i++){
00035         DT_pwmGray[i] = (uint8_t)(((i * i) * Z_pwmGrayMax ) / (Z_grayMax * Z_grayMax));
00036     }
00037     
00038     // check connect com_x
00039     D_comNull = Z_ketaSuu;
00040 #ifndef USECOM4    
00041     if(com_8 == NC){D_comNull--;}
00042     if(com_7 == NC){D_comNull--;}
00043     if(com_6 == NC){D_comNull--;}
00044     if(com_5 == NC){D_comNull--;}
00045 #endif //USECOM4
00046     if(com_4 == NC){D_comNull--;}
00047     if(com_3 == NC){D_comNull--;}
00048     if(com_2 == NC){D_comNull--;}
00049     if(com_1 == NC){D_comNull--;}
00050     
00051     // Those who will be reading the LED display
00052     D_smooth = smooth;
00053     
00054     // common and segment pin display data set
00055     if(commonPole == 0){
00056         // Anode common
00057         D_commonOn   = 1;
00058         D_commonOff  = 0;
00059         D_segmentOn  = 0;
00060         D_segmentOff = 1;
00061     }
00062     else{
00063         // Cathod common
00064         D_commonOn   = 0;
00065         D_commonOff  = 1;
00066         D_segmentOn  = 1;
00067         D_segmentOff = 0;
00068     }
00069     
00070 }
00071 
00072 /**************************************
00073 * display henka set
00074 * 0:smooth 1:hard
00075 * @SS131130
00076 **************************************/
00077 void SevenSegLed::smoothSet(uint8_t smooth){    
00078     D_smooth = smooth;
00079 }
00080     
00081 
00082 /**************************************
00083 * 7segment no gray data kosin
00084 * 100ms goto no syori
00085 **************************************/
00086 void SevenSegLed::segmentGrayDataKosin(void){
00087     uint8_t keta;
00088     uint8_t seg;
00089     
00090     uint8_t segMask;
00091     uint8_t segData;
00092 
00093 
00094     //*********************************************************
00095     // 7segment no shuturyoku pattern
00096     //*********************************************************
00097                               //          seg: a b c d  e f g p
00098                               //          bit: 7 6 5 4  3 2 1 0
00099                               //          ---------------------
00100     #define D_0 (0xfc)        // 0             1 1 1 1  1 1 0 0
00101     #define D_1 (0x60)        // 1             0 1 1 0  0 0 0 0
00102     #define D_2 (0xda)        // 2             1 1 0 1  1 0 1 0
00103     #define D_3 (0xf2)        // 3             1 1 1 1  0 0 1 0
00104     #define D_4 (0x66)        // 4             0 1 1 0  0 1 1 0
00105     #define D_5 (0xb6)        // 5             1 0 1 1  0 1 1 0
00106     #define D_6 (0xbe)        // 6             1 0 1 1  1 1 1 0
00107     #define D_7 (0xe4)        // 7             1 1 1 0  0 1 0 0
00108     #define D_8 (0xfe)        // 8             1 1 1 1  1 1 1 0
00109     #define D_9 (0xf6)        // 9             1 1 1 1  0 1 1 0
00110     #define D_A (0xee)        // A             1 1 1 0  1 1 1 0    
00111     #define D_b (0x3e)        // b             0 0 1 1  1 1 1 0
00112     #define D_C (0x9c)        // C             1 0 0 1  1 1 0 0
00113     #define D_d (0x7a)        // d             0 1 1 1  1 0 1 0        
00114     #define D_E (0x9e)        // E             1 0 0 1  1 1 1 0    
00115     #define D_F (0x8e)        // F             1 0 0 0  1 1 1 0
00116     #define D_NULL (0x00)     // NULL          0 0 0 0  0 0 0 0
00117                               // (No indication)
00118         
00119         
00120     const unsigned char DT_segData[17] = {D_0, D_1, D_2, D_3, D_4, D_5, D_6, D_7, D_8, D_9, D_A, D_b, D_C, D_d, D_E, D_F, D_NULL};
00121     uint8_t work;
00122 
00123     for(keta = 0; keta < Z_ketaSuu; keta++){
00124         // number data set
00125         work = D_7seg[keta];
00126         if(work > 0x10){work = 0x10;}       // error data then NULL
00127         segData = DT_segData[work];
00128         
00129         // dot data set
00130         if(D_dot[keta] != 0){segData |= 0x01;}
00131         
00132         // segment data set
00133         segMask = 0x80;
00134         
00135         for(seg = 0; seg < Z_segSuu; seg++){
00136             if(D_smooth == Z_smooth){
00137                 // LED display Smooth
00138                 if((segData & segMask) != 0){
00139                     // segment tento
00140                      if(D_7segGray[keta][seg] < Z_grayMax){D_7segGray[keta][seg]++;}
00141                 }
00142                 else{
00143                     // segment syoto
00144                     if(D_7segGray[keta][seg] > 0){D_7segGray[keta][seg]--;}
00145                 }
00146                 segMask = segMask >> 1;
00147             }
00148             else{
00149                 // LED display Hard
00150                 if((segData & segMask) != 0){
00151                 // segment tento
00152                     D_7segGray[keta][seg] = Z_pwmGrayMax;
00153                 }
00154                 else{
00155                     // segment syoto
00156                     D_7segGray[keta][seg] = 0;
00157                 }
00158                 segMask = segMask >> 1;
00159             }
00160        }
00161     }
00162 }
00163 
00164 
00165 /**************************************
00166 * main
00167 **************************************/
00168 void SevenSegLed::SevenSegLed_main(uint8_t* number, uint8_t* dot) {
00169     
00170     for(uint8_t i = 0; i < Z_ketaSuu; i++){
00171         D_7seg[i] = number[i];
00172         D_dot[i]  = dot[i];
00173     }
00174       
00175  
00176         // dynamic shuturyoku shori
00177  //segmentGrayDataKosin();
00178  //@SS131223       output();        //@SS131223
00179 }
00180 
00181 
00182 /**************************************
00183 * comAllClear
00184 *
00185 * common pin o subete OFF suru
00186 **************************************/
00187 void SevenSegLed::comAllClear(void){
00188     
00189     switch (D_comNull){
00190 #ifndef USECOM4
00191     case 8:                 // com_1 - com_8is all connect
00192         _com_8 = D_commonOff;
00193         //break;
00194     case 7:                 // com_8 Null
00195         _com_7 = D_commonOff;
00196         //break;
00197     case 6:                 // com_7 Null
00198         _com_6 = D_commonOff;
00199         //break;
00200     case 5:                 // com_6 Null
00201         _com_5 = D_commonOff;
00202         //break;
00203 #endif // USECOM4
00204     case 4:                 // com_5 Null
00205         _com_4 = D_commonOff;
00206         //break;                                
00207     case 3:                 // com_4 Null
00208         _com_3 = D_commonOff;
00209         // break;
00210     case 2:                 // com_3 Null
00211         _com_2 = D_commonOff;
00212         //break;
00213     case 1:                 // com_2 Null
00214         _com_1 = D_commonOff;
00215         //break;
00216     case 0:                 // com_1 Null
00217         // nothing
00218         break;
00219     default:
00220         // nothing
00221         break;
00222     }
00223 }
00224 
00225 /**************************************
00226 * segAllClear
00227 *
00228 * segment pin o subete OFF suru
00229 **************************************/
00230 void SevenSegLed::segAllClear(void){
00231     _seg_a = D_segmentOff;
00232     _seg_b = D_segmentOff;
00233     _seg_c = D_segmentOff;
00234     _seg_d = D_segmentOff;
00235     _seg_e = D_segmentOff;
00236     _seg_f = D_segmentOff;
00237     _seg_p = D_segmentOff;
00238 }
00239 
00240 /**************************************
00241 * segDataSet
00242 *
00243 * segment pin ni shuturyoku data o settei
00244 **************************************/
00245 void SevenSegLed::segDataSet(uint8_t keta){
00246 
00247     for(uint8_t i = 0; i < Z_pwmGrayMax + 1; i++){
00248         if(DT_pwmGray[D_7segGray[keta][0]] <= i){_seg_a = D_segmentOff;}else{_seg_a = D_segmentOn;}
00249         if(DT_pwmGray[D_7segGray[keta][1]] <= i){_seg_b = D_segmentOff;}else{_seg_b = D_segmentOn;}
00250         if(DT_pwmGray[D_7segGray[keta][2]] <= i){_seg_c = D_segmentOff;}else{_seg_c = D_segmentOn;}
00251         if(DT_pwmGray[D_7segGray[keta][3]] <= i){_seg_d = D_segmentOff;}else{_seg_d = D_segmentOn;}
00252         if(DT_pwmGray[D_7segGray[keta][4]] <= i){_seg_e = D_segmentOff;}else{_seg_e = D_segmentOn;}
00253         if(DT_pwmGray[D_7segGray[keta][5]] <= i){_seg_f = D_segmentOff;}else{_seg_f = D_segmentOn;}
00254         if(DT_pwmGray[D_7segGray[keta][6]] <= i){_seg_g = D_segmentOff;}else{_seg_g = D_segmentOn;}
00255         if(DT_pwmGray[D_7segGray[keta][7]] <= i){_seg_p = D_segmentOff;}else{_seg_p = D_segmentOn;}
00256     
00257     }
00258 }
00259 
00260 /**************************************
00261 * output
00262 *
00263 * This function must be treated with 1ms interval.
00264 * Each time you run this function, to switch the common.
00265 * 
00266 **************************************/
00267 void SevenSegLed::output(void){
00268     static uint8_t M_seg = 0;
00269     static uint8_t count = 0;   // This counter is used to perform a single smooth processing 10ms
00270 
00271     if(M_seg >= D_comNull){M_seg = 0;}
00272 
00273    //com, seg syokika
00274     comAllClear();
00275     segAllClear();
00276   
00277     // common output
00278     if(D_comNull != 0){
00279         // If the terminal output processing
00280         switch(M_seg){
00281         case 0:
00282             _com_1 = D_commonOn;
00283             break;
00284         case 1:
00285             _com_2 = D_commonOn;
00286             break;
00287         case 2:
00288             _com_3 = D_commonOn;
00289             break;
00290         case 3:
00291             _com_4 = D_commonOn;
00292             break;
00293 #ifndef USECOM4
00294         case 4:
00295             _com_5 = D_commonOn;
00296             break;
00297         case 5:
00298             _com_6 = D_commonOn;
00299             break;                    
00300         case 6:
00301             _com_7 = D_commonOn;
00302             break;                    
00303         case 7:
00304             _com_8 = D_commonOn;
00305             break;                                                
00306 #endif // USECOM4
00307         default:
00308             break;
00309         }
00310     }
00311     
00312     // segmant output
00313     if(M_seg < Z_ketaSuu){
00314         segDataSet(M_seg);
00315     }
00316 
00317 
00318 //    com, seg syokika
00319 //    comAllClear();
00320 //    segAllClear();
00321     M_seg++;
00322 
00323     // gray data process                                //@SS131223
00324     // It is performed in 10ms intervals smooth process //@SS131223
00325     count++;                                            //@SS131223
00326     if(count > 9){                                      //@SS131223
00327         count = 0;                                      //@SS131223
00328         segmentGrayDataKosin();                         //@SS131223
00329     }                                                   //@SS131223
00330 }
00331 
00332