A simple library for Holtek's HT1621 segment LCD driver
HT1621.cpp@0:3001ada71ba5, 2013-12-21 (annotated)
- Committer:
- kayekss
- Date:
- Sat Dec 21 13:29:11 2013 +0000
- Revision:
- 0:3001ada71ba5
First release
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kayekss | 0:3001ada71ba5 | 1 | #include "mbed.h" |
kayekss | 0:3001ada71ba5 | 2 | #include "HT1621.h" |
kayekss | 0:3001ada71ba5 | 3 | |
kayekss | 0:3001ada71ba5 | 4 | HT1621::HT1621(PinName wrPin, PinName dataPin, PinName csPin) |
kayekss | 0:3001ada71ba5 | 5 | : |
kayekss | 0:3001ada71ba5 | 6 | wr(wrPin), |
kayekss | 0:3001ada71ba5 | 7 | data(dataPin), |
kayekss | 0:3001ada71ba5 | 8 | cs(csPin) |
kayekss | 0:3001ada71ba5 | 9 | { |
kayekss | 0:3001ada71ba5 | 10 | wr = 1; |
kayekss | 0:3001ada71ba5 | 11 | cs = 1; |
kayekss | 0:3001ada71ba5 | 12 | |
kayekss | 0:3001ada71ba5 | 13 | command(SYS_DIS); |
kayekss | 0:3001ada71ba5 | 14 | wait(0.2); |
kayekss | 0:3001ada71ba5 | 15 | command(SYS_EN); |
kayekss | 0:3001ada71ba5 | 16 | command(RC_256K); |
kayekss | 0:3001ada71ba5 | 17 | command(LCD_OFF); |
kayekss | 0:3001ada71ba5 | 18 | |
kayekss | 0:3001ada71ba5 | 19 | // Clear all segments |
kayekss | 0:3001ada71ba5 | 20 | for (uint8_t i = 0; i < 64; i++) { |
kayekss | 0:3001ada71ba5 | 21 | write(i, 0x00); |
kayekss | 0:3001ada71ba5 | 22 | } |
kayekss | 0:3001ada71ba5 | 23 | command(LCD_ON); |
kayekss | 0:3001ada71ba5 | 24 | } |
kayekss | 0:3001ada71ba5 | 25 | |
kayekss | 0:3001ada71ba5 | 26 | HT1621::~HT1621() { |
kayekss | 0:3001ada71ba5 | 27 | } |
kayekss | 0:3001ada71ba5 | 28 | |
kayekss | 0:3001ada71ba5 | 29 | void HT1621::command(uint8_t b) { |
kayekss | 0:3001ada71ba5 | 30 | // 11 10 9 8| 7 6 5 4| 3 2 1 0 |
kayekss | 0:3001ada71ba5 | 31 | // --------+--+-----------+----------- |
kayekss | 0:3001ada71ba5 | 32 | // 1 0 0| command<8:0> |
kayekss | 0:3001ada71ba5 | 33 | uint16_t word = 0x0800 | (b << 1); |
kayekss | 0:3001ada71ba5 | 34 | |
kayekss | 0:3001ada71ba5 | 35 | cs = 0; |
kayekss | 0:3001ada71ba5 | 36 | for (uint8_t i = 11; i <= 11; i--) { |
kayekss | 0:3001ada71ba5 | 37 | wr = 0; |
kayekss | 0:3001ada71ba5 | 38 | data = word & (0x0001 << i) ? 1 : 0; |
kayekss | 0:3001ada71ba5 | 39 | wr = 1; |
kayekss | 0:3001ada71ba5 | 40 | } |
kayekss | 0:3001ada71ba5 | 41 | cs = 1; |
kayekss | 0:3001ada71ba5 | 42 | } |
kayekss | 0:3001ada71ba5 | 43 | |
kayekss | 0:3001ada71ba5 | 44 | void HT1621::write(uint8_t addr, uint8_t b) { |
kayekss | 0:3001ada71ba5 | 45 | // 12|11 10 9 8| 7 6 5 4| 3 2 1 0 |
kayekss | 0:3001ada71ba5 | 46 | // --+-----+-----+-----------+----------- |
kayekss | 0:3001ada71ba5 | 47 | // 1 0 1| address<5:0>| seg<3:0> |
kayekss | 0:3001ada71ba5 | 48 | uint16_t word = 0x1400 | ((addr & 0x3f) << 4) | (b & 0x0f); |
kayekss | 0:3001ada71ba5 | 49 | |
kayekss | 0:3001ada71ba5 | 50 | cs = 0; |
kayekss | 0:3001ada71ba5 | 51 | for (uint8_t i = 12; i <= 12; i--) { |
kayekss | 0:3001ada71ba5 | 52 | wr = 0; |
kayekss | 0:3001ada71ba5 | 53 | data = word & (0x0001 << i) ? 1 : 0; |
kayekss | 0:3001ada71ba5 | 54 | wr = 1; |
kayekss | 0:3001ada71ba5 | 55 | } |
kayekss | 0:3001ada71ba5 | 56 | cs = 1; |
kayekss | 0:3001ada71ba5 | 57 | } |