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.
7SegSRDriver.h
00001 /* mbed 7-Segment Display Driver Library (via an 8bit Shift Register) 00002 * Copyright (c) 2011 Paul Law 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 #ifndef LIB_SSEGSRDRIVER_H 00024 #define LIB_SSEGSRDRIVER_H 00025 00026 #include "mbed.h" 00027 00028 #define SSegSRDriver_COMN_ANODE 0 00029 #define SSegSRDriver_COMN_CATHODE 1 00030 00031 //Char defs: 0123456789AbCdEF 00032 const unsigned char SSegSRDriver_chardefs[16] = {0x3F, 0x6, 0x5B, 0x4F, 0x66, 0x6D, 0x7D, 0x7, 0x7F, 0x6F, 0x77, 0x7C, 0x39, 0x5E, 0x79, 0x71 }; 00033 00034 /** 7-Segment Display Driver class, via a 8-bit shift register (such as the 74HC595) 00035 * 00036 * Display should be hooked up to shift register as follows: 00037 * Q0 : Decimal Point, Q1-Q7 : Segments a-g 00038 * 00039 * Example: 00040 * @code 00041 * #include "mbed.h" 00042 * #include "7SegSRDriver.h" 00043 * 00044 * SSegSRDriver display(p27,p25,p26, SSegSRDriver_COMN_ANODE); 00045 * 00046 * int main() { 00047 * while (1) { 00048 * // Show the chars 0-9 then A-F, flashing the decimal point on and off 00049 * for (int i=0; i<16; i++) { 00050 * display.write(i,i%2 == 0); 00051 * wait(1); 00052 * } 00053 * } 00054 * } 00055 * @endcode 00056 */ 00057 class SSegSRDriver { 00058 00059 public: 00060 00061 /** Create a 7-Segment Display Driver object connected to a 8-bit shift register on the given DigitalOut pins 00062 * 00063 * @param srData Shift Register Data pin (DigitalOut) 00064 * @param srClock Shift Register Clock pin (DigitalOut) 00065 * @param srLatch Shift Register Latch pin (DigitalOut) 00066 * @param disp_type Display Type: Common Anode/Cathode (SSegSRDriver_COMN_ANODE (0) or SSegSRDriver_COMN_CATHODE (1)) 00067 */ 00068 SSegSRDriver(PinName srData, PinName srClock, PinName srLatch, bool disp_type); 00069 00070 /** Change the type of 7-Segment Display 00071 * 00072 * @param disp_type Display Type: Common Anode/Cathode (SSegSRDriver_COMN_ANODE (0) or SSegSRDriver_COMN_CATHODE (1)) 00073 */ 00074 void set_type(bool disp_type); 00075 00076 /** Sets the currently shown digit on the display 00077 * 00078 * @param number The digit to display (0-15) to show numbers 0-9 and letters A-F 00079 */ 00080 void write(unsigned char number); 00081 00082 /** Sets the currently shown digit on the display along with the decimal place 00083 * 00084 * @param number The digit to display (0-15) to show numbers 0-9 and letters A-F 00085 * @param dp If the decimal place should be lit (0:Off, 1:On) 00086 */ 00087 void write(unsigned char number, bool dp); 00088 00089 /** Sets the segments of the display directly 00090 * Segments are lit by binary flags where LSB is the decimal point, then segments a-g up to the MSB 00091 * e.g. to light segments e, f and the decimal place = 01100001 00092 * 00093 * @param bValue The segments to light 00094 */ 00095 void write_raw(unsigned char number); // Write directly to the display - Q0/Q1-Q7 00096 00097 /** Turn all segments of the display off 00098 */ 00099 void clear(); // Clears the display 00100 00101 private: 00102 00103 DigitalOut _srData; 00104 DigitalOut _srClock; 00105 DigitalOut _srLatch; 00106 bool _disp_type; 00107 }; 00108 00109 #endif
Generated on Fri Jul 15 2022 08:30:50 by
1.7.2