test test
/
calcRate
to test synchronize signals by a 22k signal.
7SegSRDriver.h@0:3d76f0b19b14, 2012-04-17 (annotated)
- Committer:
- test
- Date:
- Tue Apr 17 07:40:02 2012 +0000
- Revision:
- 0:3d76f0b19b14
1.0
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
test | 0:3d76f0b19b14 | 1 | /* mbed 7-Segment Display Driver Library (via an 8bit Shift Register) |
test | 0:3d76f0b19b14 | 2 | * Copyright (c) 2011 Paul Law |
test | 0:3d76f0b19b14 | 3 | * |
test | 0:3d76f0b19b14 | 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
test | 0:3d76f0b19b14 | 5 | * of this software and associated documentation files (the "Software"), to deal |
test | 0:3d76f0b19b14 | 6 | * in the Software without restriction, including without limitation the rights |
test | 0:3d76f0b19b14 | 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
test | 0:3d76f0b19b14 | 8 | * copies of the Software, and to permit persons to whom the Software is |
test | 0:3d76f0b19b14 | 9 | * furnished to do so, subject to the following conditions: |
test | 0:3d76f0b19b14 | 10 | * |
test | 0:3d76f0b19b14 | 11 | * The above copyright notice and this permission notice shall be included in |
test | 0:3d76f0b19b14 | 12 | * all copies or substantial portions of the Software. |
test | 0:3d76f0b19b14 | 13 | * |
test | 0:3d76f0b19b14 | 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
test | 0:3d76f0b19b14 | 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
test | 0:3d76f0b19b14 | 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
test | 0:3d76f0b19b14 | 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
test | 0:3d76f0b19b14 | 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
test | 0:3d76f0b19b14 | 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
test | 0:3d76f0b19b14 | 20 | * THE SOFTWARE. |
test | 0:3d76f0b19b14 | 21 | */ |
test | 0:3d76f0b19b14 | 22 | |
test | 0:3d76f0b19b14 | 23 | #ifndef LIB_SSEGSRDRIVER_H |
test | 0:3d76f0b19b14 | 24 | #define LIB_SSEGSRDRIVER_H |
test | 0:3d76f0b19b14 | 25 | |
test | 0:3d76f0b19b14 | 26 | #include "mbed.h" |
test | 0:3d76f0b19b14 | 27 | |
test | 0:3d76f0b19b14 | 28 | #define SSegSRDriver_COMN_ANODE 0 |
test | 0:3d76f0b19b14 | 29 | #define SSegSRDriver_COMN_CATHODE 1 |
test | 0:3d76f0b19b14 | 30 | |
test | 0:3d76f0b19b14 | 31 | //Char defs: 0123456789AbCdEF |
test | 0:3d76f0b19b14 | 32 | const unsigned char SSegSRDriver_chardefs[16] = {0x3F, 0x6, 0x5B, 0x4F, 0x66, 0x6D, 0x7D, 0x7, 0x7F, 0x6F, 0x77, 0x7C, 0x39, 0x5E, 0x79, 0x71 }; |
test | 0:3d76f0b19b14 | 33 | |
test | 0:3d76f0b19b14 | 34 | /** 7-Segment Display Driver class, via a 8-bit shift register (such as the 74HC595) |
test | 0:3d76f0b19b14 | 35 | * |
test | 0:3d76f0b19b14 | 36 | * Display should be hooked up to shift register as follows: |
test | 0:3d76f0b19b14 | 37 | * Q0 : Decimal Point, Q1-Q7 : Segments a-g |
test | 0:3d76f0b19b14 | 38 | * |
test | 0:3d76f0b19b14 | 39 | * Example: |
test | 0:3d76f0b19b14 | 40 | * @code |
test | 0:3d76f0b19b14 | 41 | * #include "mbed.h" |
test | 0:3d76f0b19b14 | 42 | * #include "7SegSRDriver.h" |
test | 0:3d76f0b19b14 | 43 | * |
test | 0:3d76f0b19b14 | 44 | * SSegSRDriver display(p27,p25,p26, SSegSRDriver_COMN_ANODE); |
test | 0:3d76f0b19b14 | 45 | * |
test | 0:3d76f0b19b14 | 46 | * int main() { |
test | 0:3d76f0b19b14 | 47 | * while (1) { |
test | 0:3d76f0b19b14 | 48 | * // Show the chars 0-9 then A-F, flashing the decimal point on and off |
test | 0:3d76f0b19b14 | 49 | * for (int i=0; i<16; i++) { |
test | 0:3d76f0b19b14 | 50 | * display.write(i,i%2 == 0); |
test | 0:3d76f0b19b14 | 51 | * wait(1); |
test | 0:3d76f0b19b14 | 52 | * } |
test | 0:3d76f0b19b14 | 53 | * } |
test | 0:3d76f0b19b14 | 54 | * } |
test | 0:3d76f0b19b14 | 55 | * @endcode |
test | 0:3d76f0b19b14 | 56 | */ |
test | 0:3d76f0b19b14 | 57 | class SSegSRDriver { |
test | 0:3d76f0b19b14 | 58 | |
test | 0:3d76f0b19b14 | 59 | public: |
test | 0:3d76f0b19b14 | 60 | |
test | 0:3d76f0b19b14 | 61 | /** Create a 7-Segment Display Driver object connected to a 8-bit shift register on the given DigitalOut pins |
test | 0:3d76f0b19b14 | 62 | * |
test | 0:3d76f0b19b14 | 63 | * @param srData Shift Register Data pin (DigitalOut) |
test | 0:3d76f0b19b14 | 64 | * @param srClock Shift Register Clock pin (DigitalOut) |
test | 0:3d76f0b19b14 | 65 | * @param srLatch Shift Register Latch pin (DigitalOut) |
test | 0:3d76f0b19b14 | 66 | * @param disp_type Display Type: Common Anode/Cathode (SSegSRDriver_COMN_ANODE (0) or SSegSRDriver_COMN_CATHODE (1)) |
test | 0:3d76f0b19b14 | 67 | */ |
test | 0:3d76f0b19b14 | 68 | SSegSRDriver(PinName srData, PinName srClock, PinName srLatch, bool disp_type); |
test | 0:3d76f0b19b14 | 69 | |
test | 0:3d76f0b19b14 | 70 | /** Change the type of 7-Segment Display |
test | 0:3d76f0b19b14 | 71 | * |
test | 0:3d76f0b19b14 | 72 | * @param disp_type Display Type: Common Anode/Cathode (SSegSRDriver_COMN_ANODE (0) or SSegSRDriver_COMN_CATHODE (1)) |
test | 0:3d76f0b19b14 | 73 | */ |
test | 0:3d76f0b19b14 | 74 | void set_type(bool disp_type); |
test | 0:3d76f0b19b14 | 75 | |
test | 0:3d76f0b19b14 | 76 | /** Sets the currently shown digit on the display |
test | 0:3d76f0b19b14 | 77 | * |
test | 0:3d76f0b19b14 | 78 | * @param number The digit to display (0-15) to show numbers 0-9 and letters A-F |
test | 0:3d76f0b19b14 | 79 | */ |
test | 0:3d76f0b19b14 | 80 | void write(unsigned char number); |
test | 0:3d76f0b19b14 | 81 | |
test | 0:3d76f0b19b14 | 82 | /** Sets the currently shown digit on the display along with the decimal place |
test | 0:3d76f0b19b14 | 83 | * |
test | 0:3d76f0b19b14 | 84 | * @param number The digit to display (0-15) to show numbers 0-9 and letters A-F |
test | 0:3d76f0b19b14 | 85 | * @param dp If the decimal place should be lit (0:Off, 1:On) |
test | 0:3d76f0b19b14 | 86 | */ |
test | 0:3d76f0b19b14 | 87 | void write(unsigned char number, bool dp); |
test | 0:3d76f0b19b14 | 88 | |
test | 0:3d76f0b19b14 | 89 | /** Sets the segments of the display directly |
test | 0:3d76f0b19b14 | 90 | * Segments are lit by binary flags where LSB is the decimal point, then segments a-g up to the MSB |
test | 0:3d76f0b19b14 | 91 | * e.g. to light segments e, f and the decimal place = 01100001 |
test | 0:3d76f0b19b14 | 92 | * |
test | 0:3d76f0b19b14 | 93 | * @param bValue The segments to light |
test | 0:3d76f0b19b14 | 94 | */ |
test | 0:3d76f0b19b14 | 95 | void write_raw(unsigned char number); // Write directly to the display - Q0/Q1-Q7 |
test | 0:3d76f0b19b14 | 96 | |
test | 0:3d76f0b19b14 | 97 | /** Turn all segments of the display off |
test | 0:3d76f0b19b14 | 98 | */ |
test | 0:3d76f0b19b14 | 99 | void clear(); // Clears the display |
test | 0:3d76f0b19b14 | 100 | |
test | 0:3d76f0b19b14 | 101 | private: |
test | 0:3d76f0b19b14 | 102 | |
test | 0:3d76f0b19b14 | 103 | DigitalOut _srData; |
test | 0:3d76f0b19b14 | 104 | DigitalOut _srClock; |
test | 0:3d76f0b19b14 | 105 | DigitalOut _srLatch; |
test | 0:3d76f0b19b14 | 106 | bool _disp_type; |
test | 0:3d76f0b19b14 | 107 | }; |
test | 0:3d76f0b19b14 | 108 | |
test | 0:3d76f0b19b14 | 109 | #endif |