Sanyo LC75711 VFD controller/driver for upto 16 Dot Matrix Characters
The component page is here.
Revision 0:5eb5fee234e8, committed 2017-09-12
- Comitter:
- wim
- Date:
- Tue Sep 12 18:36:56 2017 +0000
- Child:
- 1:bcf010fcacae
- Commit message:
- LC75711 VFD Driver
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LC75711.cpp Tue Sep 12 18:36:56 2017 +0000 @@ -0,0 +1,441 @@ +/* mbed LC75710 Library, for Sanyo LC7571X VFD controller + * Note: The LC75710, LC75711 and LC75712 differ only in the built-in character ROM + * + * Copyright (c) 2017, v01: WH, Initial version + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "mbed.h" +#include "LC75711.h" +#include "LC75711_UDC.inc" + + + /** Constructor for class for driving Sanyo LC75711 VFD controller + * + * @brief Supports upto 16 Grids of 35 matrix segments. Also supports 3-8 additional segments (depending on number of grids). + * SPI bus interface device. + * @param PinName mosi, sclk, cs SPI bus pins + * @param Mode selects number of Grids and Segments (default 11 Grids, 35 matrix segments, 8 additional segments) + */ +LC75711::LC75711(PinName mosi, PinName sclk, PinName cs, Mode mode) : _spi(mosi,NC,sclk), _cs(cs), _mode(mode) { + + _init(); +} + +/** Init the LC75711 interface and the controller + * @param none + * @return none + */ +void LC75711::_init(){ + +//init SPI + _cs=0; + _spi.format(8,0); //LC75711 uses mode 0 (Clock Low on Idle, Data latched on first (=rising) edge) +// _spi.frequency(100000); + _spi.frequency(250000); + +//init controller + + // Set number of Grids + _writeCmd((LC75711_GRID_REG | _mode), // B16..B23, Command register & value + 0x00, // B8..B15, Dummy + 0x00, // B0..B7, Dummy + LC75711_GRID_DLY); // Command Delay + + _setAddress(0, 0); // No shift + + setBlink(false); // No Blink + setBrightness(LC75711_BRT_DEF); // Default Brightness + + // Clear the DCRAM (undefined at Reset) + cls(); + + // Clear the UDC RAM (undefined at Reset) + const char udc_none[] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00}; + for (int idx=0; idx < LC75711_NR_UDC; idx++) { + setUDC(idx, (char *)udc_none); + } + + setDisplay(true); // Display On +} + + +/** Clear the screen and locate to 0 + */ +void LC75711::cls() { + + for (int cnt=0; cnt<LC75711_DISPLAY_MEM; cnt++) { + writeData(char (' '), cnt); // data +// writeData(0x00, cnt); // data + } + + for (int cnt=0; cnt<LC75711_ADD_MEM; cnt++) { + writeData(0x00, cnt); // adata + } +} + +/** Set the Blink mode + * + * @param bool Blink mode + * @param int grids selected grids for Blinking enable/disable (default = all) + */ +void LC75711::setBlink(bool on, int grids) { + + // Sanity check and update of local shadow + if (on) { + _blink = _blink | (grids & LC75711_GR_MSK); // Set grid bits + } + else { + _blink = _blink & ~(grids & LC75711_GR_MSK); // Clr grid bits + } + + _writeCmd((LC75711_BLNK_REG | LC75711_BLNK_ON), // B16..B23, Command register & value + ((_blink >> 8) & 0xFF), // B8..B15, GR8..GR16 + ( _blink & 0xFF), // B0..B7, GR1..GR7 + LC75711_BLNK_DLY); // Command Delay +} + + +/** Set Brightness + * + * @param char brightness (8 significant bits, valid range 0..239 (dutycycle linked to number of grids) + * @return none + */ +void LC75711::setBrightness(char brightness){ + +//Sanity check + brightness = brightness & LC75711_BRT_MSK; // mask invalid bits + if (brightness > 239) {brightness = 239;} + + _writeCmd((LC75711_BRT_REG), // B16..B23, Command register + brightness, // B8..B15, Brightness + 0x00, // B0..B7, Dummy + LC75711_BRT_DLY); // Command Delay +} + +/** Set the Display mode On/off + * + * @param bool display mode + */ +void LC75711::setDisplay(bool on) { + char display; + + if (on) { + display = LC75711_DSPL_ON; + } + else { + display = LC75711_DSPL_OFF; + } + + _writeCmd((LC75711_DSPL_REG | display), // B16..B23, Command register & value + 0xFF, // B8..B15, GR8..GR16 + 0xFF, // B0..B7, GR1..GR7 + LC75711_DSPL_DLY); // Command Delay +} + + +/** Set User Defined Characters (UDC) + * + * @param unsigned char udc_idx The Index of the UDC (0..7) + * @param UDCData_t udc_data The bitpattern for the UDC (7 bytes) + */ +void LC75711::setUDC(unsigned char udc_idx, UDCData_t udc_data) { + char data; + +//Sanity check + udc_idx = udc_idx & LC75711_UDC_MSK; // mask invalid bits + + _cs=0; // Prepare to send Address + wait_us(1); + + _spi.write(_flip(LC75711_ADDRESS)); // Address + + _cs=1; // Latch Address, Prepare to send Command & Params + wait_us(1); + + data = ((udc_data[1] & 0x07) << 5) | ((udc_data[0] & 0x1F) << 0); + _spi.write(_flip(data)); // B0..B7, AM1-AM8 + + data = ((udc_data[3] & 0x01) << 7) | ((udc_data[2] & 0x1F) << 2) | ((udc_data[1] & 0x18) >> 3); + _spi.write(_flip(data)); // B8..B15, AM9-AM16 + + data = ((udc_data[4] & 0x0F) << 4) | ((udc_data[3] & 0x1E) >> 1); + _spi.write(_flip(data)); // B16..B23, AM17-AM24 + + data = ((udc_data[6] & 0x03) << 6) | ((udc_data[5] & 0x1F) << 1) | ((udc_data[4] & 0x10) >> 4); + _spi.write(_flip(data)); // B24..B31, AM25-AM32 + + data = ((udc_data[6] & 0x1C) >> 2); + _spi.write(_flip(data)); // B32..B39, AM32-AM35 + + _spi.write(_flip(udc_idx)); // B40..B47, CA0-CA7 + + _spi.write(_flip(LC75711_UDC_REG)); // B48..B55, Command register + + wait_us(1); + _cs=0; // Latch Command & Params + + wait_us(LC75711_UDC_DLY); // Command Delay +} + + +/** Write Data to LC75711 + * @Param char data Character code + * @Param char address Parameter for data + * @return none + */ +void LC75711::writeData(char data, char address){ + +//Sanity check + address = address & LC75711_DADR_MSK; // mask invalid bits + + _writeCmd((LC75711_DATA_REG), // B16..B23, Command register + address, // B8..B15, DCRAM address + data, // B0..B7, Character code + LC75711_DATA_DLY); // Command Delay +} + +/** Write Additional Data to LC75711 + * @Param char adata Additional code (annunciator) + * @Param char address Parameter for data + * @return none + */ +void LC75711::writeAData(char adata, char address){ + +//Sanity check + address = address & LC75711_AADR_MSK; // mask invalid bits + + _writeCmd((LC75711_ADAT_REG | address), // B16..B23, Command register & ADRAM address + adata, // B8..B15, ADATA + 0x00, // B0..B7, Dummy + LC75711_ADAT_DLY); // Command Delay +} + + +/** Set Address + * @Param char RAM address for data displayed at Grid1 (0..63) + * @Param char RAM address for adata displayed at Grid1 (0..15) + * @return none + * + * Note that a Shift (L/R) command will change the Address of data displayed at Grid1 + */ +void LC75711::_setAddress(char data_addr, char adata_addr){ + +//Sanity check + data_addr = data_addr & LC75711_DADR_MSK; // mask invalid bits + adata_addr = adata_addr & LC75711_AADR_MSK; // mask invalid bits + + _writeCmd((LC75711_AC_REG | adata_addr), // B16..B23, Command register & ADRAM address + data_addr, // B8..B15, DCRAM address + 0x00, // B0..B7, Dummy + LC75711_AC_DLY); // Command Delay +} + + +/** Write command and parameters to LC75711 + * @Param char cmd Command byte + * @Param char data1 Parameters for command + * @Param char data0 Parameters for command + * @Param char delay Delay for command execution + * @return none + */ +void LC75711::_writeCmd(char cmd, char data1, char data0, char delay){ + + _cs=0; // Prepare to send Address + wait_us(1); + + _spi.write(_flip(LC75711_ADDRESS)); // Address + + _cs=1; // Latch Address, Prepare to send Command & Params + wait_us(1); + + _spi.write(_flip(data0)); // B0..B7 + + _spi.write(_flip(data1)); // B8..B15 + + _spi.write(_flip(cmd)); // B16..B23, Command register & value + + wait_us(1); + _cs=0; // Latch Command & Params + + wait_us(delay); // Command Delay +} + + +/** Helper to reverse all command or databits. The LC75711 expects LSB first, whereas SPI is MSB first + * @param char data + * @return bitreversed data + */ +char LC75711::_flip(char data) { + char value=0; + + if (data & 0x01) {value |= 0x80;} ; + if (data & 0x02) {value |= 0x40;} ; + if (data & 0x04) {value |= 0x20;} ; + if (data & 0x08) {value |= 0x10;} ; + if (data & 0x10) {value |= 0x08;} ; + if (data & 0x20) {value |= 0x04;} ; + if (data & 0x40) {value |= 0x02;} ; + if (data & 0x80) {value |= 0x01;} ; + return value; +} + + + + +#if (ASTON_TEST == 1) + +/** Constructor for class for Sanyo LC75711 VFD controller as used in ASTON + * + * @brief Supports 10 Grids of 35 Segments without additional Segments and uses Grid 11 for Icon segments. + * + * @param PinName mosi, miso, sclk, cs SPI bus pins + */ +LC75711_ASTON::LC75711_ASTON(PinName mosi, PinName sclk, PinName cs) : LC75711(mosi, sclk, cs, Grid11_Add8) { + _column = 0; + _columns = ASTON_NR_DIGITS; + + // Clear the _udc_icon (should be cleared at Reset) +// for (int idx=0; idx < 7; idx++) { +// _udc_icon = 0x00; +// } +} + +/** Locate cursor to a screen column + * + * @param column The horizontal position from the left, indexed from 0 + */ +void LC75711_ASTON::locate(int column) { + //sanity check + if (column < 0) {column = 0;} + if (column > (_columns - 1)) {column = _columns - 1;} + + _column = column; +} + + +/** Number of screen columns + * + * @param none + * @return columns + */ +int LC75711_ASTON::columns() { + return _columns; +} + + +/** Clear the screen and locate to 0 + * @param bool clrAll Clear Icons also (default = false) + */ +void LC75711_ASTON::cls(bool clrAll) { + + for (int cnt=0; cnt<ASTON_NR_DIGITS; cnt++) { + writeData(char (' '), cnt); // data + } + + if (clrAll) { + for (int cnt=0; cnt<ASTON_NR_DIGITS; cnt++) { + writeAData(0x00, cnt); // adata + } + + //Clear Icons + // + } + + _column = 0; +} + + +/** Set Icon + * + * @param Icon Enums Icon Encodes UDC_0 byte index in 8 MSBs and encodes Icon bit/segment in 8 LSBs + * @return none + */ +void LC75711_ASTON::setIcon(Icon icon){ + int byte_idx, bits; + + byte_idx = (icon >> 8) & 0x07; // Decode byte index and sanity mask + bits = (1 << (icon & 0x07)) & 0x1F; // Decode bits and sanity mask + + //Set the segment bit for the Icon + _udc_icon[byte_idx] |= bits; + + //Update UDC_0 used to display the Icons at Grid 11 + setUDC(0, _udc_icon); +} + +/** Clr Icon + * + * @param Icon Enums Icon Encodes UDC_0 byte index in 8 MSBs and encodes Icon bit/segment in 8 LSBs + * @return none + */ +void LC75711_ASTON::clrIcon(Icon icon) { + int byte_idx, bits; + + byte_idx = (icon >> 8) & 0x07; // Decode byte index and sanity mask + bits = (1 << (icon & 0x07)) & 0x1F; // Decode bits and sanity mask + + //Clear the segment bit for the Icon + _udc_icon[byte_idx] &= ~bits; + + //Update UDC_0 used to display the Icons at Grid 11 + setUDC(0, _udc_icon); +} + +/** Write a single character (Stream implementation) + */ +int LC75711_ASTON::_putc(int value) { + int addr; + + if ((value == '\n') || (value == '\r')) { + //No character to write + + //Update Cursor + _column = 0; + } + else if ((value >= 0) && (value < 192)) { + //Character to write + + //Translate between _column and displaybuffer entries + //Note that the ASTON has 1 digit/grids. + //_column == 0 => Grid10 => addr = 9 + //_column == 1 => Grid9 => addr = 8 + // .... + //_column == 9 => Grid1 => addr = 0 + addr = (9 - _column); // 1 Byte for every Grid; + + writeData(value, addr); + + //Update Cursor + _column++; + if (_column > (ASTON_NR_DIGITS - 1)) { + _column = 0; + } + + } // if validChar + + return value; +} + +// get a single character (Stream implementation) +int LC75711_ASTON::_getc() { + return -1; +} +#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LC75711.h Tue Sep 12 18:36:56 2017 +0000 @@ -0,0 +1,618 @@ +/* mbed LC75710 Library, for Sanyo LC7571X VFD controller + * Note: The LC75710, LC75711 and LC75712 differ only in the built-in character ROM + * + * Copyright (c) 2017, v01: WH, Initial version + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef LC75711_H +#define LC75711_H + +// Select one of the testboards for Sanyo LC75711 VFD controller +#include "LC75711_Config.h" +#include "LC75711_UDC.h" + +/** An interface for driving Sanyo LC75711 VFD controller + * + * @code + * + * #if (LC75711_TEST == 1) + * // Direct driving of LC75711 Test + * + * #include "mbed.h" + * #include "LC75711.h" + * + * DigitalOut myled(LED1); + * Serial pc(USBTX, USBRX); + * + * // LC75711 declaration, Default setting 16 Grids @ 35 Segments + * LC75711 LC75711(p5, p7, p8); // DI, CLK, CS + * + * int main() { + * pc.printf("Hello World: LC75711 test\n\r"); + * + * LC75711.cls(); + * LC75711.writeData(all_str); + * wait(4); + * LC75711.setBrightness(LC75711_BRT0); + * wait(1); + * LC75711.setBrightness(LC75711_BRT3); + * + * LC75711.writeData((char)'H', 9); + * LC75711.writeData((char)'e', 8); + * LC75711.writeData((char)'l', 7); + * LC75711.writeData((char)'l', 6); + * LC75711.writeData((char)'o', 5); + * + * while(1) { + * myled = !myled; + * wait(1); + * } + * } + * #endif + * + * @endcode + */ + + +//LC75711 Display and Annunciator data +#define LC75711_MAX_NR_GRIDS 16 +#define LC75711_BYTES_PER_GRID 1 + +//Memory size in bytes for Display and Annunciators +#define LC75711_DISPLAY_MEM 64 +#define LC75711_ADD_MEM 16 +//#define LC75711_UDC_MEM 8 + +//Serial control data consists of an 8-bit address and a 24-bit instruction. The address is used as a chip select function +//when multiple ICs are connected to the same bus. The address for the LC75710NE series is only used to distinguish the device +//from different types of devices. Multiple LC75711 devices on the same bus can only be distinguised by the CE control. +//Note that the serial control is similar but not identical to SPI behaviour: +// The address is transmitted during CE low, the command & data is latched on falling CE edge. +// A wait time must be observed after each command. Typical delay is 18 us. +//Address (LSB sent first) +#define LC75711_ADDRESS 0x67 + + +// +//Blink command, allows individual digit control +// 1 0 1 M A BC2 BC1 BC0 GR16 ... GR1 +#define LC75711_BLNK_REG 0xA0 +#define LC75711_BLNK_MA_MSK 0x18 +#define LC75711_BLNK_BC_MSK 0x07 + +//Blinking Mode +// M A Display operating state +// 0 0 Neither MDATA nor ADATA blinks. +// 0 1 Only ADATA blinks. +// 1 0 Only MDATA blinks. +// 1 1 Both ADATA and MDATA blink. + +//Blinking Period in sec when fOSC is 2.7 MHz +// BC2 BC1 BC0 HEX +// 0 0 0 0 Blink operation is stopped. +// 0 0 1 1 0.1 +// 0 1 0 2 0.2 +// 0 1 1 3 0.3 +// 1 0 0 4 0.4 +// 1 0 1 5 0.5 +// 1 1 0 6 0.8 +// 1 1 1 7 1.0 +#define LC75711_BLNK_00 0x00 +#define LC75711_BLNK_01 0x01 +#define LC75711_BLNK_02 0x02 +#define LC75711_BLNK_03 0x03 +#define LC75711_BLNK_04 0x04 +#define LC75711_BLNK_05 0x05 +#define LC75711_BLNK_08 0x06 +#define LC75711_BLNK_10 0x07 + +#define LC75711_BLNK_ON (LC75711_BLNK_MA_MSK | LC75711_BLNK_08) +#define LC75711_BLNK_OFF (LC75711_BLNK_MA_MSK | LC75711_BLNK_00) + +//Grid selectors +#define LC75711_GR1 (1 << 0) +#define LC75711_GR2 (1 << 1) +#define LC75711_GR3 (1 << 2) +#define LC75711_GR4 (1 << 3) +#define LC75711_GR5 (1 << 4) +#define LC75711_GR6 (1 << 5) +#define LC75711_GR7 (1 << 6) +#define LC75711_GR8 (1 << 7) +#define LC75711_GR9 (1 << 8) +#define LC75711_GR10 (1 << 9) +#define LC75711_GR11 (1 << 10) +#define LC75711_GR12 (1 << 11) +#define LC75711_GR13 (1 << 12) +#define LC75711_GR14 (1 << 13) +#define LC75711_GR15 (1 << 14) +#define LC75711_GR16 (1 << 15) + +#define LC75711_GR_ALL (0xFFFF) +#define LC75711_GR_MSK (0xFFFF) + +//Blinking Command delay +#define LC75711_BLNK_DLY 18 + +// +//Display On/Off command, allows individual digit control +// 0 0 0 1 * M A O GR16 ... GRD1 +#define LC75711_DSPL_REG 0x10 +#define LC75711_DSPL_MA_MSK 0x06 +#define LC75711_DSPL_O_MSK 0x01 + +//On/Off Mode +// M A Display operating state +// 0 0 Both MDATA and ADATA off +// 0 1 Only ADATA on +// 1 0 Only MDATA on +// 1 1 Both ADATA and MDATA on + +//On/Off +// O Display state +// 0 Off +// 1 On + +#define LC75711_DSPL_ON (LC75711_DSPL_MA_MSK | LC75711_DSPL_O_MSK) +#define LC75711_DSPL_OFF (LC75711_DSPL_MA_MSK) + +//Display Command delay +#define LC75711_DSPL_DLY 18 + + +//Display shift is NOT USED +// This would screw up the correlation between column index and character position. +// It also screws up the correlation between character data and additional data. +// Note that chardata has 64 positions whereas adddata has 16 positions + +// +//Display shift command +// 0 0 1 0 * M A R/L ... +#define LC75711_SHFT_REG 0x20 +#define LC75711_SHFT_MA_MSK 0x06 +#define LC75711_SHFT_RL_MSK 0x01 + +// Shift Mode +// M A Display operating state +// 0 0 Neither MDATA and ADATA shift +// 0 1 Only ADATA +// 1 0 Only MDATA +// 1 1 Both ADATA and MDATA + +//Shift direction +// RL Display shift +// 0 Right +// 1 Left + +//Shift Command delay +#define LC75711_SHFT_DLY 18 + +// +//Grid control command +// 0 0 1 1 GN3 GN2 GN1 GN0 ... +#define LC75711_GRID_REG 0x30 +#define LC75711_GRID_MSK 0x0F + +//Grids +// +// GN3 GN2 GN1 GN0 +// 0 0 0 0 G1 to G16 +// 0 0 0 1 G1 +// 0 0 1 0 G1 to G2 +// 0 0 1 1 G1 to G3 +// 0 1 0 0 G1 to G4 +// 0 1 0 1 G1 to G5 +// 0 1 1 0 G1 to G6 +// 0 1 1 1 G1 to G7 +// 1 0 0 0 G1 to G8 +// 1 0 0 1 G1 to G9 +// 1 0 1 0 G1 to G10 +// 1 0 1 1 G1 to G11 +// 1 1 0 0 G1 to G12 +// 1 1 0 1 G1 to G13 +// 1 1 1 0 G1 to G14 +// 1 1 1 1 G1 to G15 +#define LC75711_GR1_GR1 0x01 +#define LC75711_GR1_GR2 0x02 +#define LC75711_GR1_GR3 0x03 +#define LC75711_GR1_GR4 0x04 +#define LC75711_GR1_GR5 0x05 +#define LC75711_GR1_GR6 0x06 +#define LC75711_GR1_GR7 0x07 +#define LC75711_GR1_GR8 0x08 +#define LC75711_GR1_GR9 0x09 +#define LC75711_GR1_GR10 0x0A +#define LC75711_GR1_GR11 0x0B +#define LC75711_GR1_GR12 0x0C +#define LC75711_GR1_GR13 0x0D +#define LC75711_GR1_GR14 0x0E +#define LC75711_GR1_GR15 0x0F +#define LC75711_GR1_GR16 0x00 + +//Grid Command delay +#define LC75711_GRID_DLY 1 + +// +//Set AC Address command +// 0 1 0 0 RA3 RA2 RA1 RA0 * * DA5 DA4 DA3 DA2 DA1 DA0 * * * * * * * * +#define LC75711_AC_REG 0x40 +#define LC75711_AADR_MSK 0x0F +#define LC75711_DADR_MSK 0x3F + +//RA3..RA0 ADRAM Address (Additional data) +//DA5..DA0 DCRAM Address (Character data) + +//AC Command delay +#define LC75711_AC_DLY 18 + +// +//Set Brightness command +// 0 1 0 1 * * * * DC7 DC6 DC5 DC4 DC3 DC2 DC1 DC0 * * * * * * * * +#define LC75711_BRT_REG 0x50 +#define LC75711_BRT_MSK 0xFF + +//DC7..DC0 Brightness Level (0..239) +//Note Brightness relationship between the number of active Grids (period) and the BRT value (duty cycle) +#define LC75711_BRT_0 0x00 +#define LC75711_BRT_1 0x20 +#define LC75711_BRT_2 0x40 +#define LC75711_BRT_3 0x80 +#define LC75711_BRT_4 0xA0 +#define LC75711_BRT_5 0xC0 +#define LC75711_BRT_6 0xD0 +#define LC75711_BRT_7 0xF0 + +#define LC75711_BRT_DEF (LC75711_BRT_3) + +//Brightness Command delay +#define LC75711_BRT_DLY 1 + +// +//Set Char data command (DCRAM) +// 0 1 1 0 * * * * * * DA5 DA4 DA3 DA2 DA1 DA0 D7...D0 +#define LC75711_DATA_REG 0x60 +//#define LC75711_DADR_MSK 0x3F +//#define LC75711_DATA_MSK 0xFF + +//AA5..DA0 DCRAM Address (Character data) +//DA7..DA0 Character Data + +//Set Data Command delay +#define LC75711_DATA_DLY 18 + +// +//Set Additional data command (ADRAM), Used for annunciators etc +// 0 1 1 1 RA3 RA2 RA1 RA0 AD8 AD7 AD6 AD5 AD4 AD3 AD2 AD1 * * * * * * * * +#define LC75711_ADAT_REG 0x70 + +//RA3..RA0 ADRAM Address (Additional data) +//#define LC75711_AADR_MSK 0x0F + +//AD8..AD1 Additional Data +#define LC75711_ADAT_MSK 0xFF + +//Set AData Command delay +#define LC75711_ADAT_DLY 18 + +// +//Set UDC data command (CGRAM) +// 1 0 0 0 * * * * CA7 CA6 ... CA0 +// +// * * * * * CD35 CD34 ... CD25 +// +// CD24 CD23 ... CD9 +// +// CD8 ... CD1 +#define LC75711_UDC_REG 0x80 +#define LC75711_UDC_MSK 0x0F +#define LC75711_NR_UDC 8 + +//CA7..CA0 CGRAM Address (UDC RAM address) +//CD35..CD0 UDC Data +//UDC is a 5x7 Matrix pattern +// CD1 .. CD5 +// CD6 .. CD10 +// CD11 .. CD15 +// CD16 .. CD20 +// CD21 .. CD25 +// CD26 .. CD30 +// CD31 .. CD35 + +//Set UDC Data Command delay +#define LC75711_UDC_DLY 18 + +//UDCs are defined by a 5x7 matrix and stored as 7 bytes +typedef char UDCData_t[7]; + + +/** A class for driving Sanyo LC75711 VFD controller + * + * @brief Supports upto 16 Grids of 35 matrix segments. Also supports 3-8 additional segments (depending on number of grids). + * SPI bus interface device. + */ +class LC75711 { + public: + + /** Enums for display mode */ + enum Mode { + Grid1_Add8 = LC75711_GR1_GR1, + Grid2_Add8 = LC75711_GR1_GR2, + Grid3_Add8 = LC75711_GR1_GR3, + Grid4_Add8 = LC75711_GR1_GR4, + Grid5_Add8 = LC75711_GR1_GR5, + Grid6_Add8 = LC75711_GR1_GR6, + Grid7_Add8 = LC75711_GR1_GR7, + Grid8_Add8 = LC75711_GR1_GR8, + Grid9_Add8 = LC75711_GR1_GR9, + Grid10_Add8 = LC75711_GR1_GR10, + Grid11_Add8 = LC75711_GR1_GR11, + Grid12_Add7 = LC75711_GR1_GR12, + Grid13_Add6 = LC75711_GR1_GR13, + Grid14_Add5 = LC75711_GR1_GR14, + Grid15_Add4 = LC75711_GR1_GR15, + Grid16_Add3 = LC75711_GR1_GR16 + }; + + /** Datatypes for display data */ +// typedef char DisplayData_t[LC75711_DISPLAY_MEM]; +// typedef char DisplayAdd_t[LC75711_ADD_MEM]; + + /** Constructor for class for driving Sanyo LC75711 VFD controller + * + * @brief Supports upto 16 Grids of 35 matrix segments. Also supports 3-8 additional segments (depending on number of grids). + * SPI bus interface device. + * @param PinName mosi, sclk, cs SPI bus pins + * @param Mode selects number of Grids and Segments (default 11 Grids, 35 matrix segments, 8 additional segments) + */ + LC75711(PinName mosi, PinName sclk, PinName cs, Mode mode = Grid11_Add8); + + /** Clear the screen and locate to 0 + */ + void cls(); + + /** Set the Blink mode + * + * @param bool blink mode + * @param int grids selected grids for Blinking enable/disable (default = all) + */ + void setBlink(bool on, int grids = LC75711_GR_ALL); + + /** Set Brightness + * + * @param char brightness (8 significant bits, valid range 0..239 (dutycycle linked to number of grids) + * @return none + */ + void setBrightness(char brightness = LC75711_BRT_DEF); + + /** Set the Display mode On/off + * + * @param bool display mode + */ + void setDisplay(bool on); + + + /** Set User Defined Characters (UDC) + * + * @param unsigned char udc_idx The Index of the UDC (0..7) + * @param UDCData_t udc_data The bitpattern for the UDC (7 bytes) + */ + void setUDC(unsigned char udc_idx, UDCData_t udc_data); + + + /** Write Data to LC75711 + * @Param char data Character code + * @Param char address Parameter for data + * @return none + */ + void writeData(char data, char address); + + /** Write Additional Data to LC75711 + * @Param char adata Additional code (annunciator) + * @Param char address Parameter for data + * @return none + */ + void writeAData(char adata, char address); + + + private: + SPI _spi; + DigitalOut _cs; + Mode _mode; + int _blink; // Local shadow + + /** Init the SPI interface and the controller + * @param none + * @return none + */ + void _init(); + + /** Helper to reverse all command or databits. The LC75711 expects LSB first, whereas SPI is MSB first + * @param char data + * @return bitreversed data + */ + char _flip(char data); + + + /** Set Address + * @Param char RAM address for data displayed at Grid1 (0..63) + * @Param char RAM address for adata displayed at Grid1 (0..15) + * @return none + * + * Note that a Shift (L/R) command will change the Address of data displayed at Grid1 + */ + void _setAddress(char data_addr=0, char adata_addr=0); + + + /** Write command and parameters to LC75711 + * @Param char cmd Command byte + * @Param char data1 Parameters for command + * @Param char data0 Parameters for command + * @Param char delay Delay for command execution + * @return none + */ + void _writeCmd(char cmd, char data1, char data0, char delay); + +}; + + +#if (ASTON_TEST == 1) +// Derived class for ASTON display unit +// Grids 1-10 all display 35 segment matrix characters and no Additional segments. +// Grid 11 uses a number of Segments to display Icons. + +//ASTON Display data +#define ASTON_NR_GRIDS 10 +#define ASTON_NR_DIGITS 10 +//#define ASTON_NR_UDC 8 + +//ASTON Memory size in bytes for Display +//#define ASTON_DISPLAY_MEM (ASTON_NR_GRIDS * LC75711_BYTES_PER_GRID) + + +/** Constructor for class for driving Sanyo LC75711 VFD controller as used in ASTON + * + * @brief Supports 10 Grids of 35 Segments without additional Segments and uses Grid 11 for Icon segments. + * + * @param PinName mosi, sclk, cs SPI bus pins + */ +class LC75711_ASTON : public LC75711, public Stream { + public: + + /** Enums for Icons + * + * @Brief Aston display uses Grid 11 to show Icons. + * The Icons are each connnected to one of the 35 segments. + * Icons are controlled by redefining UDC_0. + * Icon Enums encode UDC_0 byte index in 8 MSBs and encode Icon bit/segment in 8 LSBs + */ + enum Icon { + R0 = (6<<8) | 4, + R1 = (6<<8) | 3, + R2 = (6<<8) | 2, + R3 = (6<<8) | 1, + CRD1 = (5<<8) | 4, + CRD2 = (5<<8) | 3, + CARD = (5<<8) | 2, + KEY = (4<<8) | 1, + VDCRP = (4<<8) | 2, + D = (4<<8) | 0, + D2 = (3<<8) | 4, + MAC = (3<<8) | 3, + R16_9 = (0<<8) | 0, + DISH = (5<<8) | 0, + DSH1 = (4<<8) | 3, + DSH2 = (5<<8) | 1, + TMR = (1<<8) | 3, + CBND = (2<<8) | 1, + KBND = (2<<8) | 4, + AFC = (3<<8) | 0 + }; + + +/** Constructor for class for driving Sanyo LC75711 VFD controller as used in ASTON + * + * @brief Supports 10 Grids of 35 Segments without additional Segments and uses Grid 11 for Icon segments. + * + * @param PinName mosi, sclk, cs SPI bus pins + */ + LC75711_ASTON(PinName mosi, PinName sclk, PinName cs); + +#if DOXYGEN_ONLY + /** Write a character to the Display + * + * @param c The character to write to the display + */ + int putc(int c); + + /** Write a formatted string to the Display + * + * @param format A printf-style format string, followed by the + * variables to use in formatting the string. + */ + int printf(const char* format, ...); +#endif + + /** Locate cursor to a screen column + * + * @param column The horizontal position from the left, indexed from 0 + */ + void locate(int column); + + /** Clear the screen and locate to 0 + * @param bool clrAll Clear Icons also (default = false) + */ + void cls(bool clrAll = false); + + /** Set Icon + * + * @param Icon Enums Icon Encodes UDC_0 byte index in 8 MSBs and encodes Icon bit/segment in 8 LSBs + * @return none + */ + void setIcon(Icon icon); + + /** Clr Icon + * + * @param Icon Enums Icon Encodes UDC_0 byte index in 8 MSBs and encodes Icon bit/segment in 8 LSBs + * @return none + */ + void clrIcon(Icon icon); + + + /** Number of screen columns + * + * @param none + * @return columns + */ + int columns(); + + /** Write databyte to LC75711 + * @param int address display memory location to write byte + * @param char data byte written at given address + * @return none + */ +// void writeData(int address, char data){ +// LC75711::writeData(address, data); +// } + + /** Write Display datablock to LC75711 + * @param DisplayData_t data Array of LC75711_DISPLAY_MEM (=48) bytes for displaydata (starting at address 0) + * @param length number bytes to write (valid range 0..(ASTON_NR_GRIDS * LC75711_BYTES_PER_GRID) == 36, starting at address 0) + * @return none + */ +// void writeData(DisplayData_t data, int length = (ASTON_NR_GRIDS * LC75711_BYTES_PER_GRID)) { +// LC75711::writeData(data, length); +// } + +protected: + // Stream implementation functions + virtual int _putc(int value); + virtual int _getc(); + +private: + int _column; // Current cursor location + int _columns; // Max number of columns + +// DisplayData_t _displaybuffer; // Local mirror for all chars and icons +// UDCData_t _UDC_16S; // User Defined Character pattterns (UDC) + UDCData_t _udc_icon; // The UDC_0 bitpattern for the Icons shown at Grid 11 (7 bytes) +}; +#endif + +#endif \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LC75711_Config.h Tue Sep 12 18:36:56 2017 +0000 @@ -0,0 +1,35 @@ +/* mbed LC75710 Library, for Sanyo LC7571X VFD controller + * Note: The LC75710, LC75711 and LC75712 differ only in the built-in character ROM + * + * Copyright (c) 2017, v01: WH, Initial version + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef LC75711_CONFIG_H +#define LC75711_CONFIG_H + +// Select one of the testboards for Sanyo LC75711 VFD controller +#define LC75711_TEST 0 +#define ASTON_TEST 1 + +// Select if you want to include some UDC patterns +#define LC75711_UDC 1 + +#endif \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LC75711_UDC.h Tue Sep 12 18:36:56 2017 +0000 @@ -0,0 +1,69 @@ +/* mbed LC75710 Library, for Sanyo LC7571X VFD controller + * Note: The LC75710, LC75711 and LC75712 differ only in the built-in character ROM + * + * Copyright (c) 2017, v01: WH, Initial version + * 2017, v02: WH, Added some UDC definitions + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +#ifndef MBED_LC75711_UDC_H +#define MBED_LC75711_UDC_H + +#include "LC75711_Config.h" + +#if(LC75711_UDC == 1) +// User Defined Characters (UDCs) are defined by a 7 byte bitpattern. The P0..P5 form the character pattern. +// P7 P6 P5 P4 P3 P2 P1 P0 +// 0 x x x 0 1 1 1 0 +// 1 x x x 1 0 0 0 1 +// . ............. +// 6 x x x 1 0 0 0 1 +// +// Blinking UDCs are enabled when the specific Grid blink controlbit is set. +// +// Some sample User Defined Chars 5x7 dots */ +extern const char udc_Bat_Hi[]; // Battery Full +extern const char udc_Bat_Ha[]; // Battery Half +extern const char udc_Bat_Lo[]; // Battery Low +extern const char udc_checker[]; + +//extern const char udc_PO[]; //Padlock Open +//extern const char udc_PC[]; //Padlock Closed + +// +// NOTE: the patterns below still need to be flipped or the will be mirrored on the display... +// +//extern const char udc_ae[]; //æ +//extern const char udc_0e[]; //ø +//extern const char udc_ao[]; //å +//extern const char udc_AE[]; //Æ +//extern const char udc_0E[]; //Ø +//extern const char udc_Ao[]; //Å + +//extern const char udc_alpha[] //alpha +//extern const char udc_ohm[]; //ohm +//extern const char udc_sigma[]; //sigma +//extern const char udc_pi[]; //pi +//extern const char udc_root[]; //root + +//extern const char udc_TM_T[]; // Trademark T +//extern const char udc_TM_M[]; // Trademark M +#endif + +#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LC75711_UDC.inc Tue Sep 12 18:36:56 2017 +0000 @@ -0,0 +1,64 @@ +/* mbed LC75710 Library, for Sanyo LC7571X VFD controller + * Note: The LC75710, LC75711 and LC75712 differ only in the built-in character ROM + * + * Copyright (c) 2017, v01: WH, Initial version + * 2017, v02: WH, Added some UDC definitions + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +#include "LC75711_Config.h" + +#if(LC75711_UDC == 1) +// User Defined Characters (UDCs) are defined by a 7 byte bitpattern. The P0..P5 form the character pattern. +// P7 P6 P5 P4 P3 P2 P1 P0 +// 0 x x x 0 1 1 1 0 +// 1 x x x 1 0 0 0 1 +// . ............. +// 6 x x x 1 0 0 0 1 +// +// Blinking UDCs are enabled when the specific Grid blink controlbit is set. +// +// Some sample User Defined Chars 5x7 dots */ +const char udc_Bat_Hi[] = {0x0E, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F}; // Battery Full +const char udc_Bat_Ha[] = {0x0E, 0x11, 0x13, 0x17, 0x1F, 0x1F, 0x1F}; // Battery Half +const char udc_Bat_Lo[] = {0x0E, 0x11, 0x11, 0x11, 0x11, 0x11, 0x1F}; // Battery Low +const char udc_checker[] = {0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA}; + +//const char udc_PO[] = {0x04, 0x0A, 0x0A, 0x1F, 0x1B, 0x1B, 0x1F, 0x00}; //Padlock Open +//const char udc_PC[] = {0x1C, 0x10, 0x08, 0x1F, 0x1B, 0x1B, 0x1F, 0x00}; //Padlock Closed + +// +// NOTE: the patterns below still need to be flipped or the will be mirrored on the display... +// +//const char udc_ae[] = {0x00, 0x00, 0x1B, 0x05, 0x1F, 0x14, 0x1F, 0x00}; //æ +//const char udc_0e[] = {0x00, 0x00, 0x0E, 0x13, 0x15, 0x19, 0x0E, 0x00}; //ø +//const char udc_ao[] = {0x0E, 0x0A, 0x0E, 0x01, 0x0F, 0x11, 0x0F, 0x00}; //å +//const char udc_AE[] = {0x0F, 0x14, 0x14, 0x1F, 0x14, 0x14, 0x17, 0x00}; //Æ +//const char udc_0E[] = {0x0E, 0x13, 0x15, 0x15, 0x15, 0x19, 0x0E, 0x00}; //Ø +//const char udc_Ao[] = {0x0E, 0x0A, 0x0E, 0x11, 0x1F, 0x11, 0x11, 0x00}; //Å + +//const char udc_alpha[] = {0x00, 0x00, 0x0D, 0x12, 0x12, 0x12, 0x0D, 0x00}; //alpha +//const char udc_ohm[] = {0x0E, 0x11, 0x11, 0x11, 0x0A, 0x0A, 0x1B, 0x00}; //ohm +//const char udc_sigma[] = {0x1F, 0x08, 0x04, 0x02, 0x04, 0x08, 0x1F, 0x00}; //sigma +//const char udc_pi[] = {0x1F, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x00}; //pi +//const char udc_root[] = {0x07, 0x04, 0x04, 0x04, 0x14, 0x0C, 0x04, 0x00}; //root + +//const char udc_TM_T[] = {0x1F, 0x04, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00}; // Trademark T +//const char udc_TM_M[] = {0x11, 0x1B, 0x15, 0x11, 0x00, 0x00, 0x00, 0x00}; // Trademark M +#endif