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:
Wed Oct 15 16:46:12 2014 +0000
Revision:
0:a332431006fb
Child:
1:f46d90374eb2
Alphanumeric LED display, 8 digits, 5x7 pattern. Initial library release. Supports 8x1, 8x2, 16x1 and 16x2 display configuration.

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