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

Dependents:   7segMbed

Revision:
0:6bf4ee8ee342
Child:
1:12daa491059c
diff -r 000000000000 -r 6bf4ee8ee342 Sseg.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Sseg.h	Sun Oct 20 05:59:40 2013 +0000
@@ -0,0 +1,100 @@
+/*
+  SSeg.cpp - mbed library for 7seg 4digit/8digit LED matrix.
+  Copyright 2013 morecat_lab
+ 
+  base on Dots library.
+  Copyright 2010 arms22. All right reserved.
+  
+  This library is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
+*/
+
+#ifndef SSEG_H
+#define SSEG_H
+
+#include "mbed.h"
+#include <Timer.h>
+
+#define NUM_PAT_0 0xfc
+#define NUM_PAT_1 0x60
+#define NUM_PAT_2 0xda
+#define NUM_PAT_3 0xf2
+#define NUM_PAT_4 0x66
+#define NUM_PAT_5 0xb6
+#define NUM_PAT_6 0xbe
+#define NUM_PAT_7 0xe0
+#define NUM_PAT_8 0xfe
+#define NUM_PAT_9 0xf6
+#define NUM_PAT_A 0xee
+#define NUM_PAT_B 0x3e
+#define NUM_PAT_C 0x9c
+#define NUM_PAT_D 0x7a
+#define NUM_PAT_E 0x9e
+#define NUM_PAT_F 0x8e
+
+class Sseg
+{
+private:
+    unsigned long _lastUpdateTime;
+    int _updateInterval;
+    BusOut _segPins;
+    BusOut _digPins;
+    char _buffer[8];
+    int _numOfDigs;
+    int _dig;       // support 4 or 8
+    bool _zeroSupress;
+    bool _kcommon;  // Cathode-common flag
+    void initConv(void);
+    Timer timer;
+public:
+    static const int numConv[16];
+    // 2 digit
+    Sseg(PinName a,PinName b,PinName c,PinName d,
+         PinName e,PinName f,PinName g,PinName dp,
+         PinName d1,PinName d2);
+
+    // 4 digit
+    Sseg(PinName a,PinName b,PinName c,PinName d,
+         PinName e,PinName f,PinName g,PinName dp,
+         PinName d1,PinName d2, PinName d3, PinName d4);
+
+    // 8 digit
+    Sseg(PinName a,PinName b,PinName c,PinName d,
+         PinName e,PinName f,PinName g,PinName dp,
+         PinName d1,PinName d2, PinName d3, PinName d4,
+         PinName d5,PinName d6, PinName d7, PinName d8);
+    
+    void begin(void);
+    void setKcommon(void);
+    void setAcommon(void);
+    char segCh(char i);
+    void setDot(int d);
+    void clearDot(int d);
+    void writeNum(int n);
+    void writeNum2(int n);
+    void writeNum4(int n);
+    void writeNum8(int n);
+    void writeNum(char d1, char d2);
+    void writeNum(char d1, char d2, char d3, char d4);
+    void writeNum(char d1, char d2, char d3, char d4, char d5, char d6, char d7, char d8);
+    void supressZero();
+    void setZeroSupress(bool t);
+    void writeHex(int n);
+    void writeHex(long n);
+    void writeRawData(char d1, char d2);
+    void writeRawData(char d1, char d2, char d3, char d4);
+    void writeRawData(char d1, char d2, char d3, char d4, char d5, char d6, char d7, char d8);
+    void write(uint8_t x, uint8_t y, uint8_t value);
+    void write(uint8_t y, uint8_t value);
+    void write(uint8_t y, const uint8_t values[], uint8_t size);
+    void clear(void);
+    void turnOff(void);
+    void turnOn(void);
+    void updateSeg(void);
+    bool update(void);
+    void updateWithDelay(int ms);
+    void updateOnce(void);
+};
+
+#endif  // SSEG.h