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.
Spi7Seg.h
00001 /* 00002 SpiLED.h - mbed library for Serial seven segment LED driver. 00003 This library is for Serial-in pararel-out shift register (HC595) and 7 Segiemnt LED module 00004 Copyright 20145 by morecat_lab 00005 00006 This library is distributed in the hope that it will be useful, 00007 but WITHOUT ANY WARRANTY; without even the implied warranty of 00008 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 00009 */ 00010 00011 #ifndef SPI7SEG_H 00012 #define SPI7SEG_H 00013 00014 #include <Timer.h> 00015 #include "mbed.h" 00016 00017 // LED PIN ASSIGN 00018 // 00019 // P G F E D C B A 00020 // 00021 // A 00022 // -- 00023 // F|__|B 00024 // E|G |C 00025 // -- .P 00026 // D 00027 00028 #define NUM_PAT_0 0xc0 00029 #define NUM_PAT_1 0xf9 00030 #define NUM_PAT_2 0xa4 00031 #define NUM_PAT_3 0xb0 00032 #define NUM_PAT_4 0x99 00033 #define NUM_PAT_5 0x92 00034 #define NUM_PAT_6 0x82 00035 #define NUM_PAT_7 0xf8 00036 #define NUM_PAT_8 0x80 00037 #define NUM_PAT_9 0x90 00038 #define NUM_PAT_A 0x88 00039 #define NUM_PAT_B 0x83 00040 #define NUM_PAT_C 0xc6 00041 #define NUM_PAT_D 0xa1 00042 #define NUM_PAT_E 0x86 00043 #define NUM_PAT_F 0x8e 00044 00045 /** 00046 * Spi Seven segment LED driver library (8 digit) 00047 */ 00048 class Spi7Seg 00049 { 00050 private: 00051 DigitalOut _dataPin, _clockPin, _latchPin; 00052 char _buffer[8]; 00053 int _numOfDigs; 00054 bool _zeroSupress; 00055 Timer timer; 00056 public: 00057 static const int numConv[16]; 00058 /** 00059 * create an 8 digit SPI driven seven segment driver 00060 * 00061 * @param PinName a Pin No for segment data 00062 * @param PinName b Pin No for segment clock 00063 * @param PinName c Pin No for segment latch 00064 */ 00065 Spi7Seg(PinName data,PinName clock,PinName latch); 00066 00067 /** 00068 * start driver 00069 */ 00070 void begin(void); 00071 00072 /** 00073 * get a charcter pattern from a number 00074 * 00075 * @param i number 00076 * 00077 * @returns bit pattern of number i 00078 * 00079 */ 00080 char segCh(char i); 00081 00082 /** 00083 * turn on DP 00084 * 00085 * @param d dight 00086 * 00087 */ 00088 void setDot(int d); 00089 00090 /** 00091 * turn off DP 00092 * 00093 * @param d dight 00094 * 00095 */ 00096 void clearDot(int d); 00097 00098 /** 00099 * write a number to LED 00100 * 00101 * @param n number 00102 * 00103 */ 00104 void writeNum(long n); 00105 00106 /** 00107 * write numbers to each dight of 8 dight LED 00108 * 00109 * @param d1 digit 1 number 00110 * @param d2 digit 2 number 00111 * @param d3 digit 3 number 00112 * @param d4 digit 4 number 00113 * @param d5 digit 5 number 00114 * @param d6 digit 6 number 00115 * @param d7 digit 7 number 00116 * @param d8 digit 8 number 00117 * 00118 */ 00119 void writeNum(char d1, char d2, char d3, char d4, char d5, char d6, char d7, char d8); 00120 00121 /** 00122 * zero supress: tell driver not to display 0 in the left 00123 * 00124 */ 00125 void supressZero(); 00126 00127 /** 00128 * control zero supress bit 00129 * 00130 * @param t, 1:supress on, 0:supress off 00131 * 00132 */ 00133 void setZeroSupress(bool t); 00134 00135 /** 00136 * write hex number to LED 00137 * 00138 * @param n (long)number 00139 * 00140 */ 00141 void writeHex(long n); 00142 00143 /** 00144 * write patterns to each dight of 8 dight LED 00145 * 00146 * @param d1 digit 1 pattern 00147 * @param d2 digit 2 pattern 00148 * @param d3 digit 3 pattern 00149 * @param d4 digit 4 pattern 00150 * @param d5 digit 5 pattern 00151 * @param d6 digit 6 pattern 00152 * @param d7 digit 7 pattern 00153 * @param d8 digit 8 pattern 00154 * 00155 */ 00156 void writeRawData(char d1, char d2, char d3, char d4, char d5, char d6, char d7, char d8); 00157 00158 void write(uint8_t x, uint8_t y, uint8_t value); 00159 00160 /** 00161 * write patterns to a dight 00162 * 00163 * @param d digit 00164 * 00165 * @param value pattern 00166 * 00167 */ 00168 void write(uint8_t d, uint8_t value); 00169 00170 /** 00171 * Clear LED buffer 00172 */ 00173 void clear(void); 00174 00175 /** 00176 * Update LED (by internal clock) 00177 * 00178 * @returns sync = 1, if digit == 0 00179 * 00180 */ 00181 void update(void); 00182 00183 /** 00184 * keep updating LED for specified period 00185 * 00186 * @param ms period (ms) 00187 * 00188 */ 00189 void updateWithDelay(int ms); 00190 00191 }; 00192 00193 #endif // SPI7SEG.h
Generated on Tue Jul 12 2022 22:47:11 by
1.7.2