Sanyo LC75711 VFD controller/driver for upto 16 Dot Matrix Characters

Dependents:   mbed_LC75711

The component page is here.

Committer:
wim
Date:
Tue Sep 12 18:36:56 2017 +0000
Revision:
0:5eb5fee234e8
Child:
1:bcf010fcacae
LC75711 VFD Driver

Who changed what in which revision?

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