Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: eightDotMatrixLedLibraryExample test10_rev2
Revision 0:3df409a1aa42, committed 2011-12-03
- Comitter:
- suupen
- Date:
- Sat Dec 03 23:01:36 2011 +0000
- Commit message:
- V1.01 12/04 example program comment fix.
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/EightDotMatrixLed.cpp Sat Dec 03 23:01:36 2011 +0000
@@ -0,0 +1,274 @@
+/**********************************************************
+
+* EightDotMatrixLed.cpp
+* dynamic control of eight dot matrix led
+*
+**********************************************************/
+#define _EIGHTDOTMATRIXLED_C
+
+#include "types.h"
+#include "mbed.h"
+#include "EightDotMatrixLed.h"
+
+
+
+
+/** Create a eight dot matrix led object connected to the specified DigtalOutput pin
+ */
+EightDotMatrixLed::EightDotMatrixLed(uint8_t commonPole,
+ PinName seg_a, PinName seg_b, PinName seg_c, PinName seg_d, PinName seg_e, PinName seg_f, PinName seg_g, PinName seg_h,
+ PinName com_1, PinName com_2, PinName com_3, PinName com_4, PinName com_5, PinName com_6, PinName com_7, PinName com_8):
+ _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_h(seg_h),
+ _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){
+
+
+ timer.attach_us(this, &EightDotMatrixLed::segmentGrayDataKosin, 10000); // led smooth control 10ms timer inttruupt
+
+ // data table set of Brightness
+ // DT_pwmGray[] = i ^ 2
+ for(uint32_t i = 0; i < Z_grayMax + 1; i++){
+ DT_pwmGray[i] = (uint8_t)(((i * i) * Z_pwmGrayMax ) / (Z_grayMax * Z_grayMax));
+ }
+
+ // check connect com_x
+ D_comNull = Z_comSuu;
+ if(com_8 == NC){D_comNull--;}
+ if(com_7 == NC){D_comNull--;}
+ if(com_6 == NC){D_comNull--;}
+ if(com_5 == NC){D_comNull--;}
+ if(com_4 == NC){D_comNull--;}
+ if(com_3 == NC){D_comNull--;}
+ if(com_2 == NC){D_comNull--;}
+ if(com_1 == NC){D_comNull--;}
+
+
+
+ // common and segment pin display data set
+ if(commonPole == 0){
+ // Anode common
+ D_commonOn = 1;
+ D_commonOff = 0;
+ D_segmentOn = 0;
+ D_segmentOff = 1;
+ }
+ else{
+ // Cathod common
+ D_commonOn = 0;
+ D_commonOff = 1;
+ D_segmentOn = 1;
+ D_segmentOff = 0;
+ }
+
+}
+
+
+
+/**************************************
+* 7segment no gray data kosin
+* 100ms goto no syori
+**************************************/
+void EightDotMatrixLed::segmentGrayDataKosin(void){
+ uint8_t com;
+ uint8_t seg;
+
+ for(com = 0; com < Z_comSuu; com++){
+ for(seg = 0; seg < Z_segSuu; seg++){
+ uint8_t D_dotGrayData = *(A_dotGrayData + (com * Z_segSuu) + seg);
+ uint8_t D_dotDigitalData = *(A_dotDigitalData + (com * Z_segSuu) + seg);
+
+ if((D_dotGrayData <= 100) && (D_dotDigitalData <= 1)){
+ // gray and digital data enable
+ if(D_dotDigitalData == 1){
+ if(D_dotPwmData[com][seg] < D_dotGrayData){
+ D_dotPwmData[com][seg]++;
+ }
+ }
+ else if(D_dotPwmData[com][seg] > 0){
+ D_dotPwmData[com][seg]--;
+ }
+ }
+ else if((D_dotGrayData > 100) && (D_dotDigitalData <= 1)){
+ // gray data disable and digital data enable
+ if(D_dotDigitalData == 1){
+ // digital data on
+ if(D_dotPwmData[com][seg] < Z_grayMax){
+ D_dotPwmData[com][seg]++;
+ }
+ }
+ else{
+ // digital data off
+ if(D_dotPwmData[com][seg] > 0){
+ D_dotPwmData[com][seg]--;
+ }
+ }
+ }
+ else if((D_dotGrayData <= 100) && (D_dotDigitalData > 1)){
+ // gray data enable and digital data disable
+ D_dotPwmData[com][seg] = D_dotGrayData;
+ }
+ else{
+ // gray data and digital data disable
+ D_dotPwmData[com][seg] = 0;
+ }
+ }
+ }
+}
+
+
+/**************************************
+* main
+**************************************/
+void EightDotMatrixLed::EightDotMatrixLed_main(uint8_t* grayData, uint8_t* digitalData) {
+
+ A_dotGrayData = grayData;
+ A_dotDigitalData = digitalData;
+/*
+ for(uint8_t com = 0; com < 8; com++){
+ for(uint8_t seg = 0; seg < 8; seg++){
+ D_dotGrayData[com][seg] = *(grayData + (com * Z_segSuu) + seg);
+ D_dotDigitalData[com][seg] = *(digitalData + (com * Z_segSuu) +seg);
+ }
+ }
+*/
+ // dynamic shuturyoku shori
+ output();
+}
+
+
+/**************************************
+* comAllClear
+*
+* common pin o subete OFF suru
+**************************************/
+void EightDotMatrixLed::comAllClear(void){
+
+ switch (D_comNull){
+ case 8: // com_1 - com_8is all connect
+ _com_8 = D_commonOff;
+ //break;
+ case 7: // com_8 Null
+ _com_7 = D_commonOff;
+ //break;
+ case 6: // com_7 Null
+ _com_6 = D_commonOff;
+ //break;
+ case 5: // com_6 Null
+ _com_5 = D_commonOff;
+ //break;
+ case 4: // com_5 Null
+ _com_4 = D_commonOff;
+ //break;
+ case 3: // com_4 Null
+ _com_3 = D_commonOff;
+ // break;
+ case 2: // com_3 Null
+ _com_2 = D_commonOff;
+ //break;
+ case 1: // com_2 Null
+ _com_1 = D_commonOff;
+ //break;
+ case 0: // com_1 Null
+ // nothing
+ break;
+ default:
+ // nothing
+ break;
+ }
+}
+
+/**************************************
+* segAllClear
+*
+* segment pin o subete OFF suru
+**************************************/
+void EightDotMatrixLed::segAllClear(void){
+ _seg_a = D_segmentOff;
+ _seg_b = D_segmentOff;
+ _seg_c = D_segmentOff;
+ _seg_d = D_segmentOff;
+ _seg_e = D_segmentOff;
+ _seg_f = D_segmentOff;
+ _seg_h = D_segmentOff;
+}
+
+/**************************************
+* segDataSet
+*
+* segment pin ni shuturyoku data o settei
+**************************************/
+void EightDotMatrixLed::segDataSet(uint8_t keta){
+
+ for(uint8_t i = 0; i < Z_pwmGrayMax + 1; i++){
+ if(DT_pwmGray[D_dotPwmData[keta][0]] <= i){_seg_a = D_segmentOff;}else{_seg_a = D_segmentOn;}
+ if(DT_pwmGray[D_dotPwmData[keta][1]] <= i){_seg_b = D_segmentOff;}else{_seg_b = D_segmentOn;}
+ if(DT_pwmGray[D_dotPwmData[keta][2]] <= i){_seg_c = D_segmentOff;}else{_seg_c = D_segmentOn;}
+ if(DT_pwmGray[D_dotPwmData[keta][3]] <= i){_seg_d = D_segmentOff;}else{_seg_d = D_segmentOn;}
+ if(DT_pwmGray[D_dotPwmData[keta][4]] <= i){_seg_e = D_segmentOff;}else{_seg_e = D_segmentOn;}
+ if(DT_pwmGray[D_dotPwmData[keta][5]] <= i){_seg_f = D_segmentOff;}else{_seg_f = D_segmentOn;}
+ if(DT_pwmGray[D_dotPwmData[keta][6]] <= i){_seg_g = D_segmentOff;}else{_seg_g = D_segmentOn;}
+ if(DT_pwmGray[D_dotPwmData[keta][7]] <= i){_seg_h = D_segmentOff;}else{_seg_h = D_segmentOn;}
+
+ }
+}
+
+/**************************************
+* output
+*
+* dynamic dosa saseru.
+* kono kansu wo jiikou suru tabi ni common pin o kirikaeru
+**************************************/
+void EightDotMatrixLed::output(void){
+ static uint8_t M_seg = 0;
+
+ if(M_seg >= D_comNull){M_seg = 0;}
+
+ // com, seg syokika
+ comAllClear();
+ segAllClear();
+
+
+
+ // common output
+ if(D_comNull != 0){
+ // If the terminal output processing
+ switch(M_seg){
+ case 0:
+ _com_1 = D_commonOn;
+ break;
+ case 1:
+ _com_2 = D_commonOn;
+ break;
+ case 2:
+ _com_3 = D_commonOn;
+ break;
+ case 3:
+ _com_4 = D_commonOn;
+ break;
+ case 4:
+ _com_5 = D_commonOn;
+ break;
+ case 5:
+ _com_6 = D_commonOn;
+ break;
+ case 6:
+ _com_7 = D_commonOn;
+ break;
+ case 7:
+ _com_8 = D_commonOn;
+ break;
+ default:
+ break;
+ }
+ }
+
+ // segmant output
+ if(M_seg < Z_comSuu){
+ segDataSet(M_seg);
+ }
+
+
+ // com, seg syokika
+ comAllClear();
+ segAllClear();
+ M_seg++;
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/EightDotMatrixLed.h Sat Dec 03 23:01:36 2011 +0000
@@ -0,0 +1,203 @@
+/* mbed Eight Dot Matrix LED Library
+ * Copyright (c) 2011 suupen
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+
+//================================
+// EightDotMatrixLed.h
+// V1.0 : 2011/12/03
+//
+//================================
+#ifndef _EIGHTDOTMATRIXLED_H
+#define _EIGHTDOTMATRIXLED_H
+
+/** Seven segment Numeric LED control class
+ *
+ * Example:
+ * @code
+ * //============================================
+ * // eightDotMatrixLed Library Example
+ * //
+ * // This program is used to control the LED 32.
+ * //
+ * //
+ * // <schematic>
+ * // --|>|--
+ * // A K
+ * // seg A(p5) -----R(200[ohm])--- LED ----- com0(p13)
+ * // |
+ * // -- R(200[ohm])--- LED ----- com1(p14)
+ * // |
+ * // -- R(200[ohm])--- LED ----- com2(p28)
+ * // |
+ * // -- R(200[ohm])--- LED ----- com3(p27)
+ * //
+ * //
+ * // same : segB(p6), segC(p7), segD(p8), segE(p9), segF(p10), segG(p11), segH(p12)
+ * //
+ * // <Description of LED control>
+ * // com0 Led off to on ,on to off smooth (lighting = 0 to 100 [%]
+ * // com1 Led off to on smooth, on to off hard
+ * // com2 Led off to on, on to off smooth (lighting = 0 to gray data)
+ * // com3 gray data movement
+ * //
+ * //=============================================
+ *
+ * #include "mbed.h"
+ *
+ * #include "EightDotMatrixLed.h"
+ *
+ * // common type (0:anode common 1:cathode common)
+ * // |
+ * // | segA segB segC segD segE segF segG segh com1 com2 com3 com4 (com5 to com8 = disable)
+ * // | | | | | | | | | | | | |
+ * EightDotMatrixLed segmentled(1, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p28, p27);
+ *
+ * // com0 Led off to on ,on to off smooth (lighting = 0 to 100 [%]
+ * // com1 Led off to on smooth, on to off hard
+ * // com2 Led off to on, on to off smooth (lighting = 0 to gray data)
+ * // com3 gray data movement
+ *
+ * uint8_t D_dotGrayData[4][8] = {
+ * {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}, // com0 disable
+ * {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}, // com1 disable
+ * {0, 14, 29, 43, 57, 71, 86, 100}, // com2 enable (0 to 100 [%])
+ * {0, 14, 29, 43, 57, 71, 86, 100}, // com3 enable (0 to 100 [%])
+ * };
+ * uint8_t D_dotDigitalData[4][8] = {
+ * {0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // com0 0:off, 1:on
+ * {0x01, 0x01, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}, // com1 0:disalbe 1:on
+ * {0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}, // com2 0:off, 1:on
+ * {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff} // com3 disable
+ * };
+ *
+ * Timer timer; // data change timer
+ *
+ * int main() {
+ * uint8_t com, seg;
+ * uint8_t wk0, wk1, wk2, wk3;
+ *
+ * timer.start();
+ *
+ * while(1) {
+ * // After 500[ms] to start the process
+ * if(timer.read_ms() >= 500){
+ * timer.reset();
+ *
+ * // com0 Led off to on ,on to off smooth (lighting = 0 to 100 [%]
+ * wk0 = D_dotDigitalData[0][7];
+ * for(seg = 7; seg > 0; seg--){
+ * D_dotDigitalData[0][seg] = D_dotDigitalData[0][seg - 1];
+ * }
+ * D_dotDigitalData[0][0] = wk0;
+ *
+ * // com1 Led off to on smooth, on to off hard
+ * wk1 = D_dotDigitalData[1][7];
+ * for(seg = 7; seg > 0; seg--){
+ * D_dotDigitalData[1][seg] = D_dotDigitalData[1][seg - 1];
+ * }
+ * D_dotDigitalData[1][0] = wk1;
+ *
+ * // com2 Led off to on, on to off smooth (lighting = 0 to gray data)
+ * wk2 = D_dotDigitalData[2][7];
+ * for(seg = 7; seg > 0; seg--){
+ * D_dotDigitalData[2][seg] = D_dotDigitalData[2][seg - 1];
+ * }
+ * D_dotDigitalData[2][0] = wk2;
+ *
+ * // com3 gray data movement
+ * wk3 = D_dotGrayData[3][7];
+ * for(seg = 7; seg > 0; seg--){
+ * D_dotGrayData[3][seg] = D_dotGrayData[3][seg - 1];
+ * }
+ * D_dotGrayData[3][0] = wk3;
+ * }
+ *
+ * // This function, please repeat the process in less than 1ms.
+ * segmentled.EightDotMatrixLed_main((uint8_t*)D_dotGrayData, (uint8_t*)D_dotDigitalData);
+ *
+ * }
+ *}
+ * @endcode
+ */
+
+
+
+#include "types.h"
+
+class EightDotMatrixLed {
+public:
+
+
+
+ /** Create a eight dot matrix led array object connected to the specified DigitalOut pin
+ * @param commonPole The polarity of the seven segment led common 0:Anode common, 1:Cathode common
+ * @param seg_a - seg_h DigitalOut pin to connect to. To provide members with an array of uint8_t digit minutes.
+ * @param com_1 - com_8 DigitalOut pin to connect to. To provide members with an array of uint8_t digit minutes. 8 digits maximum
+ */
+ EightDotMatrixLed(uint8_t commonPole,
+ PinName seg_a, PinName seg_b, PinName seg_c, PinName seg_d, PinName seg_e, PinName seg_f, PinName seg_g, PinName seg_h,
+ PinName com_1 = NC, PinName com_2 = NC, PinName com_3 = NC, PinName com_4 = NC,
+ PinName com_5 = NC, PinName com_6 = NC, PinName com_7 = NC, PinName com_8 = NC);
+
+ /** Data set to the seven segment LED display
+ * @param uint8_t* grayData[8][8] address pointer : 0 - 100 (1/1 [%]/count) other:disable example 0:ledOff, 100:led max lighting
+ * @param uint8_t* digitalData[8][8] address pointer : 0 :ledOff 1 : ledOn other:disable (1[s] de henka)
+ */
+ void EightDotMatrixLed_main(uint8_t* grayData, uint8_t* digitalData);
+
+private:
+void segmentGrayDataKosin(void);
+void comAllClear(void);
+void segAllClear(void);
+void segDataSet(uint8_t keta);
+void output(void);
+
+// pin set_seg, _com;
+ DigitalOut _seg_a, _seg_b, _seg_c, _seg_d, _seg_e, _seg_f, _seg_g, _seg_h;
+ DigitalOut _com_1, _com_2, _com_3, _com_4, _com_5, _com_6, _com_7, _com_8;
+
+ Ticker timer;
+
+#define Z_comSuu (8) // max number of common pin
+#define Z_segSuu (8) // max number of segment pin
+#define Z_grayMax (100) // grayData max 100 kaicho
+#define Z_pwmGrayMax (100) // pwm max (led heno pwm syuturyoku no max)
+
+uint8_t* A_dotDigitalData; // D_dotDigitalData[Z_comSuu][Z_segSuu] address pointer
+ //uint8_t D_dotDigitalData[Z_comSuu][Z_segSuu]; // segment dot digital data 0 :ledOff ,1 : ledOn other:disable (1[s] de henka)
+uint8_t* A_dotGrayData; // D_dotGrayData[Z_comSuu][Z_segSuu] address pointer
+ //uint8_t D_dotGrayData[Z_comSuu][Z_segSuu]; // setment dot gray data 0 - 100 (1/1 [%]/count) other:disable example 0:ledOff, 100:led max lighting
+
+uint8_t DT_pwmGray[Z_grayMax + 1]; // gray data kara pwm data heno henkan table
+
+uint8_t D_dotPwmData[Z_comSuu][Z_segSuu]; // pwm output data 0 - 100 (1/1 [%]/count) example 0:ledOff, 100:led max lighting
+
+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)
+
+uint8_t D_commonOn; // common On level set 0:Anode common 1:Cathode common
+uint8_t D_commonOff;
+
+uint8_t D_segmentOn; // segment On level set 0:Cathode common 1:Anode common
+uint8_t D_segmentOff;
+};
+
+#endif // _EIGHTDOTMATRIXLED_H
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/types.h Sat Dec 03 23:01:36 2011 +0000
@@ -0,0 +1,114 @@
+/*----------------------------------------------------------------------------*/
+/* File Information */
+/*----------------------------------------------------------------------------*/
+/* Name : types.h */
+/* Type : C Programming Language Header */
+/*----------------------------------------------------------------------------*/
+/*----------------------------------------------------------------------------*/
+
+#ifndef __TYPES_H__
+#define __TYPES_H__
+
+#include "stdint.h"
+/*
+typedef char int8_t;
+typedef unsigned char uint8_t;
+typedef signed short int16_t;
+typedef unsigned short uint16_t;
+typedef signed int int32_t;
+typedef unsigned int uint32_t;
+typedef signed long long int64_t;
+typedef unsigned long long uint64_t;
+*/
+//typedef bool bool_t;
+typedef enum{TRUE, FALSE} bool_t;
+
+//=========================================================================
+// byte bit access
+//=========================================================================
+typedef union{ // BYTE/NIBBLE/BIT access
+ uint8_t byte; // Byte access
+ struct{ // Nibble access
+ uint8_t lo : 4; // lower(Bit0 - 3)
+ uint8_t hi : 4; // upper(Bit4 - 7)
+ }nibble;
+ struct{ // Bit access
+ uint8_t b0 : 1; // Bit0
+ uint8_t b1 : 1; // Bit1
+ uint8_t b2 : 1; // Bit2
+ uint8_t b3 : 1; // Bit3
+ uint8_t b4 : 1; // Bit4
+ uint8_t b5 : 1; // Bit5
+ uint8_t b6 : 1; // Bit6
+ uint8_t b7 : 1; // Bit7
+ }bits;
+}byte_t;
+
+//=========================================================================
+// word bit access
+//=========================================================================
+typedef union{ // WORD/BYTE/NIBBLE/BIT access
+ uint16_t word; // Word access
+ struct{ // Byte access
+ uint8_t b0; // upper byte
+ uint8_t b1; // lower byte
+ }byte;
+ struct { // Nibble access
+ uint8_t n0 : 4; // lower byte low(Bit 0 - 3)
+ uint8_t n1 : 4; // lower byte up (Bit 4 - 7)
+ uint8_t n2 : 4; // upper byte low(Bit 8 - 11)
+ uint8_t n3 : 4; // upper byte up (Bit12 - 15)
+ }nibble;
+ struct{ // Bit acces
+ uint8_t b0 : 1; // Bit0
+ uint8_t b1 : 1; // Bit1
+ uint8_t b2 : 1; // Bit2
+ uint8_t b3 : 1; // Bit3
+ uint8_t b4 : 1; // Bit4
+ uint8_t b5 : 1; // Bit5
+ uint8_t b6 : 1; // Bit6
+ uint8_t b7 : 1; // Bit7
+ uint8_t b8 : 1; // Bit8
+ uint8_t b9 : 1; // Bit9
+ uint8_t b10: 1; // Bit10
+ uint8_t b11: 1; // Bit11
+ uint8_t b12: 1; // Bit12
+ uint8_t b13: 1; // Bit13
+ uint8_t b14: 1; // Bit14
+ uint8_t b15: 1; // Bit15
+ }bits;
+}word_t;
+
+
+//=========================================================================
+// ascii code
+//=========================================================================
+#define Z_NUL (0x00)
+#define Z_SOH (0x01)
+#define Z_STX (0x02)
+#define Z_ETX (0x03)
+#define Z_EOT (0x04)
+#define Z_ENQ (0x05)
+#define Z_ACK (0x06)
+#define Z_BEL (0x07)
+
+#define Z_BS (0x08)
+#define Z_HT (0x09)
+#define Z_LF (0x0A)
+#define Z_HM (0x0B)
+#define Z_FF (0x0C)
+#define Z_CR (0x0D)
+#define Z_SO (0x0E)
+#define Z_SI (0x0F)
+
+#define Z_DLE (0x10)
+#define Z_DC1 (0x11)
+#define Z_DC2 (0x12)
+#define Z_DC3 (0x13)
+#define Z_DC4 (0x14)
+#define Z_NAK (0x15)
+#define Z_SYN (0x16)
+#define Z_ETB (0x17)
+
+
+#endif /* __TYPES_H__*/
\ No newline at end of file