Paul Staron / HT1621_16seg_LCD
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers digitLCD.h Source File

digitLCD.h

00001 //HT1621 9 DIGIT 16SEG LCD
00002 
00003 #include "mbed.h"
00004 #include <stdarg.h>
00005 
00006 
00007      /*---Segment Display Screen----
00008             
00009           ___5___ ___13__
00010          | \     |     / |
00011         6|  7   16  15   |14
00012          |    \  | /     |
00013           ___8___ ___12__
00014          |     / | \     |   
00015         2|  3    4  11   |10
00016          | /     |     \ |
00017          -------- -------
00018              1       9
00019       
00020       Display code generate example: '1' = seg15 + seg14 + seg10
00021       
00022                   16 15 14 13 12 11 10  9  8  7  6  5  4  3  2  1
00023       Biary code = 0  1  1  0  0  0  1  0  0  0  0  0  0  0  0  0
00024       Hex value  = 0x6200
00025          
00026       -----------------------------
00027     */  
00028       
00029     //Defined HT1621's commands for this display  
00030     #define ComMode     0x52    // 4 comons, LCD 1/3 bias   
00031     #define RCosc       0x30    // on-chip RC oscillator (Power-on default) 
00032     #define LCD_on      0x06    // Turn on LCD bias generator       
00033     #define LCD_off     0x04    // Turn off LCD bias generator (default)            
00034     #define Sys_en      0x02    // Turn on system oscillator  
00035     #define Sys_dis     0x00    // Turn off system osc & LCD bias generator (default)
00036     
00037     //Other HT1621's available commands (not used)       
00038     #define TIMER_DIS   0x08    // Disable time base output    
00039     #define WDT_DIS     0x05    // Enable WDT time-out flag output
00040     #define TIMER_EN    0x06    // Enable time base output
00041     #define WDT_EN      0x07    // Enable WDT time-out flag output
00042     #define TONE_OFF    0x08    // Turn off tone outputs
00043     #define TONE_ON     0x09    // Turn on tone outputs
00044     #define CLR_TIMER   0xc0    // Clear the contents of time base generator
00045     #define CLR_WDT     0xe0    // Clear the contents of WDT stage
00046     #define XTAL_32K    0x14    // System clock source, crystal oscillator
00047     #define EXT_256K    0x1c    // System clock source, external clock source
00048     #define BIAS1_2_COM2  0x20    // LCD 1/2 bias option
00049     #define BIAS1_3_COM2  0x21    // LCD 1/3 bias option
00050     #define BIAS1_2_COM3  0x24    // LCD 1/2 bias option
00051     #define BIAS1_3_COM3  0x25    // LCD 1/3 bias option
00052     #define BIAS1_2_COM4  0x28    // LCD 1/2 bias option
00053     #define TONE_4K     0x40    // Tone frequency, 4kHz
00054     #define TONE_2K     0x60    // Tone frequency, 2kHz
00055     #define IRQ_DIS     0x80    // Disable IRQ output
00056     #define IRQ_EN      0x88    // Enable IRQ output
00057     #define F1          0xa0    // Time base/WDT clock output:1Hz The WDT time-out flag after: 4s
00058     #define F2          0xa1    // Time base/WDT clock output:2Hz The WDT time-out flag after: 2s
00059     #define F4          0xa2    // Time base/WDT clock output:4Hz The WDT time-out flag after: 1s
00060     #define F8          0xa3    // Time base/WDT clock output:8Hz The WDT time-out flag after: 1/2s
00061     #define F16         0xa4    // Time base/WDT clock output:16Hz The WDT time-out flag after: 1/4s
00062     #define F32         0xa5    // Time base/WDT clock output:32Hz The WDT time-out flag after: 1/8s
00063     #define F64         0xa6    // Time base/WDT clock output:64Hz The WDT time-out flag after: 1/16s
00064     #define F128        0xa7    // Time base/WDT clock output:128Hz The WDT time-out flag after: 1/32s
00065     #define TEST        0xe0    // Test mode, user dont use
00066     #define NORMAL      0xe3    // Normal mode  
00067         
00068     //ASCII character to LCD code table   
00069     const int num[] =  {    
00070     0x0000, //  space
00071     0x0000, //  !
00072     0xA000, //  "
00073     0x88AC, //  #
00074     0x1BB9, //  $
00075     0xCBBC, //  %
00076     0x85D3, //  &
00077     0x8000, //  '
00078     0x4400, //  (
00079     0x0044, //  )
00080     0xCCCC, //  *
00081     0x8888, //  +
00082     0x4000, //  '
00083     0x0880, //  -
00084     0x0000, //  .
00085     0x4004, //  /
00086     0x7337, //  0
00087     0x6200, //  1
00088     0x3993, //  2
00089     0x3b91, //  3
00090     0x2aa0, //  4
00091     0x1bb1, //  5
00092     0x1bb3, //  6
00093     0x3210, //  7
00094     0x3BB3, //  8
00095     0x3BB1, //  9
00096     0x8008, //  :
00097     0x8004, //  ;
00098     0x4480, //  <
00099     0x0981, //  =
00100     0x0844, //  >
00101     0x3818, //  ?
00102     0x3793, //  @
00103     0x3AB2, //  A
00104     0xBB19, //  B
00105     0x1133, //  C
00106     0xB319, //  D
00107     0x19B3, //  E
00108     0x18B2, //  F
00109     0x1B33, //  G
00110     0x2AA2, //  H
00111     0x9119, //  I
00112     0x2303, //  J
00113     0x44A2, //  K
00114     0x0123, //  L
00115     0x626A, //  M
00116     0x2662, //  N
00117     0x3333, //  O
00118     0x38B2, //  P
00119     0x3733, //  Q
00120     0x3CB2, //  R
00121     0x1BB1, //  S
00122     0x9018, //  T
00123     0x2323, //  U
00124     0x4026, //  V
00125     0xA626, //  W
00126     0x4444, //  X
00127     0x4048, //  y
00128     0x5115, //  Z
00129     0x9108, //  [
00130     0x0440, //  \
00131     0x8019, //  ]
00132     0x0404, //  ^
00133     0x0101, //  _
00134     0x0040, //  '
00135     0x0000, //  
00136     0x018B, //  a
00137     0x00AB, //  b
00138     0x0083, //  c
00139     0x808B, //  d
00140     0x0187, //  e
00141     0x9888, //  f
00142     0x80B9, //  g
00143     0x00AA, //  h
00144     0x0008, //  i
00145     0x800B, //  j
00146     0xC408, //  k
00147     0x8008, //  l
00148     0x0A8A, //  m
00149     0x008A, //  n
00150     0x0B83, //  o
00151     0x80B2, //  p
00152     0x80B8, //  q
00153     0x0082, //  r
00154     0x00B9, //  s
00155     0x8988, //  t
00156     0x0303, //  u
00157     0x0006, //  v
00158     0x0606, //  w
00159     0x4444, //  x
00160     0x4048, //  y
00161     0x0085, //  z
00162     0x9188, //  {
00163     0x9119, //  |
00164     0x8819, //  }
00165     0x1010, //  ¬   
00166     
00167 }; 
00168 
00169 
00170 
00171 /**
00172 * 9 digit (+ Hz character) 16 segment LCD display\n
00173 using Holeck's HT1621 LCD driver.
00174 
00175 @code
00176 #include "mbed.h"
00177 #include "digitLCD.h"
00178 
00179 digitLCD lcd(PTC0,PTC1,PTD6); // WO, CS, DATA
00180 
00181 main()
00182 {
00183     lcd.clear();            // clears display
00184     lcd.printf("ABCDEFGHI"); // Standard printf function, All ASCII characters will display
00185     
00186     while(1){               // basic RTC clock function
00187         time_t seconds = time(NULL);
00188         strftime(timebuf, 32, "%H-%M-%S\n", localtime(&seconds));
00189         strftime(datebuf, 32, "%a %d%b\n", localtime(&seconds));        
00190         if (n<7){lcd.printf(timebuf);}
00191             else{lcd.printf(datebuf);}
00192         if(n>10){n=0;}
00193         n++;
00194         wait(1);       
00195     }
00196 @endcode
00197 */
00198 
00199 class digitLCD 
00200 {    
00201 public:
00202 
00203     digitLCD(PinName Rw, PinName CS, PinName DATA); // Default constructor    
00204     
00205     //! Initialise display
00206     void init();
00207     //! Clear Display
00208     void clear();
00209     //! Powers on LCD bias generators
00210     void LCDon();
00211     //! Powers off LCD bias generators (low power mode)
00212     void LCDoff();
00213     //! LCD all segments on test
00214     void allsegson();
00215     //! Hz symbol on
00216     void HZon();
00217     //! Hz symbol off
00218     void HZoff();
00219     void SendBit(char sdata,char cnt);
00220     void SendCmd(int command);
00221     void Write(char addr,int sdata);    
00222     
00223     void putc( char line, char c ) {
00224         if ( (c == '\n') || (c == '\r') ) {
00225             clear_rest_of_line( line );
00226             curs[ line ] = 0;
00227             return;
00228         }        
00229         if (curs[ line ]  >= 9 )
00230             return;
00231         Write(curs[ line ],num[c-32]);
00232         curs[ line ]++;
00233     }
00234     
00235     void puts( char *s ) { 
00236          char line=0;  
00237         while ( char c    = *s++ )
00238             putc( line, c );
00239     }
00240     
00241     void printf(char *format, ... ) {
00242         char        s[ 11 ];        
00243         va_list        args;
00244         va_start( args, format );
00245         vsnprintf( s, 11, format, args );
00246         va_end( args );
00247         puts(  s );
00248         
00249     }
00250     char curs[1];
00251     void clear_rest_of_line( char line ) {
00252         for ( int i = curs[ line ]; i < 10; i++ )
00253             putc( line, ' ');
00254     }
00255     
00256 
00257 private:    
00258     DigitalOut  _Rw;
00259     DigitalOut  _CS;
00260     DigitalOut  _DATA;   
00261 };