Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed PowerControl SDFileSystem
Fork of SDFilesystem by
HeptaLcd.h
00001 #ifndef MBED_HeptaLcd 00002 #define MBED_HeptaLcd 00003 00004 #include <stdarg.h> 00005 #include "mbed.h" 00006 #include "I2cBusDevice.h" 00007 00008 // SB1602E IIC address 00009 00010 const char SB1602E_addr = 0x7C; 00011 00012 // SB1602E initialization command sequence 00013 00014 #ifdef INIT_VALUE_DATASHEET_ORIGINAL 00015 00016 const char Comm_FunctionSet_Normal = 0x38; 00017 const char Comm_FunctionSet_Extended = 0x39; 00018 const char Comm_InternalOscFrequency = 0x14; 00019 const char Comm_ContrastSet = 0x78; 00020 const char Comm_PwrIconContrast = 0x5E; 00021 const char Comm_FollowerCtrl = 0x6A; 00022 const char Comm_DisplayOnOff = 0x0C; 00023 const char Comm_ClearDisplay = 0x01; 00024 const char Comm_EntryModeSet = 0x06; 00025 00026 #else 00027 00028 const char Comm_FunctionSet_Normal = 0x38; 00029 const char Comm_FunctionSet_Extended = 0x39; 00030 const char Comm_InternalOscFrequency = 0x14; 00031 const char Comm_ContrastSet = 0x70; 00032 const char Comm_PwrIconContrast = 0x5C; 00033 const char Comm_FollowerCtrl = 0x60; 00034 const char Comm_DisplayOnOff = 0x0C; 00035 const char Comm_ClearDisplay = 0x01; 00036 const char Comm_EntryModeSet = 0x04; 00037 const char Comm_ReturnHome = 0x02; 00038 00039 #endif 00040 00041 // SB1602E general commands 00042 00043 const char Comm_SetDDRAMAddress = 0x80; 00044 const char DDRAMAddress_Ofst[] = { 0x00, 0x40 }; 00045 00046 const char Comm_SetCGRAM = 0x40; 00047 00048 // SB1602E setting values 00049 00050 const char default_Contrast = 0x35; 00051 00052 const char COMMAND = 0x00; 00053 const char DATA = 0x40; 00054 00055 const char MaxCharsInALine = 0x10; // buffer deoth for one line (no scroll function used) 00056 00057 const char init_seq0_length = 7; 00058 const char init_seq0[ init_seq0_length ] 00059 = { 00060 Comm_FunctionSet_Normal, 00061 Comm_ReturnHome, // This may be required to reset the scroll function 00062 Comm_FunctionSet_Extended, 00063 Comm_InternalOscFrequency, 00064 Comm_ContrastSet | ( default_Contrast & 0xF), 00065 Comm_PwrIconContrast | ((default_Contrast >> 4) & 0x3), 00066 Comm_FollowerCtrl | 0x0A, 00067 00068 }; 00069 // required 30us interval 00070 00071 const char init_seq1_length = 3; 00072 const char init_seq1[ init_seq1_length ] 00073 = { 00074 Comm_DisplayOnOff, 00075 Comm_ClearDisplay, 00076 Comm_EntryModeSet, 00077 }; 00078 // required 30us, 2ms interval 00079 00080 00081 class HeptaLcd : I2cBusDevice { 00082 public: 00083 I2C lcd; 00084 int addr; 00085 explicit HeptaLcd(PinName sda, PinName scl, char dev_address = SB1602E_addr, char *init_massage = " " ) : lcd(sda,scl),addr(dev_address),I2cBusDevice(&lcd, dev_address ) { 00086 wait( 0.04 ); // interval after hardware reset 00087 00088 for ( int i = 0; i < init_seq0_length; i++ ) { 00089 lcd_command( init_seq0[ i ] ); 00090 wait( 30e-6 ); 00091 } 00092 00093 wait( 0.2 ); 00094 00095 for ( int i = 0; i < init_seq1_length; i++ ) { 00096 lcd_command( init_seq1[ i ] ); 00097 wait( 2e-3 ); 00098 } 00099 00100 if ( init_massage ) 00101 puts( 0, init_massage ); 00102 00103 set_CGRAM( 7, '\x1F' ); 00104 00105 curs[ 0 ] = 0; 00106 curs[ 1 ] = 0; 00107 } 00108 00109 00110 ~HeptaLcd() { 00111 } 00112 00113 void clear( void ) { 00114 lcd_command( Comm_ClearDisplay ); 00115 wait( 2e-3 ); 00116 curs[ 0 ] = 0; 00117 curs[ 1 ] = 0; 00118 } 00119 00120 void initilize(){ 00121 char *init_massage = " "; 00122 for ( int i = 0; i < init_seq0_length; i++ ) { 00123 lcd_command( init_seq0[ i ] ); 00124 wait( 30e-6 ); 00125 } 00126 00127 wait( 0.2 ); 00128 00129 for ( int i = 0; i < init_seq1_length; i++ ) { 00130 lcd_command( init_seq1[ i ] ); 00131 wait( 2e-3 ); 00132 } 00133 00134 if ( init_massage ) 00135 puts( 0, init_massage ); 00136 00137 set_CGRAM( 7, '\x1F' ); 00138 00139 curs[ 0 ] = 0; 00140 curs[ 1 ] = 0; 00141 } 00142 void put_custom_char( char c_code, const char *cg, char x, char y ) { 00143 for ( int i = 0; i < 5; i++ ) { 00144 set_CGRAM( c_code, cg ); 00145 putcxy( c_code, x, y ); 00146 } 00147 } 00148 00149 void contrast( char contrast ) { 00150 lcd_command( Comm_FunctionSet_Extended ); 00151 lcd_command( Comm_ContrastSet | (contrast & 0x0f) ); 00152 lcd_command( Comm_PwrIconContrast | ((contrast>>4) & 0x03) ); 00153 lcd_command( Comm_FunctionSet_Normal ); 00154 } 00155 00156 void set_CGRAM( char char_code, const char* cg ) { 00157 for ( int i = 0; i < 8; i++ ) { 00158 lcd_command( (Comm_SetCGRAM | (char_code << 3) | i) ); 00159 lcd_data( *cg++ ); 00160 } 00161 } 00162 00163 void set_CGRAM( char char_code, char v ) { 00164 char c[ 8 ]; 00165 00166 for ( int i = 0; i < 8; i++ ) 00167 c[ i ] = v; 00168 00169 set_CGRAM( char_code, c ); 00170 } 00171 00172 void putcxy( char c, char x, char y ) { 00173 if ( (x >= MaxCharsInALine) || (y >= 2) ) 00174 return; 00175 00176 lcd_command( (Comm_SetDDRAMAddress | DDRAMAddress_Ofst[ y ]) + x ); 00177 lcd_data( c ); 00178 } 00179 00180 void putc( char line, char c ) { 00181 if ( (c == '\n') || (c == '\r') ) { 00182 clear_lest_of_line( line ); 00183 curs[ line ] = 0; 00184 return; 00185 } 00186 00187 putcxy( c, curs[ line ]++, line ); 00188 } 00189 00190 void puts( char line, char *s ) { 00191 while ( char c = *s++ ) 00192 putc( line, c ); 00193 } 00194 00195 void printf( char line, char *format, ... ) { 00196 char s[ 32 ]; 00197 va_list args; 00198 00199 va_start( args, format ); 00200 vsnprintf( s, 32, format, args ); 00201 va_end( args ); 00202 00203 puts( line, s ); 00204 } 00205 00206 private: 00207 char curs[2]; 00208 00209 void clear_lest_of_line( char line ) { 00210 for ( int i = curs[ line ]; i < MaxCharsInALine; i++ ) 00211 putcxy( ' ', i, line ); 00212 } 00213 00214 int lcd_write( char first, char second ) { 00215 char cmd[2]; 00216 00217 cmd[ 0 ] = first; 00218 cmd[ 1 ] = second; 00219 00220 return ( write( cmd, 2 ) ); 00221 00222 } 00223 00224 int lcd_command( char command ) { 00225 return ( lcd_write( COMMAND, command ) ); 00226 } 00227 00228 int lcd_data( char data ) { 00229 return ( lcd_write( DATA, data ) ); 00230 } 00231 } 00232 ; 00233 00234 #endif 00235 00236 00237 00238 00239 00240 00241 00242
Generated on Fri Jul 15 2022 08:06:17 by
1.7.2
