A simple library for Holtek's HT1621 segment LCD driver
Revision 0:3001ada71ba5, committed 2013-12-21
- Comitter:
- kayekss
- Date:
- Sat Dec 21 13:29:11 2013 +0000
- Commit message:
- First release
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 3001ada71ba5 HT1621.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HT1621.cpp Sat Dec 21 13:29:11 2013 +0000 @@ -0,0 +1,57 @@ +#include "mbed.h" +#include "HT1621.h" + +HT1621::HT1621(PinName wrPin, PinName dataPin, PinName csPin) +: + wr(wrPin), + data(dataPin), + cs(csPin) +{ + wr = 1; + cs = 1; + + command(SYS_DIS); + wait(0.2); + command(SYS_EN); + command(RC_256K); + command(LCD_OFF); + + // Clear all segments + for (uint8_t i = 0; i < 64; i++) { + write(i, 0x00); + } + command(LCD_ON); +} + +HT1621::~HT1621() { +} + +void HT1621::command(uint8_t b) { + // 11 10 9 8| 7 6 5 4| 3 2 1 0 + // --------+--+-----------+----------- + // 1 0 0| command<8:0> + uint16_t word = 0x0800 | (b << 1); + + cs = 0; + for (uint8_t i = 11; i <= 11; i--) { + wr = 0; + data = word & (0x0001 << i) ? 1 : 0; + wr = 1; + } + cs = 1; +} + +void HT1621::write(uint8_t addr, uint8_t b) { + // 12|11 10 9 8| 7 6 5 4| 3 2 1 0 + // --+-----+-----+-----------+----------- + // 1 0 1| address<5:0>| seg<3:0> + uint16_t word = 0x1400 | ((addr & 0x3f) << 4) | (b & 0x0f); + + cs = 0; + for (uint8_t i = 12; i <= 12; i--) { + wr = 0; + data = word & (0x0001 << i) ? 1 : 0; + wr = 1; + } + cs = 1; +}
diff -r 000000000000 -r 3001ada71ba5 HT1621.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HT1621.h Sat Dec 21 13:29:11 2013 +0000 @@ -0,0 +1,55 @@ +#ifndef HT1621_H_ +#define HT1621_H_ + +class HT1621 { +private: + DigitalOut wr; + DigitalOut data; + DigitalOut cs; + +public: + // Commands + const static uint8_t SYS_DIS = 0x00; + const static uint8_t SYS_EN = 0x01; + const static uint8_t LCD_OFF = 0x02; + const static uint8_t LCD_ON = 0x03; + const static uint8_t TIMER_DIS = 0x04; + const static uint8_t WDT_DIS = 0x05; + const static uint8_t TIMER_EN = 0x06; + const static uint8_t WDT_EN = 0x07; + const static uint8_t TONE_OFF = 0x08; + const static uint8_t TONE_ON = 0x09; + const static uint8_t CLR_TIMER = 0xc0; + const static uint8_t CLR_WDT = 0xe0; + const static uint8_t XTAL_32K = 0x14; + const static uint8_t RC_256K = 0x18; + const static uint8_t EXT_256K = 0x1c; + const static uint8_t BIAS2_COM2 = 0x20; + const static uint8_t BIAS3_COM2 = 0x21; + const static uint8_t BIAS2_COM3 = 0x24; + const static uint8_t BIAS3_COM3 = 0x25; + const static uint8_t BIAS2_COM4 = 0x28; + const static uint8_t BIAS3_COM4 = 0x29; + const static uint8_t TONE_4K = 0x40; + const static uint8_t TONE_2K = 0x60; + const static uint8_t IRQ_DIS = 0x80; + const static uint8_t IRQ_EN = 0x88; + const static uint8_t F1 = 0xa0; + const static uint8_t F2 = 0xa1; + const static uint8_t F4 = 0xa2; + const static uint8_t F8 = 0xa3; + const static uint8_t F16 = 0xa4; + const static uint8_t F32 = 0xa5; + const static uint8_t F64 = 0xa6; + const static uint8_t F128 = 0xa7; + const static uint8_t TEST = 0xe0; + const static uint8_t NORMAL = 0xe3; + + HT1621(PinName wrPin, PinName dataPin, PinName csPin); + ~HT1621(); + + void write(uint8_t addr, uint8_t b); + void command(uint8_t b); +}; + +#endif