Libraries and Example of mbed parallel bus using I2C port expanders

Dependencies:   HDSP253X mbed PCF8574_Bus

Committer:
wim
Date:
Sat Sep 17 15:35:39 2011 +0000
Revision:
1:e180256ba6fb
Example of using the parallel bus to control a smart alphanumeric display

Who changed what in which revision?

UserRevisionLine numberNew contents of line
wim 1:e180256ba6fb 1 /* HDSP253X_Display - Intelligent 8 digit 5x7 LED matrix display
wim 1:e180256ba6fb 2 *
wim 1:e180256ba6fb 3 * Copyright (c) 2011 Wim Huiskamp
wim 1:e180256ba6fb 4 * Modified software based on sourcecode by RAC 06/08/2008
wim 1:e180256ba6fb 5 *
wim 1:e180256ba6fb 6 * Released under the MIT License: http://mbed.org/license/mit
wim 1:e180256ba6fb 7 *
wim 1:e180256ba6fb 8 * version 0.2 Initial Release
wim 1:e180256ba6fb 9 */
wim 1:e180256ba6fb 10 #include "mbed.h"
wim 1:e180256ba6fb 11 //#include "Utils.h"
wim 1:e180256ba6fb 12 #include "PCF8574_DataBus.h"
wim 1:e180256ba6fb 13 #include "PCF8574_AddressBus.h"
wim 1:e180256ba6fb 14 #include "PCF8574_EnableBus.h"
wim 1:e180256ba6fb 15 #include "MBED_ControlBus.h"
wim 1:e180256ba6fb 16 #include "HDSP253X_Display.h"
wim 1:e180256ba6fb 17
wim 1:e180256ba6fb 18 /** Create an HDSP253X_Display object connected to the proper busses
wim 1:e180256ba6fb 19 *
wim 1:e180256ba6fb 20 * @param PCF8574_DataBus data databus to connect to
wim 1:e180256ba6fb 21 * @param PCF8574_AddressBus address addressbus to connect to
wim 1:e180256ba6fb 22 * @param PCF8574_EnableBus enable enablebus to connect to
wim 1:e180256ba6fb 23 * @param MBED_ControlBus control controlbus to connect to
wim 1:e180256ba6fb 24 */
wim 1:e180256ba6fb 25 HDSP253X_Display::HDSP253X_Display (PCF8574_DataBus &databus, PCF8574_AddressBus &addressbus, PCF8574_EnableBus &enablebus, MBED_ControlBus &controlbus) :
wim 1:e180256ba6fb 26 _databus(databus), _addressbus(addressbus), _enablebus(enablebus), _controlbus(controlbus) {
wim 1:e180256ba6fb 27
wim 1:e180256ba6fb 28 _init();
wim 1:e180256ba6fb 29 }
wim 1:e180256ba6fb 30
wim 1:e180256ba6fb 31 /** Init HDSP253X_Display
wim 1:e180256ba6fb 32 * @param
wim 1:e180256ba6fb 33 * @returns
wim 1:e180256ba6fb 34 */
wim 1:e180256ba6fb 35 void HDSP253X_Display::_init(void)
wim 1:e180256ba6fb 36 {
wim 1:e180256ba6fb 37 // Apply reset
wim 1:e180256ba6fb 38 reset(); // Note that this also resets the LED status display.
wim 1:e180256ba6fb 39
wim 1:e180256ba6fb 40 // Note: Brightness is 100% after reset
wim 1:e180256ba6fb 41 set_brightness(HDSP253X_DEF_DISPLAY_BRIGHT);
wim 1:e180256ba6fb 42
wim 1:e180256ba6fb 43 // Reset cursor
wim 1:e180256ba6fb 44 locate(0);
wim 1:e180256ba6fb 45 }
wim 1:e180256ba6fb 46
wim 1:e180256ba6fb 47
wim 1:e180256ba6fb 48 /*****************************************************************************/
wim 1:e180256ba6fb 49 /******************* LOW LEVEL HDSP253X SUPPORT FUNCTIONS ******************/
wim 1:e180256ba6fb 50 /*****************************************************************************/
wim 1:e180256ba6fb 51
wim 1:e180256ba6fb 52 /*---------------------------------------------------------------------------*\
wim 1:e180256ba6fb 53 |
wim 1:e180256ba6fb 54 | Function: HDSP253X_reset
wim 1:e180256ba6fb 55 |
wim 1:e180256ba6fb 56 | Description: Reset routine for HDSP253X display, applying reset,
wim 1:e180256ba6fb 57 | removing reset, then waiting for preset delay.
wim 1:e180256ba6fb 58 | With the internal clock, the delay should be around 1
wim 1:e180256ba6fb 59 | millisecond, but slower clocks will require longer delays.
wim 1:e180256ba6fb 60 | After reset the Char RAM and Flash RAM is cleared, the CTRL word is
wim 1:e180256ba6fb 61 | cleared (Blink Off, Flash Off, Brightness 100%). UDC RAM and address
wim 1:e180256ba6fb 62 | are unaffected.
wim 1:e180256ba6fb 63 |
wim 1:e180256ba6fb 64 | Parameters: None
wim 1:e180256ba6fb 65 |
wim 1:e180256ba6fb 66 | Returns: Nothing.
wim 1:e180256ba6fb 67 |
wim 1:e180256ba6fb 68 \*---------------------------------------------------------------------------*/
wim 1:e180256ba6fb 69 void HDSP253X_Display::reset(void)
wim 1:e180256ba6fb 70 {
wim 1:e180256ba6fb 71 //NOTE: On LF28A the Reset* pin is connected to the display and to the latches.
wim 1:e180256ba6fb 72 // That implies they are all reset when the Reset* pin is used !
wim 1:e180256ba6fb 73 //
wim 1:e180256ba6fb 74 // Alternative for the Display may be SW reset instruction
wim 1:e180256ba6fb 75
wim 1:e180256ba6fb 76 // Apply the reset condition and then remove after short delay
wim 1:e180256ba6fb 77 _enablebus.chipselect(CS_DISP, HIGH);
wim 1:e180256ba6fb 78 wait_ms(HDSP253X_1TCY_WAIT_MS);
wim 1:e180256ba6fb 79
wim 1:e180256ba6fb 80 _enablebus.reset(LOW);
wim 1:e180256ba6fb 81 wait_ms(HDSP253X_1TCY_WAIT_MS);
wim 1:e180256ba6fb 82 wait_ms(HDSP253X_1TCY_WAIT_MS);
wim 1:e180256ba6fb 83 _enablebus.reset(HIGH);
wim 1:e180256ba6fb 84
wim 1:e180256ba6fb 85 // Wait for the preset delay to allow operation to complete
wim 1:e180256ba6fb 86 wait_ms(HDSP253X_RST_CLR_DELAY_MS);
wim 1:e180256ba6fb 87
wim 1:e180256ba6fb 88 // Reset cursor
wim 1:e180256ba6fb 89 locate(0);
wim 1:e180256ba6fb 90 }
wim 1:e180256ba6fb 91
wim 1:e180256ba6fb 92
wim 1:e180256ba6fb 93 /*---------------------------------------------------------------------------*\
wim 1:e180256ba6fb 94 |
wim 1:e180256ba6fb 95 | Function: HDSP253X_write
wim 1:e180256ba6fb 96 |
wim 1:e180256ba6fb 97 | Description: Low level data write routine for HDSP253X. Takes in data
wim 1:e180256ba6fb 98 | and address (including Flash as top bit) and writes
wim 1:e180256ba6fb 99 | it to the display. For simplicity, entire address byte
wim 1:e180256ba6fb 100 | is written, even though top two bits are unused inputs.
wim 1:e180256ba6fb 101 | After performing the operation, address lines are set
wim 1:e180256ba6fb 102 | all high, in order to eliminate current drain through
wim 1:e180256ba6fb 103 | pullup resistors (0.5mA per pin with 10K pullups)
wim 1:e180256ba6fb 104 |
wim 1:e180256ba6fb 105 | Parameters: address - full address in bits 0-5 (bit 5 is flash)
wim 1:e180256ba6fb 106 | data - data byte to write out
wim 1:e180256ba6fb 107 |
wim 1:e180256ba6fb 108 | Returns: Nothing.
wim 1:e180256ba6fb 109 |
wim 1:e180256ba6fb 110 \*---------------------------------------------------------------------------*/
wim 1:e180256ba6fb 111
wim 1:e180256ba6fb 112 void HDSP253X_Display::_write(uint8_t address, uint8_t data)
wim 1:e180256ba6fb 113 {
wim 1:e180256ba6fb 114 // // Switch databus buffer to outputs
wim 1:e180256ba6fb 115 // _controlbus.busdir(WRITE);
wim 1:e180256ba6fb 116 // // Switch databus to outputs
wim 1:e180256ba6fb 117 // _databus.busdir(WRITE);
wim 1:e180256ba6fb 118
wim 1:e180256ba6fb 119
wim 1:e180256ba6fb 120 // Write out the address on to the addressbus and wait
wim 1:e180256ba6fb 121 _addressbus.write(address);
wim 1:e180256ba6fb 122 // wait_ms(HDSP253X_1TCY_WAIT_MS);
wim 1:e180256ba6fb 123
wim 1:e180256ba6fb 124 // Set CE low and wait
wim 1:e180256ba6fb 125 _enablebus.chipselect(CS_DISP, LOW);
wim 1:e180256ba6fb 126 // wait_ms(HDSP253X_1TCY_WAIT_MS);
wim 1:e180256ba6fb 127
wim 1:e180256ba6fb 128 // Write data to the databus
wim 1:e180256ba6fb 129 _databus.write(data);
wim 1:e180256ba6fb 130 // wait_ms(HDSP253X_1TCY_WAIT_MS);
wim 1:e180256ba6fb 131
wim 1:e180256ba6fb 132 // Set WR low, wait, then set high and wait
wim 1:e180256ba6fb 133 _controlbus.WR(LOW);
wim 1:e180256ba6fb 134 // wait_ms(HDSP253X_1TCY_WAIT_MS);
wim 1:e180256ba6fb 135 _controlbus.WR(HIGH);
wim 1:e180256ba6fb 136 // wait_ms(HDSP253X_1TCY_WAIT_MS);
wim 1:e180256ba6fb 137
wim 1:e180256ba6fb 138 // Set CE high and wait
wim 1:e180256ba6fb 139 _enablebus.chipselect(CS_DISP, HIGH);
wim 1:e180256ba6fb 140 // wait_ms(HDSP253X_1TCY_WAIT_MS);
wim 1:e180256ba6fb 141
wim 1:e180256ba6fb 142 // // Switch databus back to inputs
wim 1:e180256ba6fb 143 // _databus.busdir(READ);
wim 1:e180256ba6fb 144 // // Switch databus buffer back to inputs
wim 1:e180256ba6fb 145 // _controlbus.busdir(READ);
wim 1:e180256ba6fb 146
wim 1:e180256ba6fb 147 // // Set address lines all high to minimise power through pullups
wim 1:e180256ba6fb 148 // _addressbus.write(HDSP253X_ADDR_LOW_POWER);
wim 1:e180256ba6fb 149 }
wim 1:e180256ba6fb 150
wim 1:e180256ba6fb 151 /*---------------------------------------------------------------------------*\
wim 1:e180256ba6fb 152 |
wim 1:e180256ba6fb 153 | Function: HDSP253X_read
wim 1:e180256ba6fb 154 |
wim 1:e180256ba6fb 155 | Description: Low level data read routine for HDSP253X. Takes in
wim 1:e180256ba6fb 156 | address (including Flash as top bit) and reads data
wim 1:e180256ba6fb 157 | from the display. For simplicity, entire address byte
wim 1:e180256ba6fb 158 | is written, even though top two bits are unused inputs.
wim 1:e180256ba6fb 159 | After performing the operation, address lines are set
wim 1:e180256ba6fb 160 | all high, in order to eliminate current drain through
wim 1:e180256ba6fb 161 | pullup resistors (0.5mA per pin with 10K pullups)
wim 1:e180256ba6fb 162 |
wim 1:e180256ba6fb 163 | Parameters: address - full address in bits 0-5 (bit 5 is flash)
wim 1:e180256ba6fb 164 |
wim 1:e180256ba6fb 165 | Returns: data - data byte read in (Note that D7 is masked out)
wim 1:e180256ba6fb 166 |
wim 1:e180256ba6fb 167 \*---------------------------------------------------------------------------*/
wim 1:e180256ba6fb 168
wim 1:e180256ba6fb 169 uint8_t HDSP253X_Display::_read(uint8_t address)
wim 1:e180256ba6fb 170 {
wim 1:e180256ba6fb 171 uint8_t data = 0;
wim 1:e180256ba6fb 172
wim 1:e180256ba6fb 173 // Switch databus to inputs
wim 1:e180256ba6fb 174 _databus.busdir(READ);
wim 1:e180256ba6fb 175 // Switch databus buffer to inputs
wim 1:e180256ba6fb 176 _controlbus.busdir(READ);
wim 1:e180256ba6fb 177
wim 1:e180256ba6fb 178 // Write out the address on to the addressbus and wait
wim 1:e180256ba6fb 179 _addressbus.write(address);
wim 1:e180256ba6fb 180 // wait_ms(HDSP253X_1TCY_WAIT_MS);
wim 1:e180256ba6fb 181
wim 1:e180256ba6fb 182 // Set CE low and wait
wim 1:e180256ba6fb 183 _enablebus.chipselect(CS_DISP, LOW);
wim 1:e180256ba6fb 184 // wait_ms(HDSP253X_1TCY_WAIT_MS);
wim 1:e180256ba6fb 185
wim 1:e180256ba6fb 186 // Set RD low and wait
wim 1:e180256ba6fb 187 _controlbus.RD(LOW);
wim 1:e180256ba6fb 188 // wait_ms(HDSP253X_1TCY_WAIT_MS);
wim 1:e180256ba6fb 189
wim 1:e180256ba6fb 190 // Read the data byte from databus
wim 1:e180256ba6fb 191 // Mask out the not-readable D7 bit, this mask is needed for my specific targetboard !
wim 1:e180256ba6fb 192 // Reading the unconnected D7 bit results in 'H' level. A RMW cycle on the Ctrl register
wim 1:e180256ba6fb 193 // would then always result in a Clearscreen !
wim 1:e180256ba6fb 194 data = _databus.read() & HDSP253X_CTRL_MASK;
wim 1:e180256ba6fb 195
wim 1:e180256ba6fb 196 // set RD high and wait
wim 1:e180256ba6fb 197 _controlbus.RD(HIGH);
wim 1:e180256ba6fb 198 // wait_ms(HDSP253X_1TCY_WAIT_MS);
wim 1:e180256ba6fb 199
wim 1:e180256ba6fb 200 // Set CE high and wait
wim 1:e180256ba6fb 201 _enablebus.chipselect(CS_DISP, HIGH);
wim 1:e180256ba6fb 202 // wait_ms(HDSP253X_1TCY_WAIT_MS);
wim 1:e180256ba6fb 203
wim 1:e180256ba6fb 204 // // Set address lines all high to minimise power through pullups
wim 1:e180256ba6fb 205 // _addressbus.write(HDSP253X_ADDR_LOW_POWER);
wim 1:e180256ba6fb 206
wim 1:e180256ba6fb 207 // Switch databus buffer back to outputs
wim 1:e180256ba6fb 208 _controlbus.busdir(WRITE);
wim 1:e180256ba6fb 209 // Switch databus to outputs
wim 1:e180256ba6fb 210 _databus.busdir(WRITE);
wim 1:e180256ba6fb 211
wim 1:e180256ba6fb 212 // Return read data to caller
wim 1:e180256ba6fb 213 return data;
wim 1:e180256ba6fb 214 }
wim 1:e180256ba6fb 215
wim 1:e180256ba6fb 216
wim 1:e180256ba6fb 217 /*****************************************************************************/
wim 1:e180256ba6fb 218 /************** HIGH LEVEL HDSP253X CHARACTER DISPLAY FUNCTIONS ************/
wim 1:e180256ba6fb 219 /*****************************************************************************/
wim 1:e180256ba6fb 220
wim 1:e180256ba6fb 221
wim 1:e180256ba6fb 222 /*---------------------------------------------------------------------------*\
wim 1:e180256ba6fb 223 |
wim 1:e180256ba6fb 224 | Function: HDSP253X_putudc
wim 1:e180256ba6fb 225 |
wim 1:e180256ba6fb 226 | Description: Displays specified UDC character on the display at current
wim 1:e180256ba6fb 227 | position. Used defined characters use codes from 128-142.
wim 1:e180256ba6fb 228 | Note that the normal putc write routines can also be used
wim 1:e180256ba6fb 229 | to show UDCs, using ASCII values 128 to 143 inclusive.
wim 1:e180256ba6fb 230 |
wim 1:e180256ba6fb 231 | Parameters: udc_char_num - UDC character, 16 possible UDC values from 0-15
wim 1:e180256ba6fb 232 |
wim 1:e180256ba6fb 233 | Returns: Nothing
wim 1:e180256ba6fb 234 |
wim 1:e180256ba6fb 235 \*---------------------------------------------------------------------------*/
wim 1:e180256ba6fb 236
wim 1:e180256ba6fb 237 void HDSP253X_Display::putudc (char udc_char_num)
wim 1:e180256ba6fb 238 {
wim 1:e180256ba6fb 239 putc(HDSP253X_ASCII_UDC_CHARS + udc_char_num);
wim 1:e180256ba6fb 240 }
wim 1:e180256ba6fb 241
wim 1:e180256ba6fb 242 /*---------------------------------------------------------------------------*\
wim 1:e180256ba6fb 243 |
wim 1:e180256ba6fb 244 | Function: HDSP253X_printf
wim 1:e180256ba6fb 245 |
wim 1:e180256ba6fb 246 | Description: Displays specified string on the display at current
wim 1:e180256ba6fb 247 | cursor position. Increments cursor.
wim 1:e180256ba6fb 248 |
wim 1:e180256ba6fb 249 | Parameters: format - format string
wim 1:e180256ba6fb 250 | args - data
wim 1:e180256ba6fb 251 |
wim 1:e180256ba6fb 252 | Returns: Nothing
wim 1:e180256ba6fb 253 |
wim 1:e180256ba6fb 254 \*---------------------------------------------------------------------------*/
wim 1:e180256ba6fb 255
wim 1:e180256ba6fb 256 void HDSP253X_Display::printf (char * format, ...) {
wim 1:e180256ba6fb 257 char display_string[64];
wim 1:e180256ba6fb 258 int rv, string_len, i;
wim 1:e180256ba6fb 259 va_list args;
wim 1:e180256ba6fb 260 va_start (args, format);
wim 1:e180256ba6fb 261
wim 1:e180256ba6fb 262 rv=vsprintf (display_string, format, args);
wim 1:e180256ba6fb 263 va_end (args);
wim 1:e180256ba6fb 264 // printf("printing:'%s'\n", display_string);
wim 1:e180256ba6fb 265 // writeString (buffer);
wim 1:e180256ba6fb 266
wim 1:e180256ba6fb 267 // loop round, writing characters
wim 1:e180256ba6fb 268 string_len = strlen(display_string); // obtain length of string
wim 1:e180256ba6fb 269 for (i = 0; i < string_len; i++) {
wim 1:e180256ba6fb 270 putc(display_string[i]);
wim 1:e180256ba6fb 271 };
wim 1:e180256ba6fb 272
wim 1:e180256ba6fb 273 // return rv;
wim 1:e180256ba6fb 274 }
wim 1:e180256ba6fb 275
wim 1:e180256ba6fb 276
wim 1:e180256ba6fb 277
wim 1:e180256ba6fb 278 /*---------------------------------------------------------------------------*\
wim 1:e180256ba6fb 279 |
wim 1:e180256ba6fb 280 | Function: HDSP253X_putc
wim 1:e180256ba6fb 281 |
wim 1:e180256ba6fb 282 | Description: Displays specified character on the display at current
wim 1:e180256ba6fb 283 | cursor position. Increments cursor.
wim 1:e180256ba6fb 284 | Position on the display (0 to 7, Leftmost = 0)
wim 1:e180256ba6fb 285 |
wim 1:e180256ba6fb 286 | Parameters: disp_char - single character to display
wim 1:e180256ba6fb 287 | - ASCII characters, 128 values between 0-127
wim 1:e180256ba6fb 288 | - UDC character, 15 possible UDC values from 128-142
wim 1:e180256ba6fb 289 |
wim 1:e180256ba6fb 290 | Returns: Nothing
wim 1:e180256ba6fb 291 |
wim 1:e180256ba6fb 292 \*---------------------------------------------------------------------------*/
wim 1:e180256ba6fb 293 void HDSP253X_Display::putc(char disp_char) {
wim 1:e180256ba6fb 294
wim 1:e180256ba6fb 295 // Write selected character to display at current position
wim 1:e180256ba6fb 296
wim 1:e180256ba6fb 297 if ((disp_char & HDSP253X_UDC_SEL) == HDSP253X_UDC_SEL) {
wim 1:e180256ba6fb 298 // Write UDC character to display, code between 128-143
wim 1:e180256ba6fb 299 disp_char &= HDSP253X_UDC_MASK; // mask off unused bits
wim 1:e180256ba6fb 300 disp_char |= HDSP253X_UDC_SEL; // add in top bit to specify UDC
wim 1:e180256ba6fb 301 _write(HDSP253X_ADDR_CHAR_BASE + _column, disp_char);
wim 1:e180256ba6fb 302 }
wim 1:e180256ba6fb 303 else {
wim 1:e180256ba6fb 304 // Write ASCII character, code between 0-127
wim 1:e180256ba6fb 305 disp_char &= HDSP253X_CHAR_MASK; // mask off unused bits
wim 1:e180256ba6fb 306 _write(HDSP253X_ADDR_CHAR_BASE + _column, disp_char);
wim 1:e180256ba6fb 307 }
wim 1:e180256ba6fb 308
wim 1:e180256ba6fb 309 // Incr and wrap around cursorposition
wim 1:e180256ba6fb 310 _column++;
wim 1:e180256ba6fb 311 _column = _column % HDSP253X_NUM_CHARS;
wim 1:e180256ba6fb 312 }
wim 1:e180256ba6fb 313
wim 1:e180256ba6fb 314
wim 1:e180256ba6fb 315
wim 1:e180256ba6fb 316 #if(0)
wim 1:e180256ba6fb 317 char HDSP253X_Display::getc() {
wim 1:e180256ba6fb 318 return -1;
wim 1:e180256ba6fb 319 }
wim 1:e180256ba6fb 320 #endif
wim 1:e180256ba6fb 321
wim 1:e180256ba6fb 322 /*---------------------------------------------------------------------------*\
wim 1:e180256ba6fb 323 |
wim 1:e180256ba6fb 324 | Function: HDSP253X_locate
wim 1:e180256ba6fb 325 |
wim 1:e180256ba6fb 326 | Description: Set the cursor address where the next character will be written.
wim 1:e180256ba6fb 327 |
wim 1:e180256ba6fb 328 | Parameters: Cursor Column address
wim 1:e180256ba6fb 329 |
wim 1:e180256ba6fb 330 | Returns: Nothing
wim 1:e180256ba6fb 331 |
wim 1:e180256ba6fb 332 \*---------------------------------------------------------------------------*/
wim 1:e180256ba6fb 333
wim 1:e180256ba6fb 334 void HDSP253X_Display::locate(uint8_t column) {
wim 1:e180256ba6fb 335
wim 1:e180256ba6fb 336 // _row = row % HDSP253X_NUM_ROWS;
wim 1:e180256ba6fb 337 _column = column % HDSP253X_NUM_CHARS;
wim 1:e180256ba6fb 338 }
wim 1:e180256ba6fb 339
wim 1:e180256ba6fb 340
wim 1:e180256ba6fb 341 /*---------------------------------------------------------------------------*\
wim 1:e180256ba6fb 342 |
wim 1:e180256ba6fb 343 | Function: HDSP253X_cls
wim 1:e180256ba6fb 344 |
wim 1:e180256ba6fb 345 | Description: Clears the displayed data and flash RAM, but not the user
wim 1:e180256ba6fb 346 | defined characters. Waits for the preset delay to ensure the
wim 1:e180256ba6fb 347 | display is ready for operation; with an internal clock,
wim 1:e180256ba6fb 348 | this delay needs to be around 1 millisecond.
wim 1:e180256ba6fb 349 |
wim 1:e180256ba6fb 350 | Parameters: None
wim 1:e180256ba6fb 351 |
wim 1:e180256ba6fb 352 | Returns: Nothing
wim 1:e180256ba6fb 353 |
wim 1:e180256ba6fb 354 \*---------------------------------------------------------------------------*/
wim 1:e180256ba6fb 355
wim 1:e180256ba6fb 356 void HDSP253X_Display::cls(void) {
wim 1:e180256ba6fb 357
wim 1:e180256ba6fb 358 uint8_t disp_data;
wim 1:e180256ba6fb 359
wim 1:e180256ba6fb 360 // Read in control word, modify and write back out
wim 1:e180256ba6fb 361 disp_data = _read(HDSP253X_ADDR_CTRL_WORD);
wim 1:e180256ba6fb 362 disp_data |= HDSP253X_CTRL_CLEAR_MASK;
wim 1:e180256ba6fb 363 _write(HDSP253X_ADDR_CTRL_WORD, disp_data);
wim 1:e180256ba6fb 364
wim 1:e180256ba6fb 365 // Wait for the preset delay to allow operation to complete
wim 1:e180256ba6fb 366 wait_ms(HDSP253X_RST_CLR_DELAY_MS);
wim 1:e180256ba6fb 367
wim 1:e180256ba6fb 368 // Reset cursor
wim 1:e180256ba6fb 369 locate(0);
wim 1:e180256ba6fb 370 }
wim 1:e180256ba6fb 371
wim 1:e180256ba6fb 372
wim 1:e180256ba6fb 373 /*---------------------------------------------------------------------------*\
wim 1:e180256ba6fb 374 |
wim 1:e180256ba6fb 375 | Function: HDSP253X_set_brightness
wim 1:e180256ba6fb 376 |
wim 1:e180256ba6fb 377 | Description: Sets the brightness of the HDSP253X display, by performing
wim 1:e180256ba6fb 378 | a read-modify-write on the control register.
wim 1:e180256ba6fb 379 |
wim 1:e180256ba6fb 380 | Parameters: brightness - 3 bit brightness value
wim 1:e180256ba6fb 381 |
wim 1:e180256ba6fb 382 | Returns: Nothing
wim 1:e180256ba6fb 383 |
wim 1:e180256ba6fb 384 \*---------------------------------------------------------------------------*/
wim 1:e180256ba6fb 385
wim 1:e180256ba6fb 386 void HDSP253X_Display::set_brightness(uint8_t brightness) {
wim 1:e180256ba6fb 387
wim 1:e180256ba6fb 388 uint8_t ctrl_data;
wim 1:e180256ba6fb 389
wim 1:e180256ba6fb 390 // Read in control word, modify and write back out
wim 1:e180256ba6fb 391 ctrl_data = _read(HDSP253X_ADDR_CTRL_WORD);
wim 1:e180256ba6fb 392 ctrl_data &= ~HDSP253X_CTRL_BRIGHT_MASK;
wim 1:e180256ba6fb 393 ctrl_data |= (brightness & HDSP253X_CTRL_BRIGHT_MASK);
wim 1:e180256ba6fb 394 _write(HDSP253X_ADDR_CTRL_WORD, ctrl_data);
wim 1:e180256ba6fb 395 }
wim 1:e180256ba6fb 396
wim 1:e180256ba6fb 397 /*---------------------------------------------------------------------------*\
wim 1:e180256ba6fb 398 |
wim 1:e180256ba6fb 399 | Function: HDSP253X_start_self_test
wim 1:e180256ba6fb 400 |
wim 1:e180256ba6fb 401 | Description: Starts the HDSP253X self test, setting the relevant
wim 1:e180256ba6fb 402 | control word bit. The caller should then wait for
wim 1:e180256ba6fb 403 | the required number of seconds before checking the result.
wim 1:e180256ba6fb 404 | With the internal display clock, the self test takes
wim 1:e180256ba6fb 405 | around 5 seconds, so waiting for 6 seconds should
wim 1:e180256ba6fb 406 | be OK. Slower clocks will require longer delays.
wim 1:e180256ba6fb 407 |
wim 1:e180256ba6fb 408 | Note that some displays such as the Siemens HDSP2111
wim 1:e180256ba6fb 409 | appear to take longer than the official 4.5 seconds
wim 1:e180256ba6fb 410 | so it is advisable to wait for longer (say 6 seconds)
wim 1:e180256ba6fb 411 | before checking the result. Attempting to access the
wim 1:e180256ba6fb 412 | display before it is ready may result in the self test
wim 1:e180256ba6fb 413 | status failing to clear down.
wim 1:e180256ba6fb 414 |
wim 1:e180256ba6fb 415 | Also note that some display datasheets suggest that
wim 1:e180256ba6fb 416 | the display must be reset BEFORE running the self
wim 1:e180256ba6fb 417 | test routine, so this routine does this.
wim 1:e180256ba6fb 418 |
wim 1:e180256ba6fb 419 | Parameters: None
wim 1:e180256ba6fb 420 |
wim 1:e180256ba6fb 421 | Returns: Nothing
wim 1:e180256ba6fb 422 |
wim 1:e180256ba6fb 423 \*---------------------------------------------------------------------------*/
wim 1:e180256ba6fb 424
wim 1:e180256ba6fb 425 void HDSP253X_Display::start_self_test(void) {
wim 1:e180256ba6fb 426
wim 1:e180256ba6fb 427 // Reset the display to ensure it is ready for the self test
wim 1:e180256ba6fb 428 reset();
wim 1:e180256ba6fb 429
wim 1:e180256ba6fb 430 // Directly write the self test request, as control word is wiped at end
wim 1:e180256ba6fb 431 _write(HDSP253X_ADDR_CTRL_WORD, HDSP253X_CTRL_SELFTEST_MASK);
wim 1:e180256ba6fb 432 }
wim 1:e180256ba6fb 433
wim 1:e180256ba6fb 434 /*---------------------------------------------------------------------------*\
wim 1:e180256ba6fb 435 |
wim 1:e180256ba6fb 436 | Function: HDSP253X_finish_self_test
wim 1:e180256ba6fb 437 |
wim 1:e180256ba6fb 438 | Description: Reads the control register to determine the self test
wim 1:e180256ba6fb 439 | result. Then issues a display reset to ensure
wim 1:e180256ba6fb 440 | that it is ready for operation afterwards. While such
wim 1:e180256ba6fb 441 | a reset should not be necessary if an adequate delay
wim 1:e180256ba6fb 442 | occurs between starting the self test and checking the
wim 1:e180256ba6fb 443 | result, issuing a reset guarantees that the display will
wim 1:e180256ba6fb 444 | be ready for operation. This also means that this function
wim 1:e180256ba6fb 445 | can be called early to prematurely terminate a self test.
wim 1:e180256ba6fb 446 |
wim 1:e180256ba6fb 447 | Parameters: None
wim 1:e180256ba6fb 448 |
wim 1:e180256ba6fb 449 | Returns: True if passed, False if failed
wim 1:e180256ba6fb 450 |
wim 1:e180256ba6fb 451 \*---------------------------------------------------------------------------*/
wim 1:e180256ba6fb 452
wim 1:e180256ba6fb 453 bool HDSP253X_Display::finish_self_test(void) {
wim 1:e180256ba6fb 454 uint8_t ctrl_data;
wim 1:e180256ba6fb 455 bool result;
wim 1:e180256ba6fb 456
wim 1:e180256ba6fb 457 // Read back control word and obtain self test result
wim 1:e180256ba6fb 458 ctrl_data = _read(HDSP253X_ADDR_CTRL_WORD);
wim 1:e180256ba6fb 459 result = ((ctrl_data & HDSP253X_CTRL_STRESULT_MASK) != 0);
wim 1:e180256ba6fb 460
wim 1:e180256ba6fb 461 // Reset the display to ensure it is ready for normal operation
wim 1:e180256ba6fb 462 reset();
wim 1:e180256ba6fb 463
wim 1:e180256ba6fb 464 // Indicate the self test result
wim 1:e180256ba6fb 465 return result;
wim 1:e180256ba6fb 466 }
wim 1:e180256ba6fb 467
wim 1:e180256ba6fb 468
wim 1:e180256ba6fb 469 /*---------------------------------------------------------------------------*\
wim 1:e180256ba6fb 470 |
wim 1:e180256ba6fb 471 | Function: HDSP253X_set_blink_mode
wim 1:e180256ba6fb 472 |
wim 1:e180256ba6fb 473 | Description: Enables or disables the blinking function on the display.
wim 1:e180256ba6fb 474 | When enabled, blinking will flash the whole display
wim 1:e180256ba6fb 475 | irrespective of the flash RAM. With the internal clock,
wim 1:e180256ba6fb 476 | the blink rate is 2Hz. Note that blink mode overrides
wim 1:e180256ba6fb 477 | the normal flashing mode.
wim 1:e180256ba6fb 478 |
wim 1:e180256ba6fb 479 | Parameters: enable - true to enable, false to disable
wim 1:e180256ba6fb 480 |
wim 1:e180256ba6fb 481 | Returns: Nothing
wim 1:e180256ba6fb 482 |
wim 1:e180256ba6fb 483 \*---------------------------------------------------------------------------*/
wim 1:e180256ba6fb 484
wim 1:e180256ba6fb 485 void HDSP253X_Display::set_blink_mode(bool enable) {
wim 1:e180256ba6fb 486 uint8_t ctrl_data;
wim 1:e180256ba6fb 487
wim 1:e180256ba6fb 488 // read in control word, modify and write back out
wim 1:e180256ba6fb 489 ctrl_data = _read(HDSP253X_ADDR_CTRL_WORD);
wim 1:e180256ba6fb 490 if (enable) {
wim 1:e180256ba6fb 491 ctrl_data |= HDSP253X_CTRL_BLINK_MASK;
wim 1:e180256ba6fb 492 }
wim 1:e180256ba6fb 493 else {
wim 1:e180256ba6fb 494 ctrl_data &= ~HDSP253X_CTRL_BLINK_MASK;
wim 1:e180256ba6fb 495 }
wim 1:e180256ba6fb 496 _write(HDSP253X_ADDR_CTRL_WORD, ctrl_data);
wim 1:e180256ba6fb 497 }
wim 1:e180256ba6fb 498
wim 1:e180256ba6fb 499 /*---------------------------------------------------------------------------*\
wim 1:e180256ba6fb 500 |
wim 1:e180256ba6fb 501 | Function: HDSP253X_set_flash_mode
wim 1:e180256ba6fb 502 |
wim 1:e180256ba6fb 503 | Description: Enables or disables the flashing function on the display.
wim 1:e180256ba6fb 504 | When enabled, characters with the flashing bit set in the
wim 1:e180256ba6fb 505 | RAM will flash. With the internal clock, the flash rate is 2Hz.
wim 1:e180256ba6fb 506 |
wim 1:e180256ba6fb 507 | Parameters: enable - true to enable, false to disable
wim 1:e180256ba6fb 508 |
wim 1:e180256ba6fb 509 | Returns: Nothing
wim 1:e180256ba6fb 510 |
wim 1:e180256ba6fb 511 \*---------------------------------------------------------------------------*/
wim 1:e180256ba6fb 512
wim 1:e180256ba6fb 513 void HDSP253X_Display::set_flash_mode(bool enable) {
wim 1:e180256ba6fb 514 uint8_t ctrl_data;
wim 1:e180256ba6fb 515
wim 1:e180256ba6fb 516 // read in control word, modify and write back out
wim 1:e180256ba6fb 517 ctrl_data = _read(HDSP253X_ADDR_CTRL_WORD);
wim 1:e180256ba6fb 518 if (enable) {
wim 1:e180256ba6fb 519 ctrl_data |= HDSP253X_CTRL_FLASH_MASK;
wim 1:e180256ba6fb 520 }
wim 1:e180256ba6fb 521 else {
wim 1:e180256ba6fb 522 ctrl_data &= ~HDSP253X_CTRL_FLASH_MASK;
wim 1:e180256ba6fb 523 }
wim 1:e180256ba6fb 524 _write(HDSP253X_ADDR_CTRL_WORD, ctrl_data);
wim 1:e180256ba6fb 525 }
wim 1:e180256ba6fb 526
wim 1:e180256ba6fb 527 /*---------------------------------------------------------------------------*\
wim 1:e180256ba6fb 528 |
wim 1:e180256ba6fb 529 | Function: HDSP253X_set_all_flash_states
wim 1:e180256ba6fb 530 |
wim 1:e180256ba6fb 531 | Description: Sets flashing states of all characters in flash RAM, using
wim 1:e180256ba6fb 532 | supplied bit mask. Each bit corresponds to a character
wim 1:e180256ba6fb 533 | (bit 7 on left, bit 0 on right), and is set to flash and
wim 1:e180256ba6fb 534 | clear for steady operation. NOTE: The overall flashing
wim 1:e180256ba6fb 535 | enable/disable state is set by the separate set flash
wim 1:e180256ba6fb 536 | mode function.
wim 1:e180256ba6fb 537 |
wim 1:e180256ba6fb 538 | Parameters: flash_bits - bitmask containing flash states
wim 1:e180256ba6fb 539 |
wim 1:e180256ba6fb 540 | Returns: Nothing
wim 1:e180256ba6fb 541 |
wim 1:e180256ba6fb 542 \*---------------------------------------------------------------------------*/
wim 1:e180256ba6fb 543
wim 1:e180256ba6fb 544 void HDSP253X_Display::set_all_flash_states(uint8_t flash_bits)
wim 1:e180256ba6fb 545 {
wim 1:e180256ba6fb 546 int i;
wim 1:e180256ba6fb 547 uint8_t char_pos;
wim 1:e180256ba6fb 548
wim 1:e180256ba6fb 549 // loop round all character positions, extracting each bit in turn
wim 1:e180256ba6fb 550 for (i = 1; i <= HDSP253X_NUM_CHARS; i++)
wim 1:e180256ba6fb 551 {
wim 1:e180256ba6fb 552 // Get state of bottom bit from mask and use to adjust flash state
wim 1:e180256ba6fb 553 // Note that character address is reversed as we start from right
wim 1:e180256ba6fb 554 char_pos = HDSP253X_NUM_CHARS - i;
wim 1:e180256ba6fb 555 _write(HDSP253X_ADDR_FLASH_BASE + char_pos, flash_bits & 0x01);
wim 1:e180256ba6fb 556
wim 1:e180256ba6fb 557 // Shift the mask to the right, ready for the next go
wim 1:e180256ba6fb 558 flash_bits >>= 1;
wim 1:e180256ba6fb 559 }
wim 1:e180256ba6fb 560 }
wim 1:e180256ba6fb 561
wim 1:e180256ba6fb 562 /*---------------------------------------------------------------------------*\
wim 1:e180256ba6fb 563 |
wim 1:e180256ba6fb 564 | Function: HDSP253X_set_char_flash_state
wim 1:e180256ba6fb 565 |
wim 1:e180256ba6fb 566 | Description: Sets flashing state of one character in flash RAM, using
wim 1:e180256ba6fb 567 | supplied character position and enable state. NOTE: The
wim 1:e180256ba6fb 568 | overall flashing enable/disable state is set by the
wim 1:e180256ba6fb 569 | separate set flash mode function.
wim 1:e180256ba6fb 570 |
wim 1:e180256ba6fb 571 | Parameters: flash_state - TRUE to flash, FALSE for steady operation
wim 1:e180256ba6fb 572 | char_pos - position on the display (0 to 7)
wim 1:e180256ba6fb 573 |
wim 1:e180256ba6fb 574 | Returns: Nothing
wim 1:e180256ba6fb 575 |
wim 1:e180256ba6fb 576 \*---------------------------------------------------------------------------*/
wim 1:e180256ba6fb 577
wim 1:e180256ba6fb 578 void HDSP253X_Display::set_char_flash_state(bool flash_state, uint8_t char_pos) {
wim 1:e180256ba6fb 579 // Write out the new flash state to the flash RAM
wim 1:e180256ba6fb 580 _write(HDSP253X_ADDR_FLASH_BASE + char_pos, flash_state);
wim 1:e180256ba6fb 581 }
wim 1:e180256ba6fb 582
wim 1:e180256ba6fb 583 /*---------------------------------------------------------------------------*\
wim 1:e180256ba6fb 584 |
wim 1:e180256ba6fb 585 | Function: HDSP253X_define_user_char
wim 1:e180256ba6fb 586 |
wim 1:e180256ba6fb 587 | Description: Full definition of UDC, firstly setting the UDC address
wim 1:e180256ba6fb 588 | to specified character, and then loading all 7 data rows.
wim 1:e180256ba6fb 589 | Note that for each row, only the bottom 5 bits are used.
wim 1:e180256ba6fb 590 |
wim 1:e180256ba6fb 591 | Parameters: udc_char_num - number of UDC character, from 0 to 15
wim 1:e180256ba6fb 592 | row_data_1 - top row data
wim 1:e180256ba6fb 593 | row_data_2 - second row data
wim 1:e180256ba6fb 594 | row_data_3 - third row data
wim 1:e180256ba6fb 595 | row_data_4 - fourth row data
wim 1:e180256ba6fb 596 | row_data_5 - fifth row data
wim 1:e180256ba6fb 597 | row_data_6 - sixth row data
wim 1:e180256ba6fb 598 | row_data_7 - bottomp row data
wim 1:e180256ba6fb 599 |
wim 1:e180256ba6fb 600 | Returns: Nothing
wim 1:e180256ba6fb 601 |
wim 1:e180256ba6fb 602 \*---------------------------------------------------------------------------*/
wim 1:e180256ba6fb 603
wim 1:e180256ba6fb 604 void HDSP253X_Display::define_user_char(uint8_t udc_char_num, uint8_t row_data_1, uint8_t row_data_2,
wim 1:e180256ba6fb 605 uint8_t row_data_3, uint8_t row_data_4, uint8_t row_data_5,
wim 1:e180256ba6fb 606 uint8_t row_data_6, uint8_t row_data_7)
wim 1:e180256ba6fb 607 {
wim 1:e180256ba6fb 608 // firstly set the UDC character address, by writing to the UDC addr reg
wim 1:e180256ba6fb 609 _write(HDSP253X_ADDR_UDC_ADDRESS, udc_char_num);
wim 1:e180256ba6fb 610
wim 1:e180256ba6fb 611 // now write out the 7 rows to the UDC RAM
wim 1:e180256ba6fb 612 _write(HDSP253X_ADDR_UDC_ROW_BASE+0, row_data_1);
wim 1:e180256ba6fb 613 _write(HDSP253X_ADDR_UDC_ROW_BASE+1, row_data_2);
wim 1:e180256ba6fb 614 _write(HDSP253X_ADDR_UDC_ROW_BASE+2, row_data_3);
wim 1:e180256ba6fb 615 _write(HDSP253X_ADDR_UDC_ROW_BASE+3, row_data_4);
wim 1:e180256ba6fb 616 _write(HDSP253X_ADDR_UDC_ROW_BASE+4, row_data_5);
wim 1:e180256ba6fb 617 _write(HDSP253X_ADDR_UDC_ROW_BASE+5, row_data_6);
wim 1:e180256ba6fb 618 _write(HDSP253X_ADDR_UDC_ROW_BASE+6, row_data_7);
wim 1:e180256ba6fb 619 }
wim 1:e180256ba6fb 620
wim 1:e180256ba6fb 621
wim 1:e180256ba6fb 622 /*****************************************************************************/
wim 1:e180256ba6fb 623 /****************************** END OF FILE ********************************/
wim 1:e180256ba6fb 624 /*****************************************************************************/
wim 1:e180256ba6fb 625