Sanyo LC75711 VFD controller/driver for upto 16 Dot Matrix Characters
The component page is here.
LC75711.cpp@1:bcf010fcacae, 2017-09-13 (annotated)
- Committer:
- wim
- Date:
- Wed Sep 13 18:25:24 2017 +0000
- Revision:
- 1:bcf010fcacae
- Parent:
- 0:5eb5fee234e8
- Child:
- 2:cb6f2b7930c8
Fixed doxygen comments
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
wim | 0:5eb5fee234e8 | 1 | /* mbed LC75710 Library, for Sanyo LC7571X VFD controller |
wim | 0:5eb5fee234e8 | 2 | * Note: The LC75710, LC75711 and LC75712 differ only in the built-in character ROM |
wim | 0:5eb5fee234e8 | 3 | * |
wim | 0:5eb5fee234e8 | 4 | * Copyright (c) 2017, v01: WH, Initial version |
wim | 1:bcf010fcacae | 5 | * 2017, v02: WH, Cleaned up docs |
wim | 0:5eb5fee234e8 | 6 | * |
wim | 0:5eb5fee234e8 | 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
wim | 0:5eb5fee234e8 | 8 | * of this software and associated documentation files (the "Software"), to deal |
wim | 0:5eb5fee234e8 | 9 | * in the Software without restriction, including without limitation the rights |
wim | 0:5eb5fee234e8 | 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
wim | 0:5eb5fee234e8 | 11 | * copies of the Software, and to permit persons to whom the Software is |
wim | 0:5eb5fee234e8 | 12 | * furnished to do so, subject to the following conditions: |
wim | 0:5eb5fee234e8 | 13 | * |
wim | 0:5eb5fee234e8 | 14 | * The above copyright notice and this permission notice shall be included in |
wim | 0:5eb5fee234e8 | 15 | * all copies or substantial portions of the Software. |
wim | 0:5eb5fee234e8 | 16 | * |
wim | 0:5eb5fee234e8 | 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
wim | 0:5eb5fee234e8 | 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
wim | 0:5eb5fee234e8 | 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
wim | 0:5eb5fee234e8 | 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
wim | 0:5eb5fee234e8 | 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
wim | 0:5eb5fee234e8 | 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
wim | 0:5eb5fee234e8 | 23 | * THE SOFTWARE. |
wim | 0:5eb5fee234e8 | 24 | */ |
wim | 0:5eb5fee234e8 | 25 | |
wim | 0:5eb5fee234e8 | 26 | #include "mbed.h" |
wim | 0:5eb5fee234e8 | 27 | #include "LC75711.h" |
wim | 0:5eb5fee234e8 | 28 | #include "LC75711_UDC.inc" |
wim | 0:5eb5fee234e8 | 29 | |
wim | 0:5eb5fee234e8 | 30 | |
wim | 0:5eb5fee234e8 | 31 | /** Constructor for class for driving Sanyo LC75711 VFD controller |
wim | 0:5eb5fee234e8 | 32 | * |
wim | 1:bcf010fcacae | 33 | * @brief Supports upto 16 Grids of 35 matrix segments. Also supports 3-8 additional segments (depending on number of grids). |
wim | 1:bcf010fcacae | 34 | * SPI bus interface device. |
wim | 0:5eb5fee234e8 | 35 | * @param PinName mosi, sclk, cs SPI bus pins |
wim | 0:5eb5fee234e8 | 36 | * @param Mode selects number of Grids and Segments (default 11 Grids, 35 matrix segments, 8 additional segments) |
wim | 0:5eb5fee234e8 | 37 | */ |
wim | 0:5eb5fee234e8 | 38 | LC75711::LC75711(PinName mosi, PinName sclk, PinName cs, Mode mode) : _spi(mosi,NC,sclk), _cs(cs), _mode(mode) { |
wim | 0:5eb5fee234e8 | 39 | |
wim | 0:5eb5fee234e8 | 40 | _init(); |
wim | 0:5eb5fee234e8 | 41 | } |
wim | 0:5eb5fee234e8 | 42 | |
wim | 0:5eb5fee234e8 | 43 | /** Init the LC75711 interface and the controller |
wim | 1:bcf010fcacae | 44 | * |
wim | 0:5eb5fee234e8 | 45 | * @param none |
wim | 0:5eb5fee234e8 | 46 | * @return none |
wim | 0:5eb5fee234e8 | 47 | */ |
wim | 0:5eb5fee234e8 | 48 | void LC75711::_init(){ |
wim | 0:5eb5fee234e8 | 49 | |
wim | 0:5eb5fee234e8 | 50 | //init SPI |
wim | 0:5eb5fee234e8 | 51 | _cs=0; |
wim | 0:5eb5fee234e8 | 52 | _spi.format(8,0); //LC75711 uses mode 0 (Clock Low on Idle, Data latched on first (=rising) edge) |
wim | 0:5eb5fee234e8 | 53 | // _spi.frequency(100000); |
wim | 0:5eb5fee234e8 | 54 | _spi.frequency(250000); |
wim | 0:5eb5fee234e8 | 55 | |
wim | 0:5eb5fee234e8 | 56 | //init controller |
wim | 0:5eb5fee234e8 | 57 | |
wim | 0:5eb5fee234e8 | 58 | // Set number of Grids |
wim | 0:5eb5fee234e8 | 59 | _writeCmd((LC75711_GRID_REG | _mode), // B16..B23, Command register & value |
wim | 0:5eb5fee234e8 | 60 | 0x00, // B8..B15, Dummy |
wim | 0:5eb5fee234e8 | 61 | 0x00, // B0..B7, Dummy |
wim | 0:5eb5fee234e8 | 62 | LC75711_GRID_DLY); // Command Delay |
wim | 0:5eb5fee234e8 | 63 | |
wim | 0:5eb5fee234e8 | 64 | _setAddress(0, 0); // No shift |
wim | 0:5eb5fee234e8 | 65 | |
wim | 0:5eb5fee234e8 | 66 | setBlink(false); // No Blink |
wim | 0:5eb5fee234e8 | 67 | setBrightness(LC75711_BRT_DEF); // Default Brightness |
wim | 0:5eb5fee234e8 | 68 | |
wim | 0:5eb5fee234e8 | 69 | // Clear the DCRAM (undefined at Reset) |
wim | 0:5eb5fee234e8 | 70 | cls(); |
wim | 0:5eb5fee234e8 | 71 | |
wim | 0:5eb5fee234e8 | 72 | // Clear the UDC RAM (undefined at Reset) |
wim | 0:5eb5fee234e8 | 73 | const char udc_none[] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00}; |
wim | 0:5eb5fee234e8 | 74 | for (int idx=0; idx < LC75711_NR_UDC; idx++) { |
wim | 0:5eb5fee234e8 | 75 | setUDC(idx, (char *)udc_none); |
wim | 0:5eb5fee234e8 | 76 | } |
wim | 0:5eb5fee234e8 | 77 | |
wim | 0:5eb5fee234e8 | 78 | setDisplay(true); // Display On |
wim | 0:5eb5fee234e8 | 79 | } |
wim | 0:5eb5fee234e8 | 80 | |
wim | 0:5eb5fee234e8 | 81 | |
wim | 0:5eb5fee234e8 | 82 | /** Clear the screen and locate to 0 |
wim | 1:bcf010fcacae | 83 | * |
wim | 1:bcf010fcacae | 84 | * @param none |
wim | 1:bcf010fcacae | 85 | * @return none |
wim | 1:bcf010fcacae | 86 | */ |
wim | 0:5eb5fee234e8 | 87 | void LC75711::cls() { |
wim | 0:5eb5fee234e8 | 88 | |
wim | 0:5eb5fee234e8 | 89 | for (int cnt=0; cnt<LC75711_DISPLAY_MEM; cnt++) { |
wim | 0:5eb5fee234e8 | 90 | writeData(char (' '), cnt); // data |
wim | 0:5eb5fee234e8 | 91 | // writeData(0x00, cnt); // data |
wim | 0:5eb5fee234e8 | 92 | } |
wim | 0:5eb5fee234e8 | 93 | |
wim | 0:5eb5fee234e8 | 94 | for (int cnt=0; cnt<LC75711_ADD_MEM; cnt++) { |
wim | 0:5eb5fee234e8 | 95 | writeData(0x00, cnt); // adata |
wim | 0:5eb5fee234e8 | 96 | } |
wim | 0:5eb5fee234e8 | 97 | } |
wim | 0:5eb5fee234e8 | 98 | |
wim | 0:5eb5fee234e8 | 99 | /** Set the Blink mode |
wim | 0:5eb5fee234e8 | 100 | * |
wim | 0:5eb5fee234e8 | 101 | * @param bool Blink mode |
wim | 1:bcf010fcacae | 102 | * @param int grids selected grids for Blinking enable/disable (default = all) |
wim | 1:bcf010fcacae | 103 | * @return none |
wim | 0:5eb5fee234e8 | 104 | */ |
wim | 0:5eb5fee234e8 | 105 | void LC75711::setBlink(bool on, int grids) { |
wim | 0:5eb5fee234e8 | 106 | |
wim | 0:5eb5fee234e8 | 107 | // Sanity check and update of local shadow |
wim | 0:5eb5fee234e8 | 108 | if (on) { |
wim | 0:5eb5fee234e8 | 109 | _blink = _blink | (grids & LC75711_GR_MSK); // Set grid bits |
wim | 0:5eb5fee234e8 | 110 | } |
wim | 0:5eb5fee234e8 | 111 | else { |
wim | 0:5eb5fee234e8 | 112 | _blink = _blink & ~(grids & LC75711_GR_MSK); // Clr grid bits |
wim | 0:5eb5fee234e8 | 113 | } |
wim | 0:5eb5fee234e8 | 114 | |
wim | 0:5eb5fee234e8 | 115 | _writeCmd((LC75711_BLNK_REG | LC75711_BLNK_ON), // B16..B23, Command register & value |
wim | 0:5eb5fee234e8 | 116 | ((_blink >> 8) & 0xFF), // B8..B15, GR8..GR16 |
wim | 0:5eb5fee234e8 | 117 | ( _blink & 0xFF), // B0..B7, GR1..GR7 |
wim | 0:5eb5fee234e8 | 118 | LC75711_BLNK_DLY); // Command Delay |
wim | 0:5eb5fee234e8 | 119 | } |
wim | 0:5eb5fee234e8 | 120 | |
wim | 0:5eb5fee234e8 | 121 | |
wim | 0:5eb5fee234e8 | 122 | /** Set Brightness |
wim | 0:5eb5fee234e8 | 123 | * |
wim | 0:5eb5fee234e8 | 124 | * @param char brightness (8 significant bits, valid range 0..239 (dutycycle linked to number of grids) |
wim | 0:5eb5fee234e8 | 125 | * @return none |
wim | 0:5eb5fee234e8 | 126 | */ |
wim | 0:5eb5fee234e8 | 127 | void LC75711::setBrightness(char brightness){ |
wim | 0:5eb5fee234e8 | 128 | |
wim | 0:5eb5fee234e8 | 129 | //Sanity check |
wim | 0:5eb5fee234e8 | 130 | brightness = brightness & LC75711_BRT_MSK; // mask invalid bits |
wim | 0:5eb5fee234e8 | 131 | if (brightness > 239) {brightness = 239;} |
wim | 0:5eb5fee234e8 | 132 | |
wim | 0:5eb5fee234e8 | 133 | _writeCmd((LC75711_BRT_REG), // B16..B23, Command register |
wim | 0:5eb5fee234e8 | 134 | brightness, // B8..B15, Brightness |
wim | 0:5eb5fee234e8 | 135 | 0x00, // B0..B7, Dummy |
wim | 0:5eb5fee234e8 | 136 | LC75711_BRT_DLY); // Command Delay |
wim | 0:5eb5fee234e8 | 137 | } |
wim | 0:5eb5fee234e8 | 138 | |
wim | 0:5eb5fee234e8 | 139 | /** Set the Display mode On/off |
wim | 0:5eb5fee234e8 | 140 | * |
wim | 0:5eb5fee234e8 | 141 | * @param bool display mode |
wim | 1:bcf010fcacae | 142 | * @return none |
wim | 0:5eb5fee234e8 | 143 | */ |
wim | 0:5eb5fee234e8 | 144 | void LC75711::setDisplay(bool on) { |
wim | 0:5eb5fee234e8 | 145 | char display; |
wim | 0:5eb5fee234e8 | 146 | |
wim | 0:5eb5fee234e8 | 147 | if (on) { |
wim | 0:5eb5fee234e8 | 148 | display = LC75711_DSPL_ON; |
wim | 0:5eb5fee234e8 | 149 | } |
wim | 0:5eb5fee234e8 | 150 | else { |
wim | 0:5eb5fee234e8 | 151 | display = LC75711_DSPL_OFF; |
wim | 0:5eb5fee234e8 | 152 | } |
wim | 0:5eb5fee234e8 | 153 | |
wim | 0:5eb5fee234e8 | 154 | _writeCmd((LC75711_DSPL_REG | display), // B16..B23, Command register & value |
wim | 0:5eb5fee234e8 | 155 | 0xFF, // B8..B15, GR8..GR16 |
wim | 0:5eb5fee234e8 | 156 | 0xFF, // B0..B7, GR1..GR7 |
wim | 0:5eb5fee234e8 | 157 | LC75711_DSPL_DLY); // Command Delay |
wim | 0:5eb5fee234e8 | 158 | } |
wim | 0:5eb5fee234e8 | 159 | |
wim | 0:5eb5fee234e8 | 160 | |
wim | 0:5eb5fee234e8 | 161 | /** Set User Defined Characters (UDC) |
wim | 0:5eb5fee234e8 | 162 | * |
wim | 0:5eb5fee234e8 | 163 | * @param unsigned char udc_idx The Index of the UDC (0..7) |
wim | 1:bcf010fcacae | 164 | * @param UDCData_t udc_data The bitpattern for the UDC (7 bytes) |
wim | 1:bcf010fcacae | 165 | * @return none |
wim | 0:5eb5fee234e8 | 166 | */ |
wim | 0:5eb5fee234e8 | 167 | void LC75711::setUDC(unsigned char udc_idx, UDCData_t udc_data) { |
wim | 0:5eb5fee234e8 | 168 | char data; |
wim | 0:5eb5fee234e8 | 169 | |
wim | 0:5eb5fee234e8 | 170 | //Sanity check |
wim | 0:5eb5fee234e8 | 171 | udc_idx = udc_idx & LC75711_UDC_MSK; // mask invalid bits |
wim | 0:5eb5fee234e8 | 172 | |
wim | 0:5eb5fee234e8 | 173 | _cs=0; // Prepare to send Address |
wim | 0:5eb5fee234e8 | 174 | wait_us(1); |
wim | 0:5eb5fee234e8 | 175 | |
wim | 0:5eb5fee234e8 | 176 | _spi.write(_flip(LC75711_ADDRESS)); // Address |
wim | 0:5eb5fee234e8 | 177 | |
wim | 0:5eb5fee234e8 | 178 | _cs=1; // Latch Address, Prepare to send Command & Params |
wim | 0:5eb5fee234e8 | 179 | wait_us(1); |
wim | 0:5eb5fee234e8 | 180 | |
wim | 0:5eb5fee234e8 | 181 | data = ((udc_data[1] & 0x07) << 5) | ((udc_data[0] & 0x1F) << 0); |
wim | 0:5eb5fee234e8 | 182 | _spi.write(_flip(data)); // B0..B7, AM1-AM8 |
wim | 0:5eb5fee234e8 | 183 | |
wim | 0:5eb5fee234e8 | 184 | data = ((udc_data[3] & 0x01) << 7) | ((udc_data[2] & 0x1F) << 2) | ((udc_data[1] & 0x18) >> 3); |
wim | 0:5eb5fee234e8 | 185 | _spi.write(_flip(data)); // B8..B15, AM9-AM16 |
wim | 0:5eb5fee234e8 | 186 | |
wim | 0:5eb5fee234e8 | 187 | data = ((udc_data[4] & 0x0F) << 4) | ((udc_data[3] & 0x1E) >> 1); |
wim | 0:5eb5fee234e8 | 188 | _spi.write(_flip(data)); // B16..B23, AM17-AM24 |
wim | 0:5eb5fee234e8 | 189 | |
wim | 0:5eb5fee234e8 | 190 | data = ((udc_data[6] & 0x03) << 6) | ((udc_data[5] & 0x1F) << 1) | ((udc_data[4] & 0x10) >> 4); |
wim | 0:5eb5fee234e8 | 191 | _spi.write(_flip(data)); // B24..B31, AM25-AM32 |
wim | 0:5eb5fee234e8 | 192 | |
wim | 0:5eb5fee234e8 | 193 | data = ((udc_data[6] & 0x1C) >> 2); |
wim | 0:5eb5fee234e8 | 194 | _spi.write(_flip(data)); // B32..B39, AM32-AM35 |
wim | 0:5eb5fee234e8 | 195 | |
wim | 0:5eb5fee234e8 | 196 | _spi.write(_flip(udc_idx)); // B40..B47, CA0-CA7 |
wim | 0:5eb5fee234e8 | 197 | |
wim | 0:5eb5fee234e8 | 198 | _spi.write(_flip(LC75711_UDC_REG)); // B48..B55, Command register |
wim | 0:5eb5fee234e8 | 199 | |
wim | 0:5eb5fee234e8 | 200 | wait_us(1); |
wim | 0:5eb5fee234e8 | 201 | _cs=0; // Latch Command & Params |
wim | 0:5eb5fee234e8 | 202 | |
wim | 0:5eb5fee234e8 | 203 | wait_us(LC75711_UDC_DLY); // Command Delay |
wim | 0:5eb5fee234e8 | 204 | } |
wim | 0:5eb5fee234e8 | 205 | |
wim | 0:5eb5fee234e8 | 206 | |
wim | 0:5eb5fee234e8 | 207 | /** Write Data to LC75711 |
wim | 1:bcf010fcacae | 208 | * |
wim | 1:bcf010fcacae | 209 | * @param char data Character code |
wim | 1:bcf010fcacae | 210 | * @param char address Parameter for data |
wim | 0:5eb5fee234e8 | 211 | * @return none |
wim | 0:5eb5fee234e8 | 212 | */ |
wim | 0:5eb5fee234e8 | 213 | void LC75711::writeData(char data, char address){ |
wim | 0:5eb5fee234e8 | 214 | |
wim | 0:5eb5fee234e8 | 215 | //Sanity check |
wim | 0:5eb5fee234e8 | 216 | address = address & LC75711_DADR_MSK; // mask invalid bits |
wim | 0:5eb5fee234e8 | 217 | |
wim | 0:5eb5fee234e8 | 218 | _writeCmd((LC75711_DATA_REG), // B16..B23, Command register |
wim | 0:5eb5fee234e8 | 219 | address, // B8..B15, DCRAM address |
wim | 0:5eb5fee234e8 | 220 | data, // B0..B7, Character code |
wim | 0:5eb5fee234e8 | 221 | LC75711_DATA_DLY); // Command Delay |
wim | 0:5eb5fee234e8 | 222 | } |
wim | 0:5eb5fee234e8 | 223 | |
wim | 0:5eb5fee234e8 | 224 | /** Write Additional Data to LC75711 |
wim | 1:bcf010fcacae | 225 | * |
wim | 1:bcf010fcacae | 226 | * @param char adata Additional code (annunciator) |
wim | 1:bcf010fcacae | 227 | * @param char address Parameter for data |
wim | 0:5eb5fee234e8 | 228 | * @return none |
wim | 0:5eb5fee234e8 | 229 | */ |
wim | 0:5eb5fee234e8 | 230 | void LC75711::writeAData(char adata, char address){ |
wim | 0:5eb5fee234e8 | 231 | |
wim | 0:5eb5fee234e8 | 232 | //Sanity check |
wim | 0:5eb5fee234e8 | 233 | address = address & LC75711_AADR_MSK; // mask invalid bits |
wim | 0:5eb5fee234e8 | 234 | |
wim | 0:5eb5fee234e8 | 235 | _writeCmd((LC75711_ADAT_REG | address), // B16..B23, Command register & ADRAM address |
wim | 0:5eb5fee234e8 | 236 | adata, // B8..B15, ADATA |
wim | 0:5eb5fee234e8 | 237 | 0x00, // B0..B7, Dummy |
wim | 0:5eb5fee234e8 | 238 | LC75711_ADAT_DLY); // Command Delay |
wim | 0:5eb5fee234e8 | 239 | } |
wim | 0:5eb5fee234e8 | 240 | |
wim | 0:5eb5fee234e8 | 241 | |
wim | 0:5eb5fee234e8 | 242 | /** Set Address |
wim | 1:bcf010fcacae | 243 | * |
wim | 1:bcf010fcacae | 244 | * @param char RAM address for data displayed at Grid1 (0..63) |
wim | 1:bcf010fcacae | 245 | * @param char RAM address for adata displayed at Grid1 (0..15) |
wim | 0:5eb5fee234e8 | 246 | * @return none |
wim | 0:5eb5fee234e8 | 247 | * |
wim | 1:bcf010fcacae | 248 | * Note that a Shift (L/R) command will change the Address of data displayed at Grid1 |
wim | 0:5eb5fee234e8 | 249 | */ |
wim | 0:5eb5fee234e8 | 250 | void LC75711::_setAddress(char data_addr, char adata_addr){ |
wim | 0:5eb5fee234e8 | 251 | |
wim | 0:5eb5fee234e8 | 252 | //Sanity check |
wim | 0:5eb5fee234e8 | 253 | data_addr = data_addr & LC75711_DADR_MSK; // mask invalid bits |
wim | 0:5eb5fee234e8 | 254 | adata_addr = adata_addr & LC75711_AADR_MSK; // mask invalid bits |
wim | 0:5eb5fee234e8 | 255 | |
wim | 0:5eb5fee234e8 | 256 | _writeCmd((LC75711_AC_REG | adata_addr), // B16..B23, Command register & ADRAM address |
wim | 0:5eb5fee234e8 | 257 | data_addr, // B8..B15, DCRAM address |
wim | 0:5eb5fee234e8 | 258 | 0x00, // B0..B7, Dummy |
wim | 0:5eb5fee234e8 | 259 | LC75711_AC_DLY); // Command Delay |
wim | 0:5eb5fee234e8 | 260 | } |
wim | 0:5eb5fee234e8 | 261 | |
wim | 0:5eb5fee234e8 | 262 | |
wim | 0:5eb5fee234e8 | 263 | /** Write command and parameters to LC75711 |
wim | 1:bcf010fcacae | 264 | * |
wim | 1:bcf010fcacae | 265 | * @param char cmd Command byte |
wim | 1:bcf010fcacae | 266 | * @param char data1 Parameters for command |
wim | 1:bcf010fcacae | 267 | * @param char data0 Parameters for command |
wim | 1:bcf010fcacae | 268 | * @param char delay Delay for command execution |
wim | 0:5eb5fee234e8 | 269 | * @return none |
wim | 0:5eb5fee234e8 | 270 | */ |
wim | 0:5eb5fee234e8 | 271 | void LC75711::_writeCmd(char cmd, char data1, char data0, char delay){ |
wim | 0:5eb5fee234e8 | 272 | |
wim | 0:5eb5fee234e8 | 273 | _cs=0; // Prepare to send Address |
wim | 0:5eb5fee234e8 | 274 | wait_us(1); |
wim | 0:5eb5fee234e8 | 275 | |
wim | 0:5eb5fee234e8 | 276 | _spi.write(_flip(LC75711_ADDRESS)); // Address |
wim | 0:5eb5fee234e8 | 277 | |
wim | 0:5eb5fee234e8 | 278 | _cs=1; // Latch Address, Prepare to send Command & Params |
wim | 0:5eb5fee234e8 | 279 | wait_us(1); |
wim | 0:5eb5fee234e8 | 280 | |
wim | 0:5eb5fee234e8 | 281 | _spi.write(_flip(data0)); // B0..B7 |
wim | 0:5eb5fee234e8 | 282 | |
wim | 0:5eb5fee234e8 | 283 | _spi.write(_flip(data1)); // B8..B15 |
wim | 0:5eb5fee234e8 | 284 | |
wim | 0:5eb5fee234e8 | 285 | _spi.write(_flip(cmd)); // B16..B23, Command register & value |
wim | 0:5eb5fee234e8 | 286 | |
wim | 0:5eb5fee234e8 | 287 | wait_us(1); |
wim | 0:5eb5fee234e8 | 288 | _cs=0; // Latch Command & Params |
wim | 0:5eb5fee234e8 | 289 | |
wim | 0:5eb5fee234e8 | 290 | wait_us(delay); // Command Delay |
wim | 0:5eb5fee234e8 | 291 | } |
wim | 0:5eb5fee234e8 | 292 | |
wim | 0:5eb5fee234e8 | 293 | |
wim | 0:5eb5fee234e8 | 294 | /** Helper to reverse all command or databits. The LC75711 expects LSB first, whereas SPI is MSB first |
wim | 1:bcf010fcacae | 295 | * |
wim | 0:5eb5fee234e8 | 296 | * @param char data |
wim | 0:5eb5fee234e8 | 297 | * @return bitreversed data |
wim | 0:5eb5fee234e8 | 298 | */ |
wim | 0:5eb5fee234e8 | 299 | char LC75711::_flip(char data) { |
wim | 0:5eb5fee234e8 | 300 | char value=0; |
wim | 0:5eb5fee234e8 | 301 | |
wim | 0:5eb5fee234e8 | 302 | if (data & 0x01) {value |= 0x80;} ; |
wim | 0:5eb5fee234e8 | 303 | if (data & 0x02) {value |= 0x40;} ; |
wim | 0:5eb5fee234e8 | 304 | if (data & 0x04) {value |= 0x20;} ; |
wim | 0:5eb5fee234e8 | 305 | if (data & 0x08) {value |= 0x10;} ; |
wim | 0:5eb5fee234e8 | 306 | if (data & 0x10) {value |= 0x08;} ; |
wim | 0:5eb5fee234e8 | 307 | if (data & 0x20) {value |= 0x04;} ; |
wim | 0:5eb5fee234e8 | 308 | if (data & 0x40) {value |= 0x02;} ; |
wim | 0:5eb5fee234e8 | 309 | if (data & 0x80) {value |= 0x01;} ; |
wim | 0:5eb5fee234e8 | 310 | return value; |
wim | 0:5eb5fee234e8 | 311 | } |
wim | 0:5eb5fee234e8 | 312 | |
wim | 0:5eb5fee234e8 | 313 | |
wim | 0:5eb5fee234e8 | 314 | |
wim | 0:5eb5fee234e8 | 315 | |
wim | 0:5eb5fee234e8 | 316 | #if (ASTON_TEST == 1) |
wim | 0:5eb5fee234e8 | 317 | |
wim | 0:5eb5fee234e8 | 318 | /** Constructor for class for Sanyo LC75711 VFD controller as used in ASTON |
wim | 0:5eb5fee234e8 | 319 | * |
wim | 0:5eb5fee234e8 | 320 | * @brief Supports 10 Grids of 35 Segments without additional Segments and uses Grid 11 for Icon segments. |
wim | 0:5eb5fee234e8 | 321 | * |
wim | 0:5eb5fee234e8 | 322 | * @param PinName mosi, miso, sclk, cs SPI bus pins |
wim | 0:5eb5fee234e8 | 323 | */ |
wim | 0:5eb5fee234e8 | 324 | LC75711_ASTON::LC75711_ASTON(PinName mosi, PinName sclk, PinName cs) : LC75711(mosi, sclk, cs, Grid11_Add8) { |
wim | 0:5eb5fee234e8 | 325 | _column = 0; |
wim | 0:5eb5fee234e8 | 326 | _columns = ASTON_NR_DIGITS; |
wim | 0:5eb5fee234e8 | 327 | |
wim | 0:5eb5fee234e8 | 328 | // Clear the _udc_icon (should be cleared at Reset) |
wim | 0:5eb5fee234e8 | 329 | // for (int idx=0; idx < 7; idx++) { |
wim | 0:5eb5fee234e8 | 330 | // _udc_icon = 0x00; |
wim | 0:5eb5fee234e8 | 331 | // } |
wim | 0:5eb5fee234e8 | 332 | } |
wim | 0:5eb5fee234e8 | 333 | |
wim | 0:5eb5fee234e8 | 334 | /** Locate cursor to a screen column |
wim | 0:5eb5fee234e8 | 335 | * |
wim | 0:5eb5fee234e8 | 336 | * @param column The horizontal position from the left, indexed from 0 |
wim | 1:bcf010fcacae | 337 | * @return none |
wim | 0:5eb5fee234e8 | 338 | */ |
wim | 0:5eb5fee234e8 | 339 | void LC75711_ASTON::locate(int column) { |
wim | 0:5eb5fee234e8 | 340 | //sanity check |
wim | 0:5eb5fee234e8 | 341 | if (column < 0) {column = 0;} |
wim | 0:5eb5fee234e8 | 342 | if (column > (_columns - 1)) {column = _columns - 1;} |
wim | 0:5eb5fee234e8 | 343 | |
wim | 0:5eb5fee234e8 | 344 | _column = column; |
wim | 0:5eb5fee234e8 | 345 | } |
wim | 0:5eb5fee234e8 | 346 | |
wim | 0:5eb5fee234e8 | 347 | |
wim | 0:5eb5fee234e8 | 348 | /** Number of screen columns |
wim | 0:5eb5fee234e8 | 349 | * |
wim | 0:5eb5fee234e8 | 350 | * @param none |
wim | 0:5eb5fee234e8 | 351 | * @return columns |
wim | 0:5eb5fee234e8 | 352 | */ |
wim | 0:5eb5fee234e8 | 353 | int LC75711_ASTON::columns() { |
wim | 0:5eb5fee234e8 | 354 | return _columns; |
wim | 0:5eb5fee234e8 | 355 | } |
wim | 0:5eb5fee234e8 | 356 | |
wim | 0:5eb5fee234e8 | 357 | |
wim | 0:5eb5fee234e8 | 358 | /** Clear the screen and locate to 0 |
wim | 1:bcf010fcacae | 359 | * |
wim | 0:5eb5fee234e8 | 360 | * @param bool clrAll Clear Icons also (default = false) |
wim | 1:bcf010fcacae | 361 | * @return none |
wim | 0:5eb5fee234e8 | 362 | */ |
wim | 0:5eb5fee234e8 | 363 | void LC75711_ASTON::cls(bool clrAll) { |
wim | 0:5eb5fee234e8 | 364 | |
wim | 0:5eb5fee234e8 | 365 | for (int cnt=0; cnt<ASTON_NR_DIGITS; cnt++) { |
wim | 0:5eb5fee234e8 | 366 | writeData(char (' '), cnt); // data |
wim | 0:5eb5fee234e8 | 367 | } |
wim | 0:5eb5fee234e8 | 368 | |
wim | 0:5eb5fee234e8 | 369 | if (clrAll) { |
wim | 0:5eb5fee234e8 | 370 | for (int cnt=0; cnt<ASTON_NR_DIGITS; cnt++) { |
wim | 0:5eb5fee234e8 | 371 | writeAData(0x00, cnt); // adata |
wim | 0:5eb5fee234e8 | 372 | } |
wim | 0:5eb5fee234e8 | 373 | |
wim | 0:5eb5fee234e8 | 374 | //Clear Icons |
wim | 0:5eb5fee234e8 | 375 | // |
wim | 0:5eb5fee234e8 | 376 | } |
wim | 0:5eb5fee234e8 | 377 | |
wim | 0:5eb5fee234e8 | 378 | _column = 0; |
wim | 0:5eb5fee234e8 | 379 | } |
wim | 0:5eb5fee234e8 | 380 | |
wim | 0:5eb5fee234e8 | 381 | |
wim | 0:5eb5fee234e8 | 382 | /** Set Icon |
wim | 0:5eb5fee234e8 | 383 | * |
wim | 0:5eb5fee234e8 | 384 | * @param Icon Enums Icon Encodes UDC_0 byte index in 8 MSBs and encodes Icon bit/segment in 8 LSBs |
wim | 0:5eb5fee234e8 | 385 | * @return none |
wim | 0:5eb5fee234e8 | 386 | */ |
wim | 0:5eb5fee234e8 | 387 | void LC75711_ASTON::setIcon(Icon icon){ |
wim | 0:5eb5fee234e8 | 388 | int byte_idx, bits; |
wim | 0:5eb5fee234e8 | 389 | |
wim | 0:5eb5fee234e8 | 390 | byte_idx = (icon >> 8) & 0x07; // Decode byte index and sanity mask |
wim | 0:5eb5fee234e8 | 391 | bits = (1 << (icon & 0x07)) & 0x1F; // Decode bits and sanity mask |
wim | 0:5eb5fee234e8 | 392 | |
wim | 0:5eb5fee234e8 | 393 | //Set the segment bit for the Icon |
wim | 0:5eb5fee234e8 | 394 | _udc_icon[byte_idx] |= bits; |
wim | 0:5eb5fee234e8 | 395 | |
wim | 0:5eb5fee234e8 | 396 | //Update UDC_0 used to display the Icons at Grid 11 |
wim | 0:5eb5fee234e8 | 397 | setUDC(0, _udc_icon); |
wim | 0:5eb5fee234e8 | 398 | } |
wim | 0:5eb5fee234e8 | 399 | |
wim | 0:5eb5fee234e8 | 400 | /** Clr Icon |
wim | 0:5eb5fee234e8 | 401 | * |
wim | 0:5eb5fee234e8 | 402 | * @param Icon Enums Icon Encodes UDC_0 byte index in 8 MSBs and encodes Icon bit/segment in 8 LSBs |
wim | 0:5eb5fee234e8 | 403 | * @return none |
wim | 0:5eb5fee234e8 | 404 | */ |
wim | 0:5eb5fee234e8 | 405 | void LC75711_ASTON::clrIcon(Icon icon) { |
wim | 0:5eb5fee234e8 | 406 | int byte_idx, bits; |
wim | 0:5eb5fee234e8 | 407 | |
wim | 0:5eb5fee234e8 | 408 | byte_idx = (icon >> 8) & 0x07; // Decode byte index and sanity mask |
wim | 0:5eb5fee234e8 | 409 | bits = (1 << (icon & 0x07)) & 0x1F; // Decode bits and sanity mask |
wim | 0:5eb5fee234e8 | 410 | |
wim | 0:5eb5fee234e8 | 411 | //Clear the segment bit for the Icon |
wim | 0:5eb5fee234e8 | 412 | _udc_icon[byte_idx] &= ~bits; |
wim | 0:5eb5fee234e8 | 413 | |
wim | 0:5eb5fee234e8 | 414 | //Update UDC_0 used to display the Icons at Grid 11 |
wim | 0:5eb5fee234e8 | 415 | setUDC(0, _udc_icon); |
wim | 0:5eb5fee234e8 | 416 | } |
wim | 0:5eb5fee234e8 | 417 | |
wim | 0:5eb5fee234e8 | 418 | /** Write a single character (Stream implementation) |
wim | 1:bcf010fcacae | 419 | * |
wim | 1:bcf010fcacae | 420 | * @param value char to print |
wim | 1:bcf010fcacae | 421 | * @return value; |
wim | 0:5eb5fee234e8 | 422 | */ |
wim | 0:5eb5fee234e8 | 423 | int LC75711_ASTON::_putc(int value) { |
wim | 0:5eb5fee234e8 | 424 | int addr; |
wim | 0:5eb5fee234e8 | 425 | |
wim | 0:5eb5fee234e8 | 426 | if ((value == '\n') || (value == '\r')) { |
wim | 0:5eb5fee234e8 | 427 | //No character to write |
wim | 0:5eb5fee234e8 | 428 | |
wim | 0:5eb5fee234e8 | 429 | //Update Cursor |
wim | 0:5eb5fee234e8 | 430 | _column = 0; |
wim | 0:5eb5fee234e8 | 431 | } |
wim | 0:5eb5fee234e8 | 432 | else if ((value >= 0) && (value < 192)) { |
wim | 0:5eb5fee234e8 | 433 | //Character to write |
wim | 0:5eb5fee234e8 | 434 | |
wim | 0:5eb5fee234e8 | 435 | //Translate between _column and displaybuffer entries |
wim | 0:5eb5fee234e8 | 436 | //Note that the ASTON has 1 digit/grids. |
wim | 0:5eb5fee234e8 | 437 | //_column == 0 => Grid10 => addr = 9 |
wim | 0:5eb5fee234e8 | 438 | //_column == 1 => Grid9 => addr = 8 |
wim | 0:5eb5fee234e8 | 439 | // .... |
wim | 0:5eb5fee234e8 | 440 | //_column == 9 => Grid1 => addr = 0 |
wim | 0:5eb5fee234e8 | 441 | addr = (9 - _column); // 1 Byte for every Grid; |
wim | 0:5eb5fee234e8 | 442 | |
wim | 0:5eb5fee234e8 | 443 | writeData(value, addr); |
wim | 0:5eb5fee234e8 | 444 | |
wim | 0:5eb5fee234e8 | 445 | //Update Cursor |
wim | 0:5eb5fee234e8 | 446 | _column++; |
wim | 0:5eb5fee234e8 | 447 | if (_column > (ASTON_NR_DIGITS - 1)) { |
wim | 0:5eb5fee234e8 | 448 | _column = 0; |
wim | 0:5eb5fee234e8 | 449 | } |
wim | 0:5eb5fee234e8 | 450 | |
wim | 0:5eb5fee234e8 | 451 | } // if validChar |
wim | 0:5eb5fee234e8 | 452 | |
wim | 0:5eb5fee234e8 | 453 | return value; |
wim | 0:5eb5fee234e8 | 454 | } |
wim | 0:5eb5fee234e8 | 455 | |
wim | 1:bcf010fcacae | 456 | /** Get a single character (Stream implementation) |
wim | 1:bcf010fcacae | 457 | * |
wim | 1:bcf010fcacae | 458 | * @param none |
wim | 1:bcf010fcacae | 459 | * @return -1 |
wim | 1:bcf010fcacae | 460 | */ |
wim | 0:5eb5fee234e8 | 461 | int LC75711_ASTON::_getc() { |
wim | 0:5eb5fee234e8 | 462 | return -1; |
wim | 0:5eb5fee234e8 | 463 | } |
wim | 0:5eb5fee234e8 | 464 | #endif |