7-Segment Display Driver class, via an 8-bit shift register (such as the 74HC595)

Dependents:   000-FIN_youcef

Fork of 7SegSRDriver by Paul Law

Files at this revision

API Documentation at this revision

Comitter:
sefyou
Date:
Tue Jun 06 13:28:42 2017 +0000
Parent:
1:e55f543bc06b
Commit message:
yo

Changed in this revision

7SegSRDriver.cpp Show annotated file Show diff for this revision Revisions of this file
7SegSRDriver.h Show annotated file Show diff for this revision Revisions of this file
--- a/7SegSRDriver.cpp	Sun May 01 17:34:00 2011 +0000
+++ b/7SegSRDriver.cpp	Tue Jun 06 13:28:42 2017 +0000
@@ -1,68 +1,264 @@
 #include "mbed.h"
 #include "7SegSRDriver.h"
 
-/* mbed 7-Segment Display Driver Library (via an 8bit Shift Register)
- * Copyright (c) 2011 Paul Law
- *
- * 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.
- */
-
-// Display should be hooked up to shift register as follows:
-// Q0 : Decimal Point, Q1-Q7 : Segments a-g
-
-SSegSRDriver::SSegSRDriver(PinName srData, PinName srClock, PinName srLatch, bool disp_type): _srData(srData), _srClock(srClock), _srLatch(srLatch) {
+/***********************************************            CHRONOMETRE               ****************************************************************/
+SSegSRDriver_chronometre::SSegSRDriver_chronometre(PinName srData, PinName srClock, PinName srLatch, bool disp_type): _srData(srData), _srClock(srClock), _srLatch(srLatch) {
     _disp_type = disp_type;
-    write_raw(0);
+    bus_chronometre_1(0);
+    bus_chronometre_2(0);
+    bus_chronometre_3(0);
+    bus_chronometre_4(0);    
 }
 
-void SSegSRDriver::set_type(bool disp_type) {
-    _disp_type = disp_type;
-}
-
-void SSegSRDriver::clear() {
-    write_raw(0);
+void SSegSRDriver_chronometre::clear() {
+    bus_chronometre_1(0);
+    bus_chronometre_2(0);
+    bus_chronometre_3(0);
+    bus_chronometre_4(0); 
 }
 
-void SSegSRDriver::write(unsigned char number) {
-    write(number,0);
-}
-
-void SSegSRDriver::write(unsigned char number, bool dp) {
-    if (number<16) {
-        // Find the definition of the number in chardefs, shift left, set dp (LSB)
-        write_raw((SSegSRDriver_chardefs[number] << 1) | dp);
+void SSegSRDriver_chronometre::write_chronometre(unsigned char number, bool dp) {
+    if (number<10) {
+        bus_chronometre_1((nbr_envoye[number] << 1) | dp);
     }
 }
 
-void SSegSRDriver::write_raw(unsigned char bValue) {
+void SSegSRDriver_chronometre::write_chronometre_2(unsigned char number, bool dp) {
+    if (number<10) {
+        bus_chronometre_2((nbr_envoye_2[number] << 1) | dp);
+    }
+}
 
-    if (!_disp_type) bValue = ~bValue;  // Reverse value for Common Anode
+void SSegSRDriver_chronometre::write_chronometre_3(unsigned char number, bool dp) {
+    if (number<10) {
+        bus_chronometre_3((nbr_envoye_3[number] << 1) | dp);
+    }
+}
 
-    if (bValue<=0xFF) {
-        // Push value to shift register and latch
+void SSegSRDriver_chronometre::write_chronometre_4(unsigned char number, bool dp) {
+    if (number<10) {
+        bus_chronometre_3((nbr_envoye_4[number] << 1) | dp);
+    }
+}
+
+void SSegSRDriver_chronometre::bus_chronometre_1(unsigned char Val) { // Val= les segments a éclairer  
+
+    if (Val<=0xFF) {// Si la valeur est inférieur ou égale a 255 
         _srLatch = 0;
-        for (int i=7;i>=0;i--) {    // Output MSB to LSB
+        for (int i=7;i>=0;i--) {    // on parcours l'octet 
             _srClock = 0;
-            _srData = (bValue & (1<<i));
+            _srData = (Val & (1<<i)); //décoposition de l'octet en bit 
             _srClock = 1;
         }
         _srLatch = 1;
         _srData = 0;
     }
-}
\ No newline at end of file
+    
+ }   
+    
+void SSegSRDriver_chronometre::bus_chronometre_2(unsigned char Value) 
+{
+
+    if (Value<=0xFF) {// Si la valeur est inférieur ou égale a 255 
+        _srLatch = 0;
+        for (int i=7;i>=0;i--) // on parcours l'octet 
+        {    
+            _srClock = 0;
+            _srData = (Value & (1<<i)); //décoposition de l'octet 
+            _srClock = 1;
+        }   
+        _srLatch = 1;
+        _srData = 0;
+}
+ }  
+ 
+ void SSegSRDriver_chronometre::bus_chronometre_3(unsigned char Value) 
+{
+
+    if (Value<=0xFF) {// Si la valeur est inférieur ou égale a 255 
+        _srLatch = 0;
+        for (int i=7;i>=0;i--) // on parcours l'octet 
+        {    
+            _srClock = 0;
+            _srData = (Value & (1<<i)); //décoposition de l'octet 
+            _srClock = 1;
+        }   
+        _srLatch = 1;
+        _srData = 0;
+}
+ } 
+ 
+ void SSegSRDriver_chronometre::bus_chronometre_4(unsigned char Value) 
+{
+
+    if (Value<=0xFF) {// Si la valeur est inférieur ou égale a 255 
+        _srLatch = 0;
+        for (int i=7;i>=0;i--) // on parcours l'octet 
+        {    
+            _srClock = 0;
+            _srData = (Value & (1<<i)); //décoposition de l'octet 
+            _srClock = 1;
+        }   
+        _srLatch = 1;
+        _srData = 0;
+}
+ } 
+ 
+ 
+ /***********************************************            DOMICILE                ****************************************************************/
+ 
+SSegSRDriver_domicile::SSegSRDriver_domicile(PinName srData, PinName srClock, PinName srLatch, bool disp_type): _srData(srData), _srClock(srClock), _srLatch(srLatch) {
+    _disp_type = disp_type;
+    bus_domicile_1(0);
+    bus_domicile_2(0);
+    bus_domicile_3(0);  
+}
+
+void SSegSRDriver_domicile::clear() {
+    bus_domicile_1(0);
+    bus_domicile_2(0);
+    bus_domicile_3(0);
+}
+
+void SSegSRDriver_domicile::write_domicile(unsigned char number, bool dp) {
+    if (number<10) {
+        bus_domicile_1((nbr_envoye[number] << 1) | dp);
+    }
+}
+
+void SSegSRDriver_domicile::write_domicile_2(unsigned char number, bool dp) {
+    if (number<10) {
+        bus_domicile_2((nbr_envoye_2[number] << 1) | dp);
+    }
+}
+
+void SSegSRDriver_domicile::write_domicile_3(unsigned char number, bool dp) {
+    if (number<10) {
+        bus_domicile_3((nbr_envoye_3[number] << 1) | dp);
+    }
+}
+
+void SSegSRDriver_domicile::bus_domicile_1(unsigned char Val) { // Val= les segments a éclairer  
+
+    if (Val<=0xFF) {// Si la valeur est inférieur ou égale a 255 
+        _srLatch = 0;
+        for (int i=7;i>=0;i--) {    // on parcours l'octet 
+            _srClock = 0;
+            _srData = (Val & (1<<i)); //décoposition de l'octet en bit 
+            _srClock = 1;
+        }
+        _srLatch = 1;
+        _srData = 0;
+    }
+    
+ }  
+ 
+void SSegSRDriver_domicile::bus_domicile_2(unsigned char Val) { // Val= les segments a éclairer  
+
+    if (Val<=0xFF) {// Si la valeur est inférieur ou égale a 255 
+        _srLatch = 0;
+        for (int i=7;i>=0;i--) {    // on parcours l'octet 
+            _srClock = 0;
+            _srData = (Val & (1<<i)); //décoposition de l'octet en bit 
+            _srClock = 1;
+        }
+        _srLatch = 1;
+        _srData = 0;
+    }
+    
+ } 
+ 
+void SSegSRDriver_domicile::bus_domicile_3(unsigned char Val) { // Val= les segments a éclairer  
+
+    if (Val<=0xFF) {// Si la valeur est inférieur ou égale a 255 
+        _srLatch = 0;
+        for (int i=7;i>=0;i--) {    // on parcours l'octet 
+            _srClock = 0;
+            _srData = (Val & (1<<i)); //décoposition de l'octet en bit 
+            _srClock = 1;
+        }
+        _srLatch = 1;
+        _srData = 0;
+    }
+    
+}
+
+ 
+ /***********************************************            VISITEUR               ****************************************************************/
+ 
+SSegSRDriver_visiteur::SSegSRDriver_visiteur(PinName srData, PinName srClock, PinName srLatch, bool disp_type): _srData(srData), _srClock(srClock), _srLatch(srLatch) {
+    _disp_type = disp_type;
+    bus_visiteur_1(0);
+    bus_visiteur_2(0);
+    bus_visiteur_3(0);  
+}
+
+void SSegSRDriver_visiteur::clear() {
+    bus_visiteur_1(0);
+    bus_visiteur_2(0);
+    bus_visiteur_3(0);
+}
+ 
+void SSegSRDriver_visiteur::write_visiteur(unsigned char number, bool dp) {
+    if (number<10) {
+        bus_visiteur_1((nbr_envoye[number] << 1) | dp);
+    }
+}
+
+void SSegSRDriver_visiteur::write_visiteur_2(unsigned char number, bool dp) {
+    if (number<10) {
+        bus_visiteur_2((nbr_envoye_2[number] << 1) | dp);
+    }
+}
+
+void SSegSRDriver_visiteur::write_visiteur_3(unsigned char number, bool dp) {
+    if (number<10) {
+        bus_visiteur_3((nbr_envoye_3[number] << 1) | dp);
+    }
+}
+
+void SSegSRDriver_visiteur::bus_visiteur_1(unsigned char Val) { // Val= les segments a éclairer  
+
+    if (Val<=0xFF) {// Si la valeur est inférieur ou égale a 255 
+        _srLatch = 0;
+        for (int i=7;i>=0;i--) {    // on parcours l'octet 
+            _srClock = 0;
+            _srData = (Val & (1<<i)); //décoposition de l'octet en bit 
+            _srClock = 1;
+        }
+        _srLatch = 1;
+        _srData = 0;
+    }
+    
+ }  
+ 
+void SSegSRDriver_visiteur::bus_visiteur_2(unsigned char Val) { // Val= les segments a éclairer  
+
+    if (Val<=0xFF) {// Si la valeur est inférieur ou égale a 255 
+        _srLatch = 0;
+        for (int i=7;i>=0;i--) {    // on parcours l'octet 
+            _srClock = 0;
+            _srData = (Val & (1<<i)); //décoposition de l'octet en bit 
+            _srClock = 1;
+        }
+        _srLatch = 1;
+        _srData = 0;
+    }
+    
+ } 
+ 
+void SSegSRDriver_visiteur::bus_visiteur_3(unsigned char Val) { // Val= les segments a éclairer  
+
+    if (Val<=0xFF) {// Si la valeur est inférieur ou égale a 255 
+        _srLatch = 0;
+        for (int i=7;i>=0;i--) {    // on parcours l'octet 
+            _srClock = 0;
+            _srData = (Val & (1<<i)); //décoposition de l'octet en bit 
+            _srClock = 1;
+        }
+        _srLatch = 1;
+        _srData = 0;
+    }
+    
+}
+ 
\ No newline at end of file
--- a/7SegSRDriver.h	Sun May 01 17:34:00 2011 +0000
+++ b/7SegSRDriver.h	Tue Jun 06 13:28:42 2017 +0000
@@ -1,25 +1,3 @@
-/* mbed 7-Segment Display Driver Library (via an 8bit Shift Register)
- * Copyright (c) 2011 Paul Law
- *
- * 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.
- */
-
 #ifndef LIB_SSEGSRDRIVER_H
 #define LIB_SSEGSRDRIVER_H
 
@@ -28,75 +6,86 @@
 #define SSegSRDriver_COMN_ANODE 0
 #define SSegSRDriver_COMN_CATHODE 1
 
-//Char defs: 0123456789AbCdEF
-const unsigned char SSegSRDriver_chardefs[16] = {0x3F, 0x6, 0x5B, 0x4F, 0x66, 0x6D, 0x7D, 0x7, 0x7F, 0x6F, 0x77, 0x7C, 0x39, 0x5E, 0x79, 0x71 };
+const unsigned char nbr_envoye[11] = {0x3f, 0x30 , 0x6d, 0x79, 0x72, 0x5b, 0x5f, 0x33, 0x7f, 0x7b, 0x00};
+const unsigned char nbr_envoye_2[11] = {0x3f, 0x30 , 0x6d, 0x79, 0x72, 0x5b, 0x5f, 0x33, 0x7f, 0x7b, 0x00};
+const unsigned char nbr_envoye_3[11] = {0x3f, 0x30 , 0x6d, 0x79, 0x72, 0x5b, 0x5f, 0x33, 0x7f, 0x7b, 0x00};
+const unsigned char nbr_envoye_4[11] = {0x3f, 0x30 , 0x6d, 0x79, 0x72, 0x5b, 0x5f, 0x33, 0x7f, 0x7b, 0x00};
 
-/** 7-Segment Display Driver class, via a 8-bit shift register (such as the 74HC595)
- *
- * Display should be hooked up to shift register as follows:
- * Q0 : Decimal Point, Q1-Q7 : Segments a-g
- *
- * Example:
- * @code
- * #include "mbed.h"
- * #include "7SegSRDriver.h"
- *
- * SSegSRDriver display(p27,p25,p26, SSegSRDriver_COMN_ANODE);
- *
- * int main() {
- *     while (1) {
- *         // Show the chars 0-9 then A-F, flashing the decimal point on and off
- *         for (int i=0; i<16; i++) {
- *             display.write(i,i%2 == 0);
- *             wait(1);
- *         }
- *     }
- * }
- * @endcode
- */
-class SSegSRDriver {
+
+/**************************************************                 CHRONOMETRE                   ****************************************************/
+
+
+class SSegSRDriver_chronometre {
 
 public:
 
-    /** Create a 7-Segment Display Driver object connected to a 8-bit shift register on the given DigitalOut pins
-     *
-     * @param srData Shift Register Data pin (DigitalOut)
-     * @param srClock Shift Register Clock pin (DigitalOut)
-     * @param srLatch Shift Register Latch pin (DigitalOut)
-     * @param disp_type Display Type: Common Anode/Cathode (SSegSRDriver_COMN_ANODE (0) or SSegSRDriver_COMN_CATHODE (1))
-     */
-    SSegSRDriver(PinName srData, PinName srClock, PinName srLatch, bool disp_type);
-
-    /** Change the type of 7-Segment Display
-     *
-     * @param disp_type Display Type: Common Anode/Cathode (SSegSRDriver_COMN_ANODE (0) or SSegSRDriver_COMN_CATHODE (1))
-     */
-    void set_type(bool disp_type);
+    SSegSRDriver_chronometre(PinName srData, PinName srClock, PinName srLatch, bool disp_type);
+    void write_chronometre(unsigned char number, bool dp);   
+    void write_chronometre_2(unsigned char number_deux, bool dp); //
+    void write_chronometre_3(unsigned char number_trois, bool dp);
+    void write_chronometre_4(unsigned char number_quatre, bool dp);
+    
+    void bus_chronometre_1(unsigned char number);   // inustruction pour le bus 1 de 0 a 8 bit 
+    void bus_chronometre_2(unsigned char number_deux);   // inustruction pour le bus 2 de 0 a 8 bit
+    void bus_chronometre_3(unsigned char number_trois);
+    void bus_chronometre_4(unsigned char number_quatre); 
+    void clear();  
     
-    /** Sets the currently shown digit on the display
-     *
-     * @param number The digit to display (0-15) to show numbers 0-9 and letters A-F
-     */
-    void write(unsigned char number); 
+private:
+
+    DigitalOut _srData;
+    DigitalOut _srClock;
+    DigitalOut _srLatch;
+    bool _disp_type;
+};
+
+
+/**************************************************                 DOMICILE                   ****************************************************/
+
+
+class SSegSRDriver_domicile {
+
+public:
+
+    SSegSRDriver_domicile(PinName srData, PinName srClock, PinName srLatch, bool disp_type);
+
+    void set_type(bool disp_type);
+    void write_domicile(unsigned char number, bool dp);   
+    void write_domicile_2(unsigned char number_deux, bool dp); 
+    void write_domicile_3(unsigned char number_trois, bool dp);
+    
+    void bus_domicile_1(unsigned char number);   // inustruction pour le bus 1 de 0 a 8 bit 
+    void bus_domicile_2(unsigned char number_deux);   // inustruction pour le bus 2 de 0 a 8 bit
+    void bus_domicile_3(unsigned char number_trois); 
+    void clear();  
     
-    /** Sets the currently shown digit on the display along with the decimal place
-     *
-     * @param number The digit to display (0-15) to show numbers 0-9 and letters A-F
-     * @param dp If the decimal place should be lit (0:Off, 1:On)
-     */
-    void write(unsigned char number, bool dp);   
+private:
+
+    DigitalOut _srData;
+    DigitalOut _srClock;
+    DigitalOut _srLatch;
+    bool _disp_type;
+};
+
+
+/**************************************************                 VISITEUR                   ****************************************************/
+
+
+class SSegSRDriver_visiteur {
+
+public:
+
+    SSegSRDriver_visiteur(PinName srData, PinName srClock, PinName srLatch, bool disp_type);
+
+    void set_type(bool disp_type);
+    void write_visiteur(unsigned char number, bool dp);   
+    void write_visiteur_2(unsigned char number_deux, bool dp); 
+    void write_visiteur_3(unsigned char number_trois, bool dp);
     
-    /** Sets the segments of the display directly
-     * Segments are lit by binary flags where LSB is the decimal point, then segments a-g up to the MSB
-     * e.g. to light segments e, f and the decimal place = 01100001
-     *
-     * @param bValue The segments to light
-     */
-    void write_raw(unsigned char number);   // Write directly to the display - Q0/Q1-Q7
-    
-    /** Turn all segments of the display off
-     */
-    void clear();   // Clears the display
+    void bus_visiteur_1(unsigned char number);   // inustruction pour le bus 1 de 0 a 8 bit 
+    void bus_visiteur_2(unsigned char number_deux);   // inustruction pour le bus 2 de 0 a 8 bit
+    void bus_visiteur_3(unsigned char number_trois); 
+    void clear();  
     
 private: