Holtek HT1621 16 segment 9 digit LCD display library

Committer:
star297
Date:
Sat Jan 17 15:45:45 2015 +0000
Revision:
0:45d8278c902a
updated docs

Who changed what in which revision?

UserRevisionLine numberNew contents of line
star297 0:45d8278c902a 1 //HT1621 9 DIGIT 16SEG LCD
star297 0:45d8278c902a 2
star297 0:45d8278c902a 3 #include "mbed.h"
star297 0:45d8278c902a 4 #include <stdarg.h>
star297 0:45d8278c902a 5
star297 0:45d8278c902a 6
star297 0:45d8278c902a 7 /*---Segment Display Screen----
star297 0:45d8278c902a 8
star297 0:45d8278c902a 9 ___5___ ___13__
star297 0:45d8278c902a 10 | \ | / |
star297 0:45d8278c902a 11 6| 7 16 15 |14
star297 0:45d8278c902a 12 | \ | / |
star297 0:45d8278c902a 13 ___8___ ___12__
star297 0:45d8278c902a 14 | / | \ |
star297 0:45d8278c902a 15 2| 3 4 11 |10
star297 0:45d8278c902a 16 | / | \ |
star297 0:45d8278c902a 17 -------- -------
star297 0:45d8278c902a 18 1 9
star297 0:45d8278c902a 19
star297 0:45d8278c902a 20 Display code generate example: '1' = seg15 + seg14 + seg10
star297 0:45d8278c902a 21
star297 0:45d8278c902a 22 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1
star297 0:45d8278c902a 23 Biary code = 0 1 1 0 0 0 1 0 0 0 0 0 0 0 0 0
star297 0:45d8278c902a 24 Hex value = 0x6200
star297 0:45d8278c902a 25
star297 0:45d8278c902a 26 -----------------------------
star297 0:45d8278c902a 27 */
star297 0:45d8278c902a 28
star297 0:45d8278c902a 29 //Defined HT1621's commands for this display
star297 0:45d8278c902a 30 #define ComMode 0x52 // 4 comons, LCD 1/3 bias
star297 0:45d8278c902a 31 #define RCosc 0x30 // on-chip RC oscillator (Power-on default)
star297 0:45d8278c902a 32 #define LCD_on 0x06 // Turn on LCD bias generator
star297 0:45d8278c902a 33 #define LCD_off 0x04 // Turn off LCD bias generator (default)
star297 0:45d8278c902a 34 #define Sys_en 0x02 // Turn on system oscillator
star297 0:45d8278c902a 35 #define Sys_dis 0x00 // Turn off system osc & LCD bias generator (default)
star297 0:45d8278c902a 36
star297 0:45d8278c902a 37 //Other HT1621's available commands (not used)
star297 0:45d8278c902a 38 #define TIMER_DIS 0x08 // Disable time base output
star297 0:45d8278c902a 39 #define WDT_DIS 0x05 // Enable WDT time-out flag output
star297 0:45d8278c902a 40 #define TIMER_EN 0x06 // Enable time base output
star297 0:45d8278c902a 41 #define WDT_EN 0x07 // Enable WDT time-out flag output
star297 0:45d8278c902a 42 #define TONE_OFF 0x08 // Turn off tone outputs
star297 0:45d8278c902a 43 #define TONE_ON 0x09 // Turn on tone outputs
star297 0:45d8278c902a 44 #define CLR_TIMER 0xc0 // Clear the contents of time base generator
star297 0:45d8278c902a 45 #define CLR_WDT 0xe0 // Clear the contents of WDT stage
star297 0:45d8278c902a 46 #define XTAL_32K 0x14 // System clock source, crystal oscillator
star297 0:45d8278c902a 47 #define EXT_256K 0x1c // System clock source, external clock source
star297 0:45d8278c902a 48 #define BIAS1_2_COM2 0x20 // LCD 1/2 bias option
star297 0:45d8278c902a 49 #define BIAS1_3_COM2 0x21 // LCD 1/3 bias option
star297 0:45d8278c902a 50 #define BIAS1_2_COM3 0x24 // LCD 1/2 bias option
star297 0:45d8278c902a 51 #define BIAS1_3_COM3 0x25 // LCD 1/3 bias option
star297 0:45d8278c902a 52 #define BIAS1_2_COM4 0x28 // LCD 1/2 bias option
star297 0:45d8278c902a 53 #define TONE_4K 0x40 // Tone frequency, 4kHz
star297 0:45d8278c902a 54 #define TONE_2K 0x60 // Tone frequency, 2kHz
star297 0:45d8278c902a 55 #define IRQ_DIS 0x80 // Disable IRQ output
star297 0:45d8278c902a 56 #define IRQ_EN 0x88 // Enable IRQ output
star297 0:45d8278c902a 57 #define F1 0xa0 // Time base/WDT clock output:1Hz The WDT time-out flag after: 4s
star297 0:45d8278c902a 58 #define F2 0xa1 // Time base/WDT clock output:2Hz The WDT time-out flag after: 2s
star297 0:45d8278c902a 59 #define F4 0xa2 // Time base/WDT clock output:4Hz The WDT time-out flag after: 1s
star297 0:45d8278c902a 60 #define F8 0xa3 // Time base/WDT clock output:8Hz The WDT time-out flag after: 1/2s
star297 0:45d8278c902a 61 #define F16 0xa4 // Time base/WDT clock output:16Hz The WDT time-out flag after: 1/4s
star297 0:45d8278c902a 62 #define F32 0xa5 // Time base/WDT clock output:32Hz The WDT time-out flag after: 1/8s
star297 0:45d8278c902a 63 #define F64 0xa6 // Time base/WDT clock output:64Hz The WDT time-out flag after: 1/16s
star297 0:45d8278c902a 64 #define F128 0xa7 // Time base/WDT clock output:128Hz The WDT time-out flag after: 1/32s
star297 0:45d8278c902a 65 #define TEST 0xe0 // Test mode, user don t use
star297 0:45d8278c902a 66 #define NORMAL 0xe3 // Normal mode
star297 0:45d8278c902a 67
star297 0:45d8278c902a 68 //ASCII character to LCD code table
star297 0:45d8278c902a 69 const int num[] = {
star297 0:45d8278c902a 70 0x0000, // space
star297 0:45d8278c902a 71 0x0000, // !
star297 0:45d8278c902a 72 0xA000, // "
star297 0:45d8278c902a 73 0x88AC, // #
star297 0:45d8278c902a 74 0x1BB9, // $
star297 0:45d8278c902a 75 0xCBBC, // %
star297 0:45d8278c902a 76 0x85D3, // &
star297 0:45d8278c902a 77 0x8000, // '
star297 0:45d8278c902a 78 0x4400, // (
star297 0:45d8278c902a 79 0x0044, // )
star297 0:45d8278c902a 80 0xCCCC, // *
star297 0:45d8278c902a 81 0x8888, // +
star297 0:45d8278c902a 82 0x4000, // '
star297 0:45d8278c902a 83 0x0880, // -
star297 0:45d8278c902a 84 0x0000, // .
star297 0:45d8278c902a 85 0x4004, // /
star297 0:45d8278c902a 86 0x7337, // 0
star297 0:45d8278c902a 87 0x6200, // 1
star297 0:45d8278c902a 88 0x3993, // 2
star297 0:45d8278c902a 89 0x3b91, // 3
star297 0:45d8278c902a 90 0x2aa0, // 4
star297 0:45d8278c902a 91 0x1bb1, // 5
star297 0:45d8278c902a 92 0x1bb3, // 6
star297 0:45d8278c902a 93 0x3210, // 7
star297 0:45d8278c902a 94 0x3BB3, // 8
star297 0:45d8278c902a 95 0x3BB1, // 9
star297 0:45d8278c902a 96 0x8008, // :
star297 0:45d8278c902a 97 0x8004, // ;
star297 0:45d8278c902a 98 0x4480, // <
star297 0:45d8278c902a 99 0x0981, // =
star297 0:45d8278c902a 100 0x0844, // >
star297 0:45d8278c902a 101 0x3818, // ?
star297 0:45d8278c902a 102 0x3793, // @
star297 0:45d8278c902a 103 0x3AB2, // A
star297 0:45d8278c902a 104 0xBB19, // B
star297 0:45d8278c902a 105 0x1133, // C
star297 0:45d8278c902a 106 0xB319, // D
star297 0:45d8278c902a 107 0x19B3, // E
star297 0:45d8278c902a 108 0x18B2, // F
star297 0:45d8278c902a 109 0x1B33, // G
star297 0:45d8278c902a 110 0x2AA2, // H
star297 0:45d8278c902a 111 0x9119, // I
star297 0:45d8278c902a 112 0x2303, // J
star297 0:45d8278c902a 113 0x44A2, // K
star297 0:45d8278c902a 114 0x0123, // L
star297 0:45d8278c902a 115 0x626A, // M
star297 0:45d8278c902a 116 0x2662, // N
star297 0:45d8278c902a 117 0x3333, // O
star297 0:45d8278c902a 118 0x38B2, // P
star297 0:45d8278c902a 119 0x3733, // Q
star297 0:45d8278c902a 120 0x3CB2, // R
star297 0:45d8278c902a 121 0x1BB1, // S
star297 0:45d8278c902a 122 0x9018, // T
star297 0:45d8278c902a 123 0x2323, // U
star297 0:45d8278c902a 124 0x4026, // V
star297 0:45d8278c902a 125 0xA626, // W
star297 0:45d8278c902a 126 0x4444, // X
star297 0:45d8278c902a 127 0x4048, // y
star297 0:45d8278c902a 128 0x5115, // Z
star297 0:45d8278c902a 129 0x9108, // [
star297 0:45d8278c902a 130 0x0440, // \
star297 0:45d8278c902a 131 0x8019, // ]
star297 0:45d8278c902a 132 0x0404, // ^
star297 0:45d8278c902a 133 0x0101, // _
star297 0:45d8278c902a 134 0x0040, // '
star297 0:45d8278c902a 135 0x0000, //
star297 0:45d8278c902a 136 0x018B, // a
star297 0:45d8278c902a 137 0x00AB, // b
star297 0:45d8278c902a 138 0x0083, // c
star297 0:45d8278c902a 139 0x808B, // d
star297 0:45d8278c902a 140 0x0187, // e
star297 0:45d8278c902a 141 0x9888, // f
star297 0:45d8278c902a 142 0x80B9, // g
star297 0:45d8278c902a 143 0x00AA, // h
star297 0:45d8278c902a 144 0x0008, // i
star297 0:45d8278c902a 145 0x800B, // j
star297 0:45d8278c902a 146 0xC408, // k
star297 0:45d8278c902a 147 0x8008, // l
star297 0:45d8278c902a 148 0x0A8A, // m
star297 0:45d8278c902a 149 0x008A, // n
star297 0:45d8278c902a 150 0x0B83, // o
star297 0:45d8278c902a 151 0x80B2, // p
star297 0:45d8278c902a 152 0x80B8, // q
star297 0:45d8278c902a 153 0x0082, // r
star297 0:45d8278c902a 154 0x00B9, // s
star297 0:45d8278c902a 155 0x8988, // t
star297 0:45d8278c902a 156 0x0303, // u
star297 0:45d8278c902a 157 0x0006, // v
star297 0:45d8278c902a 158 0x0606, // w
star297 0:45d8278c902a 159 0x4444, // x
star297 0:45d8278c902a 160 0x4048, // y
star297 0:45d8278c902a 161 0x0085, // z
star297 0:45d8278c902a 162 0x9188, // {
star297 0:45d8278c902a 163 0x9119, // |
star297 0:45d8278c902a 164 0x8819, // }
star297 0:45d8278c902a 165 0x1010, // ¬
star297 0:45d8278c902a 166
star297 0:45d8278c902a 167 };
star297 0:45d8278c902a 168
star297 0:45d8278c902a 169
star297 0:45d8278c902a 170
star297 0:45d8278c902a 171 /**
star297 0:45d8278c902a 172 * 9 digit (+ Hz character) 16 segment LCD display\n
star297 0:45d8278c902a 173 using Holeck's HT1621 LCD driver.
star297 0:45d8278c902a 174
star297 0:45d8278c902a 175 @code
star297 0:45d8278c902a 176 #include "mbed.h"
star297 0:45d8278c902a 177 #include "digitLCD.h"
star297 0:45d8278c902a 178
star297 0:45d8278c902a 179 digitLCD lcd(PTC0,PTC1,PTD6); // WO, CS, DATA
star297 0:45d8278c902a 180
star297 0:45d8278c902a 181 main()
star297 0:45d8278c902a 182 {
star297 0:45d8278c902a 183 lcd.clear(); // clears display
star297 0:45d8278c902a 184 lcd.printf("ABCDEFGHI"); // Standard printf function, All ASCII characters will display
star297 0:45d8278c902a 185
star297 0:45d8278c902a 186 while(1){ // basic RTC clock function
star297 0:45d8278c902a 187 time_t seconds = time(NULL);
star297 0:45d8278c902a 188 strftime(timebuf, 32, "%H-%M-%S\n", localtime(&seconds));
star297 0:45d8278c902a 189 strftime(datebuf, 32, "%a %d%b\n", localtime(&seconds));
star297 0:45d8278c902a 190 if (n<7){lcd.printf(timebuf);}
star297 0:45d8278c902a 191 else{lcd.printf(datebuf);}
star297 0:45d8278c902a 192 if(n>10){n=0;}
star297 0:45d8278c902a 193 n++;
star297 0:45d8278c902a 194 wait(1);
star297 0:45d8278c902a 195 }
star297 0:45d8278c902a 196 @endcode
star297 0:45d8278c902a 197 */
star297 0:45d8278c902a 198
star297 0:45d8278c902a 199 class digitLCD
star297 0:45d8278c902a 200 {
star297 0:45d8278c902a 201 public:
star297 0:45d8278c902a 202
star297 0:45d8278c902a 203 digitLCD(PinName Rw, PinName CS, PinName DATA); // Default constructor
star297 0:45d8278c902a 204
star297 0:45d8278c902a 205 //! Initialise display
star297 0:45d8278c902a 206 void init();
star297 0:45d8278c902a 207 //! Clear Display
star297 0:45d8278c902a 208 void clear();
star297 0:45d8278c902a 209 //! Powers on LCD bias generators
star297 0:45d8278c902a 210 void LCDon();
star297 0:45d8278c902a 211 //! Powers off LCD bias generators (low power mode)
star297 0:45d8278c902a 212 void LCDoff();
star297 0:45d8278c902a 213 //! LCD all segments on test
star297 0:45d8278c902a 214 void allsegson();
star297 0:45d8278c902a 215 //! Hz symbol on
star297 0:45d8278c902a 216 void HZon();
star297 0:45d8278c902a 217 //! Hz symbol off
star297 0:45d8278c902a 218 void HZoff();
star297 0:45d8278c902a 219 void SendBit(char sdata,char cnt);
star297 0:45d8278c902a 220 void SendCmd(int command);
star297 0:45d8278c902a 221 void Write(char addr,int sdata);
star297 0:45d8278c902a 222
star297 0:45d8278c902a 223 void putc( char line, char c ) {
star297 0:45d8278c902a 224 if ( (c == '\n') || (c == '\r') ) {
star297 0:45d8278c902a 225 clear_rest_of_line( line );
star297 0:45d8278c902a 226 curs[ line ] = 0;
star297 0:45d8278c902a 227 return;
star297 0:45d8278c902a 228 }
star297 0:45d8278c902a 229 if (curs[ line ] >= 9 )
star297 0:45d8278c902a 230 return;
star297 0:45d8278c902a 231 Write(curs[ line ],num[c-32]);
star297 0:45d8278c902a 232 curs[ line ]++;
star297 0:45d8278c902a 233 }
star297 0:45d8278c902a 234
star297 0:45d8278c902a 235 void puts( char *s ) {
star297 0:45d8278c902a 236 char line=0;
star297 0:45d8278c902a 237 while ( char c = *s++ )
star297 0:45d8278c902a 238 putc( line, c );
star297 0:45d8278c902a 239 }
star297 0:45d8278c902a 240
star297 0:45d8278c902a 241 void printf(char *format, ... ) {
star297 0:45d8278c902a 242 char s[ 11 ];
star297 0:45d8278c902a 243 va_list args;
star297 0:45d8278c902a 244 va_start( args, format );
star297 0:45d8278c902a 245 vsnprintf( s, 11, format, args );
star297 0:45d8278c902a 246 va_end( args );
star297 0:45d8278c902a 247 puts( s );
star297 0:45d8278c902a 248
star297 0:45d8278c902a 249 }
star297 0:45d8278c902a 250 char curs[1];
star297 0:45d8278c902a 251 void clear_rest_of_line( char line ) {
star297 0:45d8278c902a 252 for ( int i = curs[ line ]; i < 10; i++ )
star297 0:45d8278c902a 253 putc( line, ' ');
star297 0:45d8278c902a 254 }
star297 0:45d8278c902a 255
star297 0:45d8278c902a 256
star297 0:45d8278c902a 257 private:
star297 0:45d8278c902a 258 DigitalOut _Rw;
star297 0:45d8278c902a 259 DigitalOut _CS;
star297 0:45d8278c902a 260 DigitalOut _DATA;
star297 0:45d8278c902a 261 };