このライブラリは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.h Source File

SevenSegLed.h

00001 /* mbed Seven segment LED (Maximum four digit) Library
00002  * Copyright (c) 2011 suupen
00003  *
00004  * Permission is hereby granted, free of charge, to any person obtaining a copy
00005  * of this software and associated documentation files (the "Software"), to deal
00006  * in the Software without restriction, including without limitation the rights
00007  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00008  * copies of the Software, and to permit persons to whom the Software is
00009  * furnished to do so, subject to the following conditions:
00010  *
00011  * The above copyright notice and this permission notice shall be included in
00012  * all copies or substantial portions of the Software.
00013  *
00014  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00015  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00016  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00017  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00018  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00019  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00020  * THE SOFTWARE.
00021  */
00022 
00023 
00024 //***********************************************************************/
00025 //*                                                                     */
00026 //*    ledDynamic.h                                                     */
00027 //* ---------   V1.0 : 4digit(4com) display                             */
00028 //* ---------   V2.0 : 8digit(8com) display                             */
00029 //* @SS131130   V2.1 : HYOJI MODE NO TUIKA (smooth or hard)             */
00030 //* @SS131223   V2.2 : Run the library side dynamic output processing   */
00031 //*                                                                     */
00032 //***********************************************************************/
00033 #ifndef _SEVENSEGLED_H
00034 #define _SEVENSEGLED_H
00035 
00036 /** Seven segment Numeric LED control class
00037  *
00038  * Example:
00039  * @code
00040  * //-----------------------------------------------------------------------------
00041  * //sevenSegmentLed Library Example
00042  * //
00043  * //This program by one every second counts, do a 8-digit seven-segment LED display.
00044  * //
00045  * // <compile option>
00046  * //  SevenSegLed.h  "USECOM4" : YUKO JI SAIDAI 4COM. MUKO JI SAIDAI 8COM.
00047  * //
00048  * //seven segment numeric LED Display : LTC4627P
00049  * //      http://www.excesssolutions.com/mas_assets/acrobat/ES5721.pdf
00050  * //
00051  * // LTC4627T                              Resister        mbed
00052  * // Pin No     Function                   [ohm]           Function
00053  * // ---------------------------------------------------------------------------
00054  * //  1         Common Anode Digit 1        -              P29 
00055  * //  2         Common Anode Digit 2        -              P13
00056  * //  3         Cathode D                   200            P22
00057  * //  4         Common Anode L1,L2,L3       -              -
00058  * //  5         Cathode E                   200            P24
00059  * //  6         Common Anode Digit 3        -              P25  
00060  * //  7         Cathode D.p.                200            P30
00061  * //  8         Common Anode Digit 4        -              P27 
00062  * //  9         No Connection               -              -
00063  * // 10         No Pin                      -              -
00064  * // 11         Cathode F                   200            P16 
00065  * // 12         No Pin                      -              -
00066  * // 13         Cathode C,L3                200            P17 
00067  * // 14         Cathode A,L1                200            P14
00068  * // 15         Cathode G                   200            P19
00069  * // 16         Cathode B,L2                200            P20
00070  * //---------------------------------------------------------------------------
00071  * #include "mbed.h" 
00072  * #include "SevenSegLed.h"
00073  *
00074  * //                     common type (0:anode common 1:cathode common)
00075  * //                     | 
00076  * //                     |  display mode (0:smooth 1:hard)
00077  * //                     |  |
00078  * //                     |  |    segA segB segC segD segE segF segG segP com1 com2 com3 com4 (com5,com6,com7,com8 = NC)                          
00079  * //                     |  |    |    |    |    |    |    |    |    |    |    |    |    | 
00080  * SevenSegLed segmentled(0, 0, p14, p20, p17, p22, p24, p16, p19, p30, p29, p13, p25, p27);
00081  *
00082  *
00083  * //                   1  2  3  4digit 
00084  * //                   |  |  |  |
00085  * uint8_t D_7seg[4] = {0, 0, 0, 0}; // seven segment digit number    (0x00:"0", 0x01:"1", ... , 0x09:"9", 0x0A:"A", ... , 0x0F:"F", other:" ")
00086  * uint8_t D_dot[4]  = {0, 0, 0, 0}; // seven segment digit dotpoint. (0:off 1:on)
00087  * 
00088  * 
00089  * Timer timer;    // 1second timer
00090  *     
00091  * int main() {
00092  *     uint16_t counter = 0;
00093  *     
00094  *     timer.start();
00095  * 
00096  *     while(1) {
00097  *         // After one second to start the process
00098  *         if(timer.read_ms() >= 1000){
00099  *             timer.reset();
00100  *             counter++;
00101  * 
00102  *             // Display digit data updates
00103  *             D_7seg[0] = (uint8_t)((counter & 0xF000) >> 12);
00104  *             D_7seg[1] = (uint8_t)((counter & 0x0F00) >> 8);
00105  *             D_7seg[2] = (uint8_t)((counter & 0x00F0) >> 4);
00106  *             D_7seg[3] = (uint8_t)(counter & 0x000F);
00107  *             
00108  *             // Display dot point data updates
00109  *             D_dot[0] = 0;
00110  *             D_dot[1] = 0;
00111  *             D_dot[2] = 0;
00112  *             D_dot[3] = 0;            
00113  *             
00114  *             // dot point data set
00115  *             D_dot[counter & 0x0003] = 1;
00116  *         }
00117  * 
00118  *         // seven segment display to output data
00119  *         // This function, please repeat the process in less than 1ms.
00120  *         segmentled.SevenSegLed_main(D_7seg, D_dot);      
00121  *  
00122  *     }
00123  * }
00124  * @endcode
00125  */
00126 
00127 //#define USECOM4     // YUKO JI COM SUU 4KETA MADE. NUKO JI COM SUU 8KETA MADE.
00128                     // LPC1114FN28 DEHA PIN SETTI DE "NC" ATUKAI DEKINAI NODE kitchen timer YO NI KONO commpile option WO TUKERU
00129 
00130 #include "types.h"
00131 
00132 
00133 class SevenSegLed {
00134 public:
00135 
00136     //@SS131130 
00137     /** Display henko set
00138     * @param smooth 0:smooth  1:hard
00139     */
00140     void smoothSet(uint8_t smooth);
00141 
00142 
00143     /** Create a seven segment led array object connected to the specified DigitalOut pin
00144     * @param commonPole The polarity of the seven segment led common  0:Anode common, 1:Cathode common
00145     * @param smooth Reading the LED display method.  0:Smooth changing the LED display in one second  1:Quickly changing the LED display
00146     * @param seg_a - seg_p DigitalOut pin to connect to.    To provide members with an array of uint8_t digit minutes.
00147     * @param com_1 - com_8 DigitalOut pin to connect to.    To provide members with an array of uint8_t digit minutes. 8 digits maximum   
00148     */
00149 #ifdef USECOM4
00150     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,
00151                 PinName com_1 = NC, PinName com_2 = NC, PinName com_3 = NC, PinName com_4 = NC);
00152 #else // ~USECOM4
00153     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,
00154                 PinName com_1 = NC, PinName com_2 = NC, PinName com_3 = NC, PinName com_4 = NC,
00155                 PinName com_5 = NC, PinName com_6 = NC, PinName com_7 = NC, PinName com_8 = NC);
00156 #endif // USECOM4    
00157     /** Data set to the seven segment LED display
00158     * @param number Array variable address pointer of Numerical data 0 - 9,A - F : The figures show, 0x10:off
00159     * @param dot    Array variable address pointer of dot data  0:off 1:on
00160     */
00161     void SevenSegLed_main(uint8_t* number, uint8_t* dot);
00162 
00163 private:
00164 void segmentGrayDataKosin(void);
00165 void comAllClear(void);
00166 void segAllClear(void);
00167 void segDataSet(uint8_t keta);
00168 void output(void);
00169 
00170 //  pin set_seg, _com;
00171     DigitalOut _seg_a, _seg_b, _seg_c, _seg_d, _seg_e, _seg_f, _seg_g, _seg_p;
00172 #ifdef USECOM4
00173     DigitalOut _com_1, _com_2, _com_3, _com_4;
00174 #else //~USECOM4
00175     DigitalOut _com_1, _com_2, _com_3, _com_4, _com_5, _com_6, _com_7, _com_8;
00176 #endif // USECOM4
00177     
00178    Ticker timer;
00179 
00180 #ifdef USECOM4
00181 #define Z_ketaSuu (4)   // 7segment no keta suu
00182 #else //USECOM4
00183 #define Z_ketaSuu (8)   // 7segment no keta suu
00184 #endif // USECOM4
00185 #define Z_segSuu  (8)   // 7segmetn no segment suu (a,b,...,g,Dp)
00186 #define Z_grayMax (100)  // grayData max 100 kaicho
00187 #define Z_pwmGrayMax (100) // pwm max (led heno pwm syuturyoku no max)
00188 
00189  
00190 uint8_t D_7seg[Z_ketaSuu];    // digit number display request 0:"0", 1:"1", ... , 9:"9", A:"A", B:"b", C:"C", D:"d", E:"E", F:"F"
00191                             // [0]:digit1, [1]:digit2, ... ,[7]:digit8
00192 uint8_t D_dot[Z_ketaSuu];   // digit dot display request   0:off  1(not 0):on
00193                             // [0]:digit1, [1]:digit2, ... ,[7]:digit8
00194                             
00195 
00196 uint8_t D_7segGray[Z_ketaSuu][Z_segSuu];    // hyoji segment no gray data 0:syoto 1:min - 10:max
00197 
00198 uint8_t DT_pwmGray[Z_grayMax + 1];  // gray data kara pwm data heno henkan table
00199 
00200 uint8_t D_comNull;  // comX Null check No set (0:all com is NC 1:com1 connect, 2:com2 connect,...,8:com8 connect(all com connect)
00201 
00202 uint8_t D_smooth; // Those who will be reading the LED display  0:smooth 1:hard
00203 #define Z_smooth (0)
00204 #define Z_hard   (1)
00205 
00206 uint8_t D_commonOn; // common On level set   0:Anode common   1:Cathode common
00207 uint8_t D_commonOff;
00208 
00209 uint8_t D_segmentOn; // segment On level set 0:Cathode common 1:Anode common
00210 uint8_t D_segmentOff;
00211 };
00212 
00213 #endif    // _SEVENSEGLED_H