diff --git a/HT1621.cpp b/HT1621.cpp
deleted file mode 100644
index 9d6a94f..0000000
--- a/HT1621.cpp
+++ /dev/null
@@ -1,266 +0,0 @@
-/**
- * \file HT1621.cpp
- * \brief Implementation of a class for dealing with the Holtek HT1621 chip.
- * \author Enrico Formenti
- * \date 31 january 2015
- * \version 1.0
- * \copyright BSD license, check the License page on the blog for more information. All this text must be
- * included in any redistribution.
- *
- * See macduino.blogspot.com for more details.
- *
- */
-
-#include "HT1621.h"
-
-byte setDigits( long number, byte *d, byte len ) // returns # of digits
-{
- static byte idx; // static stays
-
- long fullrange = number;
-
- if ( fullrange < 0L )
- {
- fullrange *= -1L;
- }
-
- for ( idx = 0; idx < len; idx++ )
- {
- d[ idx ] = 0;
- }
-
- // Here is the actual conversion to array
- idx = 0;
- while (( fullrange ) && ( idx < len ))
- {
- d[ idx++ ] = fullrange % 10;
- fullrange /= 10;
- }
- // Finished actual conversion to array
-
- if( number < 0 && idx < len ) {
- d[ idx++ ] = 11;
- }
-
-
- return idx;
-}
-
-void HT1621::clear(int places)
-{
- for (uint8_t i = 0; i < places; i++)
- write(i, 0);
-}
-
-void HT1621::flush()
-{
- clear();
-}
-
-void HT1621::begin()
-{
- pinMode(_DATA_pin, OUTPUT);
- pinMode(_RW_pin, OUTPUT);
- pinMode(_CS_pin, OUTPUT);
-
- digitalWrite(_CS_pin, HIGH);
- digitalWrite(_RW_pin, HIGH);
- digitalWrite(_DATA_pin, HIGH);
-
-#ifndef __HT1621_READ
- register uint8_t i;
-
- for(i=0; i<16; i++)
- ram[i] = 0;
-#endif
-
- delay(10);
- clear();
-
-}
-
-// OCIO !!!
-// nell'esempio dopo ogni write viene dato un delay
-// di 20 microsecondi...
-void HT1621::writeBits(uint8_t data, uint8_t cnt)
-{
- register uint8_t i;
-
- for(i=0;i
- * See macduino.blogspot.com for more details.
- *
- */
-
-
-#ifndef _HT1621_h
-#define _HT1621_h
-
-#if ARDUINO >= 100
-#include "Arduino.h"
-#else
-#include "WProgram.h"
-#endif
-
-#define TAKE_CS() digitalWrite(_CS_pin, LOW)
-#define RELEASE_CS() digitalWrite(_CS_pin, HIGH)
-
-
-// Uncomment the line below if you can read from the HT1621 directly
-// #define __HT1621_READ
-
-
-#define DECIMAL B00000001
- /*
- * a
- * -
- * f | | b
- * - <-g
- * e | | c
- * - . <-h
- * d
- *
- * f g e d a b c h
- * 1 1 1 1 1 1 1 1 (all on)
- *
- *
- */
-const word charMap[] = {
- B10111110, //0
- B00000110, //1
- B01111100, //2
- B01011110, //3
- B11000110, //4
- B11011010, //5
- B11110010, //6
- B00001110, //7
- B11111110, //8
- B11001110, //9
- B00000001, //10 '.'
- B01000000, //11 '-'
- B11001100, //12 'deg' (top o)
- B01110010, //13 'c'
-};
-
-byte setDigits( long number, byte *d, byte len );
-
-class HT1621 {
-private:
- uint8_t _CS_pin;
- uint8_t _DATA_pin;
- uint8_t _RW_pin;
-
-protected:
-
-#ifndef __HT1621_READ
- /**
- * \var ram[16]
- * This array is used to simulate the HT1621 internal ram whenever the read operations are not possible.
- * \warning Define the label __HT1621 to disable this feature and use standard read procedures.
- */
- uint8_t ram[16];
-#endif
-
-public:
- /*!
- * \enum Modes
- * Operating modes for the HT1621.
- */
- enum Modes : uint8_t {
- COMMAND_MODE = 0b10000000, /*!< This is used for sending standard commands. */
- READ_MODE = 0b11000000, /*!< This instructs the HT1621 to prepare for reading the internal RAM. */
- WRITE_MODE = 0b10100000, /*!< This instructs the HT1621 to prepare for writing the internal RAM. */
- READ_MODIFY_WRITE_MODE = 0b10100000, /*!< This instructs the HT1621 to prepare for reading/modifying batch of internal RAM adresses. */
- SPECIAL_MODE = 0b10010000 /*!< This instructs the HT1621 to prepare for executing a special command. */
- };
-
- /*!
- * \enum Commands
- *
- * This is an enum of available commands for the HT1621.
- *
- */
-
- enum Commands : uint8_t {
- SYS_DIS = 0b00000000, /*!< System disable. It stops the bias generator and the system oscillator. */
- SYS_EN = 0b00000010, /*!< System enable. It starts the bias generator and the system oscillator. */
- LCD_OFF = 0b00000100, /*!< Turn off the bias generator. */
- LCD_ON = 0b00000110, /*!< Turn on the bias generator. */
- TIMER_DIS = 0b00001000, /*!< Disable time base output. */
- WDT_DIS = 0b00001010, /*!< Watch-dog timer disable. */
- TIMER_EN = 0b00001100, /*!< Enable time base output. */
- WDT_EN = 0b00001110, /*!< Watch-dog timer enable. The timer is reset. */
- CLR_TIMER = 0b00011000, /*!< Clear the contents of the time base generator. */
- CLR_WDT = 0b00011100, /*!< Clear the contents of the watch-dog stage. */
-
- TONE_OFF = 0b00010000, /*!< Stop emitting the tone signal at the tone pin. \sa TONE2K, TONE4K */
- TONE_ON = 0b00010010, /*!< Start emitting tone signal at the tone pin. Tone frequency is selected using commands TONE2K or TONE4K. \sa TONE2K, TONE4K */
- TONE2K = 0b11000000, /*!< Output tone is at 2kHz. */
- TONE4K = 0b10000000, /*!< Output tone is at 4kHz. */
-
- RC256K = 0b00110000, /*!< System oscillator is the internal RC oscillator at 256kHz. */
- XTAL32K = 0b00101000, /*!< System oscillator is the crystal oscillator at 32768Hz. */
- EXT256K = 0b00111000, /*!< System oscillator is an external oscillator at 256kHz. */
-
- //Set bias to 1/2 or 1/3 cycle
- //Set to 2,3 or 4 connected COM lines
- BIAS_HALF_2_COM = 0b01000000, /*!< Use 1/2 bias and 2 commons. */
- BIAS_HALF_3_COM = 0b01001000, /*!< Use 1/2 bias and 3 commons. */
- BIAS_HALF_4_COM = 0b01010000, /*!< Use 1/2 bias and 4 commons. */
- BIAS_THIRD_2_COM = 0b01000010, /*!< Use 1/3 bias and 2 commons. */
- BIAS_THIRD_3_COM = 0b01001010, /*!< Use 1/3 bias and 3 commons. */
- BIAS_THIRD_4_COM = 0b01010010, /*!< Use 1/3 bias and 4 commons. */
-
- IRQ_EN = 0b00010000, /*!< Enables IRQ output. This needs to be excuted in SPECIAL_MODE. */
- IRQ_DIS = 0b00010000, /*!< Disables IRQ output. This needs to be excuted in SPECIAL_MODE. */
-
- // WDT configuration commands
- F1 = 0b01000000, /*!< Time base/WDT clock. Output = 1Hz. Time-out = 4s. This needs to be excuted in SPECIAL_MODE. */
- F2 = 0b01000010, /*!< Time base/WDT clock. Output = 2Hz. Time-out = 2s. This needs to be excuted in SPECIAL_MODE. */
- F4 = 0b01000100, /*!< Time base/WDT clock. Output = 4Hz. Time-out = 1s. This needs to be excuted in SPECIAL_MODE. */
- F8 = 0b01000110, /*!< Time base/WDT clock. Output = 8Hz. Time-out = .5s. This needs to be excuted in SPECIAL_MODE. */
- F16 = 0b01001000, /*!< Time base/WDT clock. Output = 16Hz. Time-out = .25s. This needs to be excuted in SPECIAL_MODE. */
- F32 = 0b01001010, /*!< Time base/WDT clock. Output = 32Hz. Time-out = .125s. This needs to be excuted in SPECIAL_MODE. */
- F64 = 0b01001100, /*!< Time base/WDT clock. Output = 64Hz. Time-out = .0625s. This needs to be excuted in SPECIAL_MODE. */
- F128 = 0b01001110, /*!< Time base/WDT clock. Output = 128Hz. Time-out = .03125s. This needs to be excuted in SPECIAL_MODE. */
-
- //Don't use
- TEST_ON = 0b11000000, /*!< Don't use! Only for manifacturers. This needs SPECIAL_MODE. */
- TEST_OFF = 0b11000110 /*!< Don't use! Only for manifacturers. This needs SPECIAL_MODE. */
- };
-
-
- /**
- * \fn HT1621(uint8_t CSpin, uint8_t RWpin, uint8_t DATApin)
- * \brief Constructor. Use begin() to complete the initialization of the chip.
- * @param \c CSpin Channel select pin.
- * @param \c RWpin Read/Write signal pin
- * @param \c DATApin Data pin both for reading or writing data.
- */
- HT1621(uint8_t CSpin, uint8_t RWpin, uint8_t DATApin) : _CS_pin(CSpin), _DATA_pin(DATApin), _RW_pin(RWpin) {};
- /**
- * \fn void begin(void)
- * \brief Init the HT1621. It inits the control bus. Moreover, it clears the (simulated) ram if \c __HT1621_READ is defined.
- */
- void begin(void);
- /**
- * \fn void writeBits(uint8_t data, uint8_t cnt)
- * \brief Send bits to the HT1621.
- * @param data Data to be sent to the HT1621 seen as an array of bits.
- * @param cnt Number of bits to send to the HT1621.
- * \warning In order to allow series of data to be sent CS is not taken by this function, so several writes can be issued in a row. You need to control CS by your own.
- * \warning There is no check on the size of cnt. Hence avoid ask to send more than 7 bits per time.
- * \sa readBits()
- */
- void writeBits(uint8_t data, uint8_t cnt);
- /**
- * \fn uint8_t readBits(uint8_t cnt)
- * \brief Reads bits from the HT1621.
- * @param cnt Number of bits to read. Maximal number of bits that can be read is 8.
- * \return uint8_t A byte containing the bits read. Last bit is the leftmost one.
- * \warning There is no check if too much bits are read. 0nly the last batch of 8 will be sent back.
- * \sa writeBits()
- */
- uint8_t readBits(uint8_t cnt);
- /**
- * \fn void sendCommand(uint8_t cmd, bool first = true, bool last = true)
- * \brief Sends a command to the HT1621.
- * @param cmd Id of the command to send.
- * @param first If true CS is taken.
- * @param last If true CS is relased.
- * \warning There is no check on the command id.
- */
- void sendCommand(uint8_t cmd, bool first = true, bool last = true);
- /**
- * \fn void write(uint8_t address, uint8_t data)
- * \brief Write \c data at the given address.
- * @param address Address to which write the data. Max address is 128.
- * @param data Data to be written. Remark that only the 4 less significative bits are used.
- * \warning There is no check to verify if the address is valid.
- */
- void write(uint8_t address, uint8_t data);
- /**
- * \fn void write(uint8_t address, uint8_t data, uint8_t cnt)
- * \brief Write \c data at the given address and at the \c cnt successive addresses.
- * @param address Address to which write the data. Max address is 128.
- * @param data Data to be written. Remark that only the 4 less significative bits are used.
- * @param cnt Number of times that \c data has to be written
- * \warning There is no check to verify if the address is valid. Moreover, pay attention that
- * the address \c (address+cnt) has also to be valid.
- */
- void write(uint8_t address, uint8_t data, uint8_t cnt);
- /**
- * \fn void write(uint8_t address, uint8_t *data, uint8_t cnt)
- * \brief Write \c cnt bytes starting at \c address and take data from buffer \c data.
- * @param address Address to which start writing data. Max address is 128.
- * @param data Buffer to be written.
- * @param cnt Length of the buffer.
- * \warning The buffer is byte aligned, so it is not very efficient. Indeed, only the 4 less significant
- * bits are written.
- * \warning There is no check that the buffer is of suitable length.
- */
- void write(uint8_t address, uint8_t *data, uint8_t cnt);
- /**
- * \fn read(uint8_t address)
- * \brief Read memory content at address \c address
- * @param address Memory address to read from.
- * \return uint8_t A byte contained the date read.
- * \warning There is no check to verify if the address is valid.
- */
- uint8_t read(uint8_t address);
- /**
- * \fn void read(uint8_t address, uint8_t *data, uint8_t cnt)
- * \brief Read \c cnt bytes starting from \c address into buffer \c data.
- * @param address Memory address to read from.
- * @param *data Buffer in which to store data read.
- * @param cnt Number of bytes to read.
- * \warning There is no check to verify if the address is valid.
- * \warning There is no check that the buffer is of suitable length.
- */
- void read(uint8_t address, uint8_t *data, uint8_t cnt);
-
- /*
- * write bytes
- */
- void writeChar(uint8_t address, uint8_t c, bool decimal = false);
-
- void printNumber(long number, int places, int dec = 0, bool flushdisplay = true);
-
- void printFloat(double number, int places, int decimalplaces = 2, bool flushdisplay = true);
-
- void clear(int places = 16);
-
- void flush();
-};
-
-#endif
diff --git a/MC128U201.png b/MC128U201.png
new file mode 100644
index 0000000..8afe4a3
Binary files /dev/null and b/MC128U201.png differ
diff --git a/MC128U202.png b/MC128U202.png
new file mode 100644
index 0000000..6665c00
Binary files /dev/null and b/MC128U202.png differ
diff --git a/README.md b/README.md
index 4ba463d..9708463 100644
--- a/README.md
+++ b/README.md
@@ -1,7 +1,44 @@
-Arduino Library for 7segment LCD via software SPI (or SPI like communication)
+Arduino Library for 32x4 LCDs via software SPI (or SPI like communication)
-Mostly from: macduino.blogspot.com, thanks!
+With Test files to cycle all segments and reverse video here > https://youtu.be/1nOSXn8DHw4
-modified to add print like statments for easy digit display
+**WHY:**
+
+The HT1621 is in many old lcd appliances and can be directly adressed to write to old salvaged lcds that are driven by this chip.
+It has an integrated 2Khz/4Khz Buzzer and any 48-pi SSOP with 1621 on it's name is probably a a HT.
+You can buy the chips from ebay from less than 20.cents a piece.
+*ebay search:* goo.gl/qw28xx
+
+**WHAT:**
+
+The HT1621 is a 128 pattern (32x4), memory mapping, and multi-function LCD driver.
+The S/W configuration feature of the HT1621 makes it suitable for multiple LCD applications including LCD modules and display subsystems.
+Only three or four lines are required for the interface between the host controller and the HT1621.
+The HT1621 contains a power down command to reduce power consumption.
+Operating voltage: 2.4V~5.2V
+
+*datasheet:* http://www.seeedstudio.com/document/HT1621.pdf
+
+Note: RD pin is optional
-purchased from ebay: http://www.ebay.ca/itm/Arduino-example-12Digit-7Seg-SPI-LCD-LED-UNO-MEGA2560-AVR-PIC-ARM-CPLD-/281152682213?hash=item41760178e5
\ No newline at end of file
+
+**HOW:**
+
+The idea is to give to create and collect the info, libraries and boards to allow anyone to reverse and reuse old salvaged LCDs either ones that already have the chip as a driver or other ones that can be hacked to use with this chip
+
+---
+**TODO:**
+- Make OpenSourceVersion of a HT1621 Breakoutboard
+- Find the best method to reverse the codes for unknown LCDs
+- Create documenta page for collecting this knowlage
+- Test the lib in a OpenDay @ the Lab, dedicated to arduino display hacking and writing
+
+---
+**REFERENCE LINKS**
+(HT1621 BreakoutBoard) http://blog.ankitdaf.com/ht1621b-display-controller-breakout-board/
+http://arduino.ru/forum/apparatnye-voprosy/podklyuchenie-i-ispolzovanie-zhk-segmentnogo-indikatora
+
+---
+**Original Source: https://github.com/marc-gist/HT1621**
+Mostly from: macduino.blogspot.com, thanks!
+modified to add print like statments for easy digit display
diff --git a/ht1621.cpp b/ht1621.cpp
new file mode 100644
index 0000000..369650d
--- /dev/null
+++ b/ht1621.cpp
@@ -0,0 +1,139 @@
+#include
+
+#include "HT1621.h"
+
+#define ADDR_MAX 128
+
+#define TAKE_CS() digitalWrite(cs_pin, LOW)
+#define RELEASE_CS() digitalWrite(cs_pin, HIGH)
+
+inline void HT1621::initControlBus()
+{
+ pinMode(data_pin, OUTPUT);
+ pinMode(wr_pin, OUTPUT);
+ pinMode(rd_pin, OUTPUT);
+ pinMode(cs_pin, OUTPUT);
+
+ digitalWrite(cs_pin, HIGH);
+ digitalWrite(wr_pin, HIGH);
+ digitalWrite(rd_pin, HIGH);
+ digitalWrite(data_pin, HIGH);
+}
+
+inline bool HT1621::testMem()
+{
+ uint8_t test = 10;
+ writeMem(0x5a, test);
+ //if (readMem(0x5a) != test)
+ // return false;
+ return true;
+}
+
+bool HT1621::begin()
+{
+ initControlBus();
+ //delay(100); //uncomment if init fails
+ sendCommand(SYS_DIS);
+ if (! testMem())
+ return false;
+
+ memset(0, 0, ADDR_MAX);
+ sendCommand(SYS_EN);
+ sendCommand(LCD_ON);
+ return true;
+}
+
+void HT1621::writeBits(uint8_t data, uint8_t cnt)
+{
+ uint8_t bitmask;
+ while (cnt) {
+ digitalWrite(wr_pin, LOW);
+ uint8_t bitval = (data & (1 << (cnt - 1))) ? HIGH : LOW;
+ digitalWrite(data_pin, bitval);
+ digitalWrite(wr_pin, HIGH);
+ cnt--;
+ }
+}
+
+uint8_t HT1621::readBits(uint8_t cnt)
+{
+ uint8_t data = 0;
+ pinMode(data_pin, INPUT);
+ while (cnt) {
+ digitalWrite(rd_pin, LOW);
+ data += digitalRead(data_pin) << (cnt - 1);
+ digitalWrite(rd_pin, HIGH);
+ cnt--;
+ }
+ pinMode(data_pin, OUTPUT);
+ return data;
+}
+
+#define COMMAND_MODE 0b100
+void HT1621::sendCommand(uint8_t cmd, bool first /*= true*/, bool last /*= true*/)
+{
+ if (first) {
+ TAKE_CS();
+ writeBits(COMMAND_MODE, 3);
+ }
+ writeBits(cmd, 8);
+ writeBits(0, 1); //Last bit - don't care
+ if (last)
+ RELEASE_CS();
+}
+
+#define WRITE_MODE 0b101
+void HT1621::writeMem(uint8_t address, uint8_t data)
+{
+ TAKE_CS();
+ writeBits(WRITE_MODE, 3);
+ writeBits(address, 6);
+ writeBits(data, 4);
+ RELEASE_CS();
+}
+
+void HT1621::memset(uint8_t address, uint8_t data, uint8_t cnt)
+{
+ TAKE_CS();
+ writeBits(WRITE_MODE, 3);
+ writeBits(address, 6);
+ for (uint8_t i = 0; i < cnt; i++)
+ writeBits(data, 4);
+ RELEASE_CS();
+}
+
+//Write up to 256 values starting from address
+//Note: Data is 8-bit aligned. This is not vary efficient
+void HT1621::write(uint8_t address, uint8_t *data, uint8_t cnt)
+{
+ TAKE_CS();
+ writeBits(WRITE_MODE, 3);
+ writeBits(address, 6);
+ for (uint8_t i = 0; i < cnt; i++)
+ writeBits(data[i], 4);
+ RELEASE_CS();
+}
+
+#define READ_MODE 0b110
+uint8_t HT1621::readMem(uint8_t address)
+{
+ uint8_t data;
+ TAKE_CS();
+ writeBits(READ_MODE, 3);
+ writeBits(address, 6);
+ data = readBits(4);
+ RELEASE_CS();
+ return data;
+}
+
+#define READ_MODE 0b110
+void HT1621::read(uint8_t address, uint8_t *data, uint8_t cnt)
+{
+ TAKE_CS();
+ writeBits(READ_MODE, 3);
+ writeBits(address, 6);
+ for (uint8_t i = 0; i < cnt; i++)
+ data[i] = readBits(4);
+ RELEASE_CS();
+}
+
diff --git a/ht1621.h b/ht1621.h
new file mode 100644
index 0000000..11d6455
--- /dev/null
+++ b/ht1621.h
@@ -0,0 +1,63 @@
+/* HT1621 - Holtek RAM Mapping 32x4 LCD Controller */
+#ifndef HT1621_H
+#define HT1621_H
+
+#include
+
+class HT1621 {
+public:
+ enum {
+ SYS_DIS = 0b00000000,
+ SYS_EN = 0b00000001,
+ LCD_OFF = 0b00000010,
+ LCD_ON = 0b00000011,
+ TIMER_DIS = 0b00000100,
+ WDT_DIS = 0b00000101,
+ TIMER_EN = 0b00000110,
+ WDT_EN = 0b00000111,
+ TONE_OFF = 0b00001000,
+ TONE_ON = 0b00001001,
+
+ //Set bias to 1/2 or 1/3 cycle
+ //Set to 2,3 or 4 connected COM lines
+ BIAS_HALF_2_COM = 0b00100000,
+ BIAS_HALF_3_COM = 0b00100100,
+ BIAS_HALF_4_COM = 0b00101000,
+ BIAS_THIRD_2_COM = 0b00100001,
+ BIAS_THIRD_3_COM = 0b00100101,
+ BIAS_THIRD_4_COM = 0b00101001,
+
+ //Don't use
+ TEST_ON = 0b11100000,
+ TEST_OFF = 0b11100011
+ } Commands;
+
+ HT1621(uint8_t data, uint8_t wr, uint8_t rd, uint8_t cs) :
+ data_pin(data), wr_pin(wr), rd_pin(rd), cs_pin(cs) {}
+
+ bool begin();
+
+ void sendCommand(uint8_t cmd, bool first = true, bool last = true);
+
+ void write(uint8_t address, uint8_t *data, uint8_t cnt);
+ void read(uint8_t address, uint8_t *data, uint8_t cnt);
+
+ void writeMem(uint8_t address, uint8_t data);
+ uint8_t readMem(uint8_t address);
+
+ void memset(uint8_t address, uint8_t data, uint8_t cnt);
+
+private:
+ void writeBits(uint8_t data, uint8_t cnt);
+ uint8_t readBits(uint8_t cnt);
+
+ inline void initControlBus();
+ inline bool testMem();
+
+ uint8_t data_pin;
+ uint8_t wr_pin;
+ uint8_t rd_pin;
+ uint8_t cs_pin;
+};
+
+#endif //HT1621_H
diff --git a/ht1621_tester.ino b/ht1621_tester.ino
new file mode 100644
index 0000000..145b4e1
--- /dev/null
+++ b/ht1621_tester.ino
@@ -0,0 +1,134 @@
+/**
+ HT1261-based 7segment LCD display test program
+ 2015/09/26 morecat_lab
+
+ X3msnake 2016/10/24 - Added TEST_PATTERN changed clear memory to fill memory in order to have a full lit display on initialization
+ */
+
+#include "Arduino.h"
+#include "HT1621.h"
+
+HT1621 ht(2,13,4,5); // data,wr,rd,cs
+
+ //#define TS120
+ //#define TS125
+ //#define TS174
+ //#define TS119
+ //#define TS206
+
+#define TEST_SEGMENT
+#define TEST_PATTERN
+// #define TEST_SMALL_SEGMENT
+
+//// LCD 7segment character pattern
+//#if defined(TS120) || defined(TS206)
+//#define LARGE_NUM_DIGIT 9
+//#define LARGE_NUM_START 6
+//#define SMALL_NUM_DIGIT 2
+//#define SMALL_NUM_START 2
+//char pattern[] = {
+// 0x5F, 0x50, 0x3D, 0x79, 0x72, 0x6B, 0x6F, 0x51,
+// 0x7F, 0x7B, 0x77, 0x6E, 0x0F, 0x7C, 0x3F, 0x27 };
+//#endif
+//
+//#if defined(TS125)
+//#define LARGE_NUM_DIGIT 8
+//#define LARGE_NUM_START 0
+//#define SMALL_NUM_DIGIT 2
+//#define SMALL_NUM_START 16
+//char pattern[] = {
+// 0xEB, 0x60, 0xC7, 0xE5, 0x6C, 0xAD, 0xAF, 0xE0,
+// 0xEF, 0xED, 0xEE, 0x2F, 0x8B, 0x67, 0x8F, 0x8E };
+//#endif
+//
+//#if defined(TS119) || defined(TS174)
+//#define LARGE_NUM_DIGIT 7
+//#define LARGE_NUM_START 2
+//#define SMALL_NUM_DIGIT 1
+//#define SMALL_NUM_START 0
+//char pattern[] = {
+// 0xAF, 0xA0, 0xCB, 0xE9, 0xE4, 0x6D, 0x6F, 0xA8,
+// 0xEF, 0xED, 0xEE, 0x67, 0x0F, 0xE3, 0x4F, 0x4E };
+//#endif
+//
+//void setNum(char adr, char num) {
+// ht.writeMem(adr, pattern[num] &0xf);
+// ht.writeMem(adr+1, pattern[num] >> 4);
+//}
+//
+//// print large segment
+//void printNum(long num) {
+// for (int i = 1 ; i <= LARGE_NUM_DIGIT ; i++) {
+// int adr = (LARGE_NUM_DIGIT - i) * 2 + LARGE_NUM_START;
+// setNum(adr, num % 10);
+// num /= 10;
+// }
+//}
+//
+//// print small segment (if any)
+//void printsNum(long num) {
+// for (int i = 1 ; i <= SMALL_NUM_DIGIT ; i++) {
+// int adr = (SMALL_NUM_DIGIT - i) * 2 + SMALL_NUM_START;
+// setNum(adr, num % 10);
+// num /= 10;
+// }
+//}
+
+void setup()
+{
+ pinMode(13, OUTPUT);
+ Serial.begin(9600);
+ ht.begin();
+// ht.sendCommand(HT1621::RC256K);
+ ht.sendCommand(HT1621::BIAS_THIRD_4_COM); // FOR TS119
+// ht.sendCommand(HT1621::BIAS_HALF_4_COM);
+ ht.sendCommand(HT1621::SYS_EN);
+ ht.sendCommand(HT1621::LCD_ON);
+
+ // Fill RAM
+ for (int i = 0 ; i < 32 ; i++) {
+ ht.writeMem(i, 0xF);
+ }
+
+
+#ifdef TEST_SEGMENT
+ // test segment
+ for (int i = 0 ; i < 32 ; i++) {
+ for (int j = 0 ; j <= 4 ; j++) {
+ ht.writeMem(i, 1<