to test synchronize signals by a 22k signal.

Committer:
test
Date:
Tue Apr 17 07:40:02 2012 +0000
Revision:
0:3d76f0b19b14
1.0

Who changed what in which revision?

UserRevisionLine numberNew contents of line
test 0:3d76f0b19b14 1 #include "mbed.h"
test 0:3d76f0b19b14 2 #include "7SegSRDriver.h"
test 0:3d76f0b19b14 3
test 0:3d76f0b19b14 4 /* mbed 7-Segment Display Driver Library (via an 8bit Shift Register)
test 0:3d76f0b19b14 5 * Copyright (c) 2011 Paul Law
test 0:3d76f0b19b14 6 *
test 0:3d76f0b19b14 7 * Permission is hereby granted, free of charge, to any person obtaining a copy
test 0:3d76f0b19b14 8 * of this software and associated documentation files (the "Software"), to deal
test 0:3d76f0b19b14 9 * in the Software without restriction, including without limitation the rights
test 0:3d76f0b19b14 10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
test 0:3d76f0b19b14 11 * copies of the Software, and to permit persons to whom the Software is
test 0:3d76f0b19b14 12 * furnished to do so, subject to the following conditions:
test 0:3d76f0b19b14 13 *
test 0:3d76f0b19b14 14 * The above copyright notice and this permission notice shall be included in
test 0:3d76f0b19b14 15 * all copies or substantial portions of the Software.
test 0:3d76f0b19b14 16 *
test 0:3d76f0b19b14 17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
test 0:3d76f0b19b14 18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
test 0:3d76f0b19b14 19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
test 0:3d76f0b19b14 20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
test 0:3d76f0b19b14 21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
test 0:3d76f0b19b14 22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
test 0:3d76f0b19b14 23 * THE SOFTWARE.
test 0:3d76f0b19b14 24 */
test 0:3d76f0b19b14 25
test 0:3d76f0b19b14 26 // Display should be hooked up to shift register as follows:
test 0:3d76f0b19b14 27 // Q0 : Decimal Point, Q1-Q7 : Segments a-g
test 0:3d76f0b19b14 28
test 0:3d76f0b19b14 29 SSegSRDriver::SSegSRDriver(PinName srData, PinName srClock, PinName srLatch, bool disp_type): _srData(srData), _srClock(srClock), _srLatch(srLatch) {
test 0:3d76f0b19b14 30 _disp_type = disp_type;
test 0:3d76f0b19b14 31 write_raw(0);
test 0:3d76f0b19b14 32 }
test 0:3d76f0b19b14 33
test 0:3d76f0b19b14 34 void SSegSRDriver::set_type(bool disp_type) {
test 0:3d76f0b19b14 35 _disp_type = disp_type;
test 0:3d76f0b19b14 36 }
test 0:3d76f0b19b14 37
test 0:3d76f0b19b14 38 void SSegSRDriver::clear() {
test 0:3d76f0b19b14 39 write_raw(0);
test 0:3d76f0b19b14 40 }
test 0:3d76f0b19b14 41
test 0:3d76f0b19b14 42 void SSegSRDriver::write(unsigned char number) {
test 0:3d76f0b19b14 43 write(number,0);
test 0:3d76f0b19b14 44 }
test 0:3d76f0b19b14 45
test 0:3d76f0b19b14 46 void SSegSRDriver::write(unsigned char number, bool dp) {
test 0:3d76f0b19b14 47 if (number<16) {
test 0:3d76f0b19b14 48 // Find the definition of the number in chardefs, shift left, set dp (LSB)
test 0:3d76f0b19b14 49 if(!_disp_type) //if Common Anode
test 0:3d76f0b19b14 50 write_raw((SSegSRDriver_chardefs[number])<<1 | dp); //small change to fit taobao buy LEDs.
test 0:3d76f0b19b14 51 else //if common Cathode
test 0:3d76f0b19b14 52 write_raw((SSegSRDriver_chardefs[number]) | (dp<<0x7)); //small change to fit taobao buy LEDs.
test 0:3d76f0b19b14 53 }
test 0:3d76f0b19b14 54 }
test 0:3d76f0b19b14 55
test 0:3d76f0b19b14 56 void SSegSRDriver::write_raw(unsigned char bValue) {
test 0:3d76f0b19b14 57
test 0:3d76f0b19b14 58 if (!_disp_type) bValue = ~bValue; // Reverse value for Common Anode
test 0:3d76f0b19b14 59
test 0:3d76f0b19b14 60 if (bValue<=0xFF) {
test 0:3d76f0b19b14 61 // Push value to shift register and latch
test 0:3d76f0b19b14 62 _srLatch = 0;
test 0:3d76f0b19b14 63 for (int i=7;i>=0;i--) { // Output MSB to LSB
test 0:3d76f0b19b14 64 _srClock = 0;
test 0:3d76f0b19b14 65 _srData = (bValue & (1<<i));
test 0:3d76f0b19b14 66 _srClock = 1;
test 0:3d76f0b19b14 67 }
test 0:3d76f0b19b14 68 _srLatch = 1;
test 0:3d76f0b19b14 69 _srData = 0;
test 0:3d76f0b19b14 70 }
test 0:3d76f0b19b14 71 }