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