7 segment display library for mbed This routine support 2,4 and 8 digit anode-common or cathode-common LED.

Dependents:   7segMbed

Committer:
morecat_lab
Date:
Sun Oct 20 05:59:40 2013 +0000
Revision:
0:6bf4ee8ee342
Child:
1:12daa491059c
1st release

Who changed what in which revision?

UserRevisionLine numberNew contents of line
morecat_lab 0:6bf4ee8ee342 1 /*
morecat_lab 0:6bf4ee8ee342 2 SSeg.cpp - mbed library for 7seg 4digit/8digit LED matrix.
morecat_lab 0:6bf4ee8ee342 3 Copyright 2013 morecat_lab
morecat_lab 0:6bf4ee8ee342 4
morecat_lab 0:6bf4ee8ee342 5 base on Dots library.
morecat_lab 0:6bf4ee8ee342 6 Copyright 2010 arms22. All right reserved.
morecat_lab 0:6bf4ee8ee342 7
morecat_lab 0:6bf4ee8ee342 8 This library is distributed in the hope that it will be useful,
morecat_lab 0:6bf4ee8ee342 9 but WITHOUT ANY WARRANTY; without even the implied warranty of
morecat_lab 0:6bf4ee8ee342 10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
morecat_lab 0:6bf4ee8ee342 11 */
morecat_lab 0:6bf4ee8ee342 12
morecat_lab 0:6bf4ee8ee342 13 #ifndef SSEG_H
morecat_lab 0:6bf4ee8ee342 14 #define SSEG_H
morecat_lab 0:6bf4ee8ee342 15
morecat_lab 0:6bf4ee8ee342 16 #include "mbed.h"
morecat_lab 0:6bf4ee8ee342 17 #include <Timer.h>
morecat_lab 0:6bf4ee8ee342 18
morecat_lab 0:6bf4ee8ee342 19 #define NUM_PAT_0 0xfc
morecat_lab 0:6bf4ee8ee342 20 #define NUM_PAT_1 0x60
morecat_lab 0:6bf4ee8ee342 21 #define NUM_PAT_2 0xda
morecat_lab 0:6bf4ee8ee342 22 #define NUM_PAT_3 0xf2
morecat_lab 0:6bf4ee8ee342 23 #define NUM_PAT_4 0x66
morecat_lab 0:6bf4ee8ee342 24 #define NUM_PAT_5 0xb6
morecat_lab 0:6bf4ee8ee342 25 #define NUM_PAT_6 0xbe
morecat_lab 0:6bf4ee8ee342 26 #define NUM_PAT_7 0xe0
morecat_lab 0:6bf4ee8ee342 27 #define NUM_PAT_8 0xfe
morecat_lab 0:6bf4ee8ee342 28 #define NUM_PAT_9 0xf6
morecat_lab 0:6bf4ee8ee342 29 #define NUM_PAT_A 0xee
morecat_lab 0:6bf4ee8ee342 30 #define NUM_PAT_B 0x3e
morecat_lab 0:6bf4ee8ee342 31 #define NUM_PAT_C 0x9c
morecat_lab 0:6bf4ee8ee342 32 #define NUM_PAT_D 0x7a
morecat_lab 0:6bf4ee8ee342 33 #define NUM_PAT_E 0x9e
morecat_lab 0:6bf4ee8ee342 34 #define NUM_PAT_F 0x8e
morecat_lab 0:6bf4ee8ee342 35
morecat_lab 0:6bf4ee8ee342 36 class Sseg
morecat_lab 0:6bf4ee8ee342 37 {
morecat_lab 0:6bf4ee8ee342 38 private:
morecat_lab 0:6bf4ee8ee342 39 unsigned long _lastUpdateTime;
morecat_lab 0:6bf4ee8ee342 40 int _updateInterval;
morecat_lab 0:6bf4ee8ee342 41 BusOut _segPins;
morecat_lab 0:6bf4ee8ee342 42 BusOut _digPins;
morecat_lab 0:6bf4ee8ee342 43 char _buffer[8];
morecat_lab 0:6bf4ee8ee342 44 int _numOfDigs;
morecat_lab 0:6bf4ee8ee342 45 int _dig; // support 4 or 8
morecat_lab 0:6bf4ee8ee342 46 bool _zeroSupress;
morecat_lab 0:6bf4ee8ee342 47 bool _kcommon; // Cathode-common flag
morecat_lab 0:6bf4ee8ee342 48 void initConv(void);
morecat_lab 0:6bf4ee8ee342 49 Timer timer;
morecat_lab 0:6bf4ee8ee342 50 public:
morecat_lab 0:6bf4ee8ee342 51 static const int numConv[16];
morecat_lab 0:6bf4ee8ee342 52 // 2 digit
morecat_lab 0:6bf4ee8ee342 53 Sseg(PinName a,PinName b,PinName c,PinName d,
morecat_lab 0:6bf4ee8ee342 54 PinName e,PinName f,PinName g,PinName dp,
morecat_lab 0:6bf4ee8ee342 55 PinName d1,PinName d2);
morecat_lab 0:6bf4ee8ee342 56
morecat_lab 0:6bf4ee8ee342 57 // 4 digit
morecat_lab 0:6bf4ee8ee342 58 Sseg(PinName a,PinName b,PinName c,PinName d,
morecat_lab 0:6bf4ee8ee342 59 PinName e,PinName f,PinName g,PinName dp,
morecat_lab 0:6bf4ee8ee342 60 PinName d1,PinName d2, PinName d3, PinName d4);
morecat_lab 0:6bf4ee8ee342 61
morecat_lab 0:6bf4ee8ee342 62 // 8 digit
morecat_lab 0:6bf4ee8ee342 63 Sseg(PinName a,PinName b,PinName c,PinName d,
morecat_lab 0:6bf4ee8ee342 64 PinName e,PinName f,PinName g,PinName dp,
morecat_lab 0:6bf4ee8ee342 65 PinName d1,PinName d2, PinName d3, PinName d4,
morecat_lab 0:6bf4ee8ee342 66 PinName d5,PinName d6, PinName d7, PinName d8);
morecat_lab 0:6bf4ee8ee342 67
morecat_lab 0:6bf4ee8ee342 68 void begin(void);
morecat_lab 0:6bf4ee8ee342 69 void setKcommon(void);
morecat_lab 0:6bf4ee8ee342 70 void setAcommon(void);
morecat_lab 0:6bf4ee8ee342 71 char segCh(char i);
morecat_lab 0:6bf4ee8ee342 72 void setDot(int d);
morecat_lab 0:6bf4ee8ee342 73 void clearDot(int d);
morecat_lab 0:6bf4ee8ee342 74 void writeNum(int n);
morecat_lab 0:6bf4ee8ee342 75 void writeNum2(int n);
morecat_lab 0:6bf4ee8ee342 76 void writeNum4(int n);
morecat_lab 0:6bf4ee8ee342 77 void writeNum8(int n);
morecat_lab 0:6bf4ee8ee342 78 void writeNum(char d1, char d2);
morecat_lab 0:6bf4ee8ee342 79 void writeNum(char d1, char d2, char d3, char d4);
morecat_lab 0:6bf4ee8ee342 80 void writeNum(char d1, char d2, char d3, char d4, char d5, char d6, char d7, char d8);
morecat_lab 0:6bf4ee8ee342 81 void supressZero();
morecat_lab 0:6bf4ee8ee342 82 void setZeroSupress(bool t);
morecat_lab 0:6bf4ee8ee342 83 void writeHex(int n);
morecat_lab 0:6bf4ee8ee342 84 void writeHex(long n);
morecat_lab 0:6bf4ee8ee342 85 void writeRawData(char d1, char d2);
morecat_lab 0:6bf4ee8ee342 86 void writeRawData(char d1, char d2, char d3, char d4);
morecat_lab 0:6bf4ee8ee342 87 void writeRawData(char d1, char d2, char d3, char d4, char d5, char d6, char d7, char d8);
morecat_lab 0:6bf4ee8ee342 88 void write(uint8_t x, uint8_t y, uint8_t value);
morecat_lab 0:6bf4ee8ee342 89 void write(uint8_t y, uint8_t value);
morecat_lab 0:6bf4ee8ee342 90 void write(uint8_t y, const uint8_t values[], uint8_t size);
morecat_lab 0:6bf4ee8ee342 91 void clear(void);
morecat_lab 0:6bf4ee8ee342 92 void turnOff(void);
morecat_lab 0:6bf4ee8ee342 93 void turnOn(void);
morecat_lab 0:6bf4ee8ee342 94 void updateSeg(void);
morecat_lab 0:6bf4ee8ee342 95 bool update(void);
morecat_lab 0:6bf4ee8ee342 96 void updateWithDelay(int ms);
morecat_lab 0:6bf4ee8ee342 97 void updateOnce(void);
morecat_lab 0:6bf4ee8ee342 98 };
morecat_lab 0:6bf4ee8ee342 99
morecat_lab 0:6bf4ee8ee342 100 #endif // SSEG.h