HT1621(TS119-5, TS174 )Library

Dependents:   Demo_HT1621

Files at this revision

API Documentation at this revision

Comitter:
og
Date:
Sat Sep 10 09:55:39 2016 +0000
Commit message:
HT1621(TS119-5, TS174) demo

Changed in this revision

HT1621.cpp Show annotated file Show diff for this revision Revisions of this file
HT1621.h Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r 2377890cc77a HT1621.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/HT1621.cpp	Sat Sep 10 09:55:39 2016 +0000
@@ -0,0 +1,132 @@
+#include "HT1621.h"
+
+#define ADDR_MAX 128
+
+#define TAKE_CS()    _cs = 0
+#define RELEASE_CS() _cs = 1
+
+HT1621::HT1621(
+    PinName data, PinName wr, PinName rd, PinName cs
+    ):
+    _data(data), _wr(wr), _rd(rd), _cs(cs)
+{
+    _data.output();
+    _data = 1;
+    _wr = 1;
+    _rd = 1;
+    _cs = 1;
+    sendCommand(SYS_DIS);
+    wait_ms(500);
+    //if (! testMem())
+    //    return false;
+
+    memset(0, 0, ADDR_MAX);
+    sendCommand(SYS_EN);
+    sendCommand(LCD_ON);
+}
+
+
+inline bool HT1621::testMem()
+{
+    uint8_t test = 10;
+    writeMem(0x5a, test);
+    if (readMem(0x5a) != test)
+        return false;
+    return true;
+}
+
+
+void HT1621::writeBits(uint8_t data, uint8_t cnt)
+{
+    while (cnt) {
+        _wr = 0;
+        uint8_t bitval = (data & (1 << (cnt - 1))) ? 1 : 0;
+        _data = bitval;
+        //wait_ms(1);
+        _wr = 1;
+        cnt--;
+    }
+}
+
+uint8_t HT1621::readBits(uint8_t cnt)
+{
+    uint8_t data = 0;
+    _data.input();
+    while (cnt) {
+        _rd = 0;
+        data += _data << (cnt - 1);
+        //wait_ms(1);
+        _rd= 1;
+        cnt--;
+    }
+    _data.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 -r 000000000000 -r 2377890cc77a HT1621.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/HT1621.h	Sat Sep 10 09:55:39 2016 +0000
@@ -0,0 +1,75 @@
+/* HT1621 - Holtek RAM Mapping 32x4 LCD Controller */
+/**
+ * TEST
+ * TS119-3
+ * TS119-5  http://www.aitendo.com/product/5152
+ * TS174    http://www.aitendo.com/product/5153
+ * http://www.holtek.com.tw/documents/10179/a33bf4b4-f0ef-4b77-94e4-3dd5d0c35f16
+ * 
+ * HT1621 Library
+ * https://storage.googleapis.com/google-code-archive-source/v2/code.google.com/wirejungle/source-archive.zip
+ * 
+ * reference
+ * http://jr4pdp.blog.enjoy.jp/myblog/2016/01/lcd-ts174nblpic-da92.html
+ * http://morecatlab.akiba.coocan.jp/lab/index.php/2015/10/segment-lcd/
+*/
+#ifndef MBED_HT1621_H
+#define MBED_HT1621_H
+#include "mbed.h"
+
+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(
+        PinName data, PinName wr, PinName rd, PinName cs
+        );
+    ~HT1621(){}
+
+
+    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:
+    DigitalInOut _data;
+    DigitalOut _wr, _rd, _cs;
+    void writeBits(uint8_t data, uint8_t cnt);
+    uint8_t readBits(uint8_t cnt);
+
+    inline void initControlBus();
+    inline bool testMem();
+    
+};
+
+#endif //HT1621_H