Alphanumeric LED display, 8 digits, 5x7 pattern. Supports 8x1, 8x2, 16x1 and 16x2 display configuration.

Dependents:   mbed_HCMS2975

Alphanumeric LED display, 8 digits, 5x7 LED pattern. The device has SPI interface. The library supports multiple devices connected in a daisy chain. This provides a 8x1, 8x2, 16x1 and 16x2 display configuration.The library methods are similar to those used for the LCDText library.

/media/uploads/wim/hcms2975.jpg

These displays are from mid 80s to mid 90s and they look cool, but they are rather expensive ($100 a piece..). The lib was developed and tested with displays salvaged from some equipment. You see them mostly in HP printers, medical equipment etc.

Some info can be found here and here.

Datasheet is here

Committer:
wim
Date:
Mon Jan 05 20:37:06 2015 +0000
Revision:
1:f46d90374eb2
Parent:
0:a332431006fb
Fixed setBrightness() at init()

Who changed what in which revision?

UserRevisionLine numberNew contents of line
wim 0:a332431006fb 1 /**
wim 0:a332431006fb 2 * @file HCMS2975.h
wim 0:a332431006fb 3 * @brief mbed Avago/HP HCSM2975 LED matrix display Library.
wim 0:a332431006fb 4 * @author WH
wim 0:a332431006fb 5 * @date Copyright (c) 2014
wim 0:a332431006fb 6 * v01: WH, Initial release,
wim 0:a332431006fb 7 * Info available at http://playground.arduino.cc/Main/LedDisplay and http://www.pjrc.com/teensy/td_libs_LedDisplay.html
wim 1:f46d90374eb2 8 * v02: WH, added getVersion(),
wim 1:f46d90374eb2 9 * v03: WH, fixed setBrightness at init() when there is no HW reset.
wim 0:a332431006fb 10 *
wim 0:a332431006fb 11 * Permission is hereby granted, free of charge, to any person obtaining a copy
wim 0:a332431006fb 12 * of this software and associated documentation files (the "Software"), to deal
wim 0:a332431006fb 13 * in the Software without restriction, including without limitation the rights
wim 0:a332431006fb 14 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
wim 0:a332431006fb 15 * copies of the Software, and to permit persons to whom the Software is
wim 0:a332431006fb 16 * furnished to do so, subject to the following conditions:
wim 0:a332431006fb 17 *
wim 0:a332431006fb 18 * The above copyright notice and this permission notice shall be included in
wim 0:a332431006fb 19 * all copies or substantial portions of the Software.
wim 0:a332431006fb 20 *
wim 0:a332431006fb 21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
wim 0:a332431006fb 22 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
wim 0:a332431006fb 23 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
wim 0:a332431006fb 24 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
wim 0:a332431006fb 25 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
wim 0:a332431006fb 26 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
wim 0:a332431006fb 27 * THE SOFTWARE.
wim 0:a332431006fb 28 */
wim 0:a332431006fb 29 #ifndef _HCMS2975_H
wim 0:a332431006fb 30 #define _HCMS2975_H
wim 0:a332431006fb 31
wim 0:a332431006fb 32 #include "mbed.h"
wim 0:a332431006fb 33
wim 0:a332431006fb 34 //Enable Stream printf or minimalistic printf
wim 0:a332431006fb 35 #define HCMS2975_PRINTF 1
wim 0:a332431006fb 36
wim 1:f46d90374eb2 37 #define HCMS2975_VERSION 2
wim 0:a332431006fb 38
wim 0:a332431006fb 39 //Max supported display is 16x2
wim 0:a332431006fb 40 #define HCMS2975_BUFFER_SIZE 32
wim 0:a332431006fb 41 //#define HCMS2975_BUFFER_SIZE 8
wim 0:a332431006fb 42
wim 0:a332431006fb 43 /* LED Type information on Rows and Columns. This information is encoded in
wim 0:a332431006fb 44 * an int and used for the LEDType enumerators in order to simplify code maintenance */
wim 0:a332431006fb 45 // Columns encoded in b7..b0
wim 0:a332431006fb 46 #define LED_T_COL_MSK 0x000000FF
wim 0:a332431006fb 47 #define LED_T_C8 0x00000008
wim 0:a332431006fb 48 #define LED_T_C16 0x00000010
wim 0:a332431006fb 49
wim 0:a332431006fb 50 // Rows encoded in b15..b8
wim 0:a332431006fb 51 #define LED_T_ROW_MSK 0x0000FF00
wim 0:a332431006fb 52 #define LED_T_R1 0x00000100
wim 0:a332431006fb 53 #define LED_T_R2 0x00000200
wim 0:a332431006fb 54 #define LED_T_R3 0x00000300
wim 0:a332431006fb 55 #define LED_T_R4 0x00000400
wim 0:a332431006fb 56
wim 0:a332431006fb 57 /* LED number of devices. This information is encoded in
wim 0:a332431006fb 58 * an int and used for the command and databyte transmission counter in order to simplify code maintenance */
wim 0:a332431006fb 59 // Number of Devices encoded in b23..16
wim 0:a332431006fb 60 #define LED_T_CNT_MSK 0x00FF0000
wim 0:a332431006fb 61 #define LED_T_N1 0x00010000
wim 0:a332431006fb 62 #define LED_T_N2 0x00020000
wim 0:a332431006fb 63 #define LED_T_N4 0x00040000
wim 0:a332431006fb 64
wim 0:a332431006fb 65
wim 0:a332431006fb 66 // Controlword 0
wim 0:a332431006fb 67 #define HCMS2975_CONTROL0 0x00
wim 0:a332431006fb 68
wim 0:a332431006fb 69 // D6 is /Sleep
wim 0:a332431006fb 70 #define HCMS2975_SLP 0x00
wim 0:a332431006fb 71 #define HCMS2975_NORMAL 0x40
wim 0:a332431006fb 72
wim 0:a332431006fb 73 // D4.D5 selects max peak current
wim 0:a332431006fb 74 #define HCMS2975_PEAK_12_8 0x30
wim 1:f46d90374eb2 75 #define HCMS2975_PEAK_9_3 0x00
wim 0:a332431006fb 76 #define HCMS2975_PEAK_6_4 0x10
wim 1:f46d90374eb2 77 #define HCMS2975_PEAK_4_0 0x20
wim 0:a332431006fb 78
wim 0:a332431006fb 79 // display brightness definitions, indicating percentage brightness
wim 0:a332431006fb 80 // D3..D0 select brightness
wim 0:a332431006fb 81 #define HCMS2975_BRIGHT_100 0x0F
wim 0:a332431006fb 82 #define HCMS2975_BRIGHT_80 0x0E
wim 0:a332431006fb 83 #define HCMS2975_BRIGHT_60 0x0D
wim 0:a332431006fb 84 #define HCMS2975_BRIGHT_47 0x0C
wim 0:a332431006fb 85 #define HCMS2975_BRIGHT_37 0x0B
wim 0:a332431006fb 86 #define HCMS2975_BRIGHT_30 0x0A
wim 0:a332431006fb 87 #define HCMS2975_BRIGHT_23 0x09
wim 0:a332431006fb 88 #define HCMS2975_BRIGHT_18 0x08
wim 0:a332431006fb 89 #define HCMS2975_BRIGHT_15 0x07
wim 0:a332431006fb 90 #define HCMS2975_BRIGHT_11_7 0x06
wim 0:a332431006fb 91 #define HCMS2975_BRIGHT_8_3 0x05
wim 0:a332431006fb 92 #define HCMS2975_BRIGHT_6_7 0x04
wim 0:a332431006fb 93 #define HCMS2975_BRIGHT_5 0x03
wim 0:a332431006fb 94 #define HCMS2975_BRIGHT_3_3 0x02
wim 0:a332431006fb 95 #define HCMS2975_BRIGHT_1_7 0x01
wim 0:a332431006fb 96 #define HCMS2975_BRIGHT_0 0x00
wim 0:a332431006fb 97
wim 0:a332431006fb 98 // default display brightness
wim 0:a332431006fb 99 #define HCMS2975_DEF_BRIGHT HCMS2975_BRIGHT_30
wim 0:a332431006fb 100 #define HCMS2975_DEF_PEAK HCMS2975_PEAK_6_4
wim 0:a332431006fb 101
wim 0:a332431006fb 102 // Controlword 1
wim 0:a332431006fb 103 #define HCMS2975_CONTROL1 0x80
wim 0:a332431006fb 104
wim 0:a332431006fb 105 //Select Prescaler mode
wim 0:a332431006fb 106 #define HCMS2975_PRE_1 0x00
wim 0:a332431006fb 107 #define HCMS2975_PRE_8 0x02
wim 0:a332431006fb 108
wim 0:a332431006fb 109 //Select Serial/Simultaneous mode
wim 0:a332431006fb 110 #define HCMS2975_SERIAL 0x00
wim 0:a332431006fb 111 #define HCMS2975_SIMUL 0x01
wim 0:a332431006fb 112
wim 0:a332431006fb 113 // Write Digit columns data as 5 sequential bytes.
wim 0:a332431006fb 114 // First byte defines left column. D7 always 0, D6..D0 define bitpattern. D6 is downmost, D0 is topmost pixel.
wim 0:a332431006fb 115 //
wim 0:a332431006fb 116 extern const char udc_0[]; /* |> */
wim 0:a332431006fb 117 extern const char udc_1[]; /* <| */
wim 0:a332431006fb 118 extern const char udc_2[]; /* | */
wim 0:a332431006fb 119 extern const char udc_3[]; /* || */
wim 0:a332431006fb 120 extern const char udc_4[]; /* ||| */
wim 0:a332431006fb 121 extern const char udc_5[]; /* = */
wim 0:a332431006fb 122 extern const char udc_6[]; /* checkerboard */
wim 0:a332431006fb 123 extern const char udc_7[]; /* \ */
wim 0:a332431006fb 124
wim 0:a332431006fb 125 extern const char udc_Bat_Hi[]; /* Battery Full */
wim 0:a332431006fb 126 extern const char udc_Bat_Ha[]; /* Battery Half */
wim 0:a332431006fb 127 extern const char udc_Bat_Lo[]; /* Battery Low */
wim 0:a332431006fb 128 extern const char udc_AC[]; /* AC Power */
wim 0:a332431006fb 129 extern const char udc_smiley[]; /* Smiley */
wim 0:a332431006fb 130
wim 0:a332431006fb 131 /** A library for driving HCMS2975 LED matrix displays
wim 0:a332431006fb 132 * @brief Currently supports 8x1, 8x2, 16x1, 16x2
wim 0:a332431006fb 133 *
wim 0:a332431006fb 134 *
wim 0:a332431006fb 135 * @code
wim 0:a332431006fb 136 * #include "mbed.h"
wim 0:a332431006fb 137 * #include "HCMS2975.h"
wim 0:a332431006fb 138 *
wim 0:a332431006fb 139 * // SPI Communication
wim 0:a332431006fb 140 * SPI spi_led(p5, NC, p7); // MOSI, MISO, SCLK
wim 0:a332431006fb 141 *
wim 0:a332431006fb 142 * //Display
wim 0:a332431006fb 143 * HCMS2975 led(&spi_led, p8, p9, p10); // SPI bus, CS pin, RS pin, Rst pin, LEDType = default
wim 0:a332431006fb 144 *
wim 0:a332431006fb 145 * int main() {
wim 0:a332431006fb 146 * int cnt;
wim 0:a332431006fb 147 *
wim 0:a332431006fb 148 * led.locate(0, 0);
wim 0:a332431006fb 149 *
wim 0:a332431006fb 150 * // 12345678
wim 0:a332431006fb 151 * led.printf("Hi mbed ");
wim 0:a332431006fb 152 * wait(2);
wim 0:a332431006fb 153 *
wim 0:a332431006fb 154 * cnt=0x20;
wim 0:a332431006fb 155 * while(1) {
wim 0:a332431006fb 156 * wait(0.5);
wim 0:a332431006fb 157 *
wim 0:a332431006fb 158 * led.putc(cnt);
wim 0:a332431006fb 159 * cnt++;
wim 0:a332431006fb 160 * if (cnt == 0x80) cnt=0x20;
wim 0:a332431006fb 161 * }
wim 0:a332431006fb 162 * }
wim 0:a332431006fb 163 * @endcode
wim 0:a332431006fb 164 */
wim 0:a332431006fb 165
wim 0:a332431006fb 166
wim 0:a332431006fb 167 /** Create an HCMS2975 Display object connected to the proper pins
wim 0:a332431006fb 168 *
wim 0:a332431006fb 169 * @param *spi SPI port
wim 0:a332431006fb 170 * @param cs PinName for Chip Select (active low)
wim 0:a332431006fb 171 * @param rs PinName for RS (Data = low, Command = High)
wim 0:a332431006fb 172 * @param rst PinName for Rst (active low, optional, default=NC)
wim 0:a332431006fb 173 * @param type Sets the panel size (default = LED8x1)
wim 0:a332431006fb 174 */
wim 0:a332431006fb 175 class HCMS2975 : public Stream {
wim 0:a332431006fb 176 //class HCMS2975 {
wim 0:a332431006fb 177
wim 0:a332431006fb 178 //Unfortunately this #define selection breaks Doxygen !!!
wim 0:a332431006fb 179 //#if (HCMS2975_PRINTF == 1)
wim 0:a332431006fb 180 //class HCMS2975 : public Stream {
wim 0:a332431006fb 181 //#else
wim 0:a332431006fb 182 //class HCMS2975 {
wim 0:a332431006fb 183 //#endif
wim 0:a332431006fb 184
wim 0:a332431006fb 185 public:
wim 0:a332431006fb 186 /** LED panel format */
wim 0:a332431006fb 187 enum LEDType {
wim 0:a332431006fb 188 LED8x1 = (LED_T_N1 | LED_T_C8 | LED_T_R1), /**< 8x1 LED panel (default) */
wim 0:a332431006fb 189 LED8x2 = (LED_T_N2 | LED_T_C8 | LED_T_R2), /**< 8x2 LED panel */
wim 0:a332431006fb 190 LED16x1 = (LED_T_N2 | LED_T_C16 | LED_T_R1), /**< 16x1 LED panel */
wim 0:a332431006fb 191 LED16x2 = (LED_T_N4 | LED_T_C16 | LED_T_R2), /**< 16x2 LED panel */
wim 0:a332431006fb 192 };
wim 0:a332431006fb 193
wim 0:a332431006fb 194 /** Display control */
wim 0:a332431006fb 195 enum DisplayMode {
wim 0:a332431006fb 196 DispOff, /**< Display Off */
wim 0:a332431006fb 197 DispOn /**< Display On */
wim 0:a332431006fb 198 };
wim 0:a332431006fb 199
wim 0:a332431006fb 200 /** Create an HCMS2975 Display object connected to the proper pins
wim 0:a332431006fb 201 *
wim 0:a332431006fb 202 * @param *spi SPI port
wim 0:a332431006fb 203 * @param cs PinName for Chip Select (active low)
wim 0:a332431006fb 204 * @param rs PinName for RS ()
wim 1:f46d90374eb2 205 * @param rst PinName for Rst (active low, optional, default = NC)
wim 0:a332431006fb 206 * @param type Sets the panel size (default = LED8x1)
wim 0:a332431006fb 207 */
wim 0:a332431006fb 208 HCMS2975(SPI *spi, PinName cs, PinName rs, PinName rst = NC, LEDType type = LED8x1);
wim 0:a332431006fb 209
wim 0:a332431006fb 210
wim 0:a332431006fb 211 /** Destructor for HCMS2975 Display object
wim 0:a332431006fb 212 *
wim 0:a332431006fb 213 * @param none
wim 0:a332431006fb 214 * @return none
wim 0:a332431006fb 215 */
wim 0:a332431006fb 216 virtual ~HCMS2975();
wim 0:a332431006fb 217
wim 0:a332431006fb 218 #if (HCMS2975_PRINTF != 1)
wim 0:a332431006fb 219 /** Write a character to the Display
wim 0:a332431006fb 220 *
wim 0:a332431006fb 221 * @param c The character to write to the display
wim 0:a332431006fb 222 */
wim 0:a332431006fb 223 int putc(int c);
wim 0:a332431006fb 224
wim 0:a332431006fb 225 /** Write a raw string to the Display
wim 0:a332431006fb 226 *
wim 0:a332431006fb 227 * @param string text, may be followed by variables to emulate formatting the string.
wim 0:a332431006fb 228 * However, when (HCMS2975_PRINTF != 1) then printf formatting is NOT supported and variables will be ignored!
wim 0:a332431006fb 229 */
wim 0:a332431006fb 230 int printf(const char* text, ...);
wim 0:a332431006fb 231 #else
wim 0:a332431006fb 232 #if DOXYGEN_ONLY
wim 0:a332431006fb 233 /** Write a character to the Display
wim 0:a332431006fb 234 *
wim 0:a332431006fb 235 * @param c The character to write to the display
wim 0:a332431006fb 236 */
wim 0:a332431006fb 237 int putc(int c);
wim 0:a332431006fb 238
wim 0:a332431006fb 239 /** Write a formatted string to the Display
wim 0:a332431006fb 240 *
wim 0:a332431006fb 241 * @param format A printf-style format string, followed by the
wim 0:a332431006fb 242 * variables to use in formatting the string.
wim 0:a332431006fb 243 */
wim 0:a332431006fb 244 int printf(const char* format, ...);
wim 0:a332431006fb 245 #endif
wim 0:a332431006fb 246
wim 0:a332431006fb 247 #endif
wim 0:a332431006fb 248
wim 0:a332431006fb 249 /** Clear the screen and locate to 0,0
wim 0:a332431006fb 250 */
wim 0:a332431006fb 251 void cls();
wim 0:a332431006fb 252
wim 0:a332431006fb 253 /** Locate cursor to a screen column and row
wim 0:a332431006fb 254 *
wim 0:a332431006fb 255 * @param column The horizontal position from the left, indexed from 0
wim 0:a332431006fb 256 * @param row The vertical position from the top, indexed from 0
wim 0:a332431006fb 257 */
wim 0:a332431006fb 258 void locate(int column=0, int row=0);
wim 0:a332431006fb 259
wim 0:a332431006fb 260 /** Return the number of columns
wim 0:a332431006fb 261 *
wim 1:f46d90374eb2 262 * @return int The number of columns
wim 0:a332431006fb 263 */
wim 0:a332431006fb 264 int columns();
wim 0:a332431006fb 265
wim 0:a332431006fb 266 /** Return the number of rows
wim 0:a332431006fb 267 *
wim 1:f46d90374eb2 268 * @return int The number of rows
wim 0:a332431006fb 269 */
wim 0:a332431006fb 270 int rows();
wim 0:a332431006fb 271
wim 0:a332431006fb 272 /** Set the Displaymode
wim 0:a332431006fb 273 *
wim 0:a332431006fb 274 * @param displayMode The Display mode (DispOff, DispOn)
wim 0:a332431006fb 275 */
wim 0:a332431006fb 276 void setMode(DisplayMode displayMode);
wim 0:a332431006fb 277
wim 0:a332431006fb 278 /** Set Brightness
wim 0:a332431006fb 279 *
wim 0:a332431006fb 280 * @param brightness The brightness level (valid range 0..15)
wim 0:a332431006fb 281 */
wim 0:a332431006fb 282 void setBrightness(uint8_t brightness = HCMS2975_DEF_BRIGHT);
wim 0:a332431006fb 283
wim 0:a332431006fb 284 /** Set User Defined Characters (UDC)
wim 0:a332431006fb 285 *
wim 0:a332431006fb 286 * @param unsigned char c The Index of the UDC (0..7)
wim 1:f46d90374eb2 287 * @param char *udc_data The bitpatterns for the UDC (5 bytes of 7 significant bits for bitpattern)
wim 0:a332431006fb 288 */
wim 0:a332431006fb 289 void setUDC(unsigned char c, char *udc_data);
wim 0:a332431006fb 290
wim 1:f46d90374eb2 291
wim 0:a332431006fb 292 /** Returns the version number of the library
wim 0:a332431006fb 293 * @return int version number
wim 0:a332431006fb 294 */
wim 0:a332431006fb 295 int getVersion();
wim 0:a332431006fb 296
wim 0:a332431006fb 297 protected:
wim 0:a332431006fb 298 /** Low level Reset method for controller
wim 0:a332431006fb 299 */
wim 0:a332431006fb 300 void _reset();
wim 0:a332431006fb 301
wim 0:a332431006fb 302 /** Low level Init method for LED controller
wim 0:a332431006fb 303 */
wim 0:a332431006fb 304 void _init();
wim 0:a332431006fb 305
wim 0:a332431006fb 306 /** Low level command byte write operation.
wim 0:a332431006fb 307 * @param command commandbyte to write
wim 0:a332431006fb 308 */
wim 0:a332431006fb 309 void _writeCommand(uint8_t command);
wim 0:a332431006fb 310
wim 0:a332431006fb 311 /** Low level _dataBuffer write operation.
wim 0:a332431006fb 312 */
wim 0:a332431006fb 313 void _pushBuffer();
wim 0:a332431006fb 314
wim 0:a332431006fb 315 // Stream implementation functions
wim 0:a332431006fb 316 virtual int _putc(int value);
wim 0:a332431006fb 317 virtual int _getc();
wim 0:a332431006fb 318
wim 0:a332431006fb 319 //SPI bus
wim 0:a332431006fb 320 SPI *_spi;
wim 0:a332431006fb 321 DigitalOut _cs;
wim 0:a332431006fb 322
wim 0:a332431006fb 323 DigitalOut _rs;
wim 0:a332431006fb 324 DigitalOut *_rst;
wim 0:a332431006fb 325
wim 0:a332431006fb 326 //Display type
wim 0:a332431006fb 327 LEDType _type;
wim 0:a332431006fb 328 int _nr_cols;
wim 0:a332431006fb 329 int _nr_rows;
wim 0:a332431006fb 330
wim 0:a332431006fb 331 int _row;
wim 0:a332431006fb 332 int _column;
wim 0:a332431006fb 333 int _peak, _brightness;
wim 0:a332431006fb 334
wim 0:a332431006fb 335 // _displayBuffer
wim 0:a332431006fb 336 char _displayBuffer[HCMS2975_BUFFER_SIZE];
wim 0:a332431006fb 337 int _displaySize;
wim 0:a332431006fb 338 int _deviceCount;
wim 0:a332431006fb 339
wim 0:a332431006fb 340 // Local UDC memory
wim 0:a332431006fb 341 char _udc[8][5];
wim 0:a332431006fb 342 };
wim 0:a332431006fb 343
wim 0:a332431006fb 344
wim 0:a332431006fb 345 #endif