Version 2.0 of TextLCD_SB1602E. The old class driver has been rewritten in more common manner of I2C devices.
Dependents: SB1602E_Hello BME280_LCD PreHeater PreHeater ... more
Hello program for the text LCD module "SB1602E" class library
This is the version 2.0 of the TextLCD_SB1602E.
- SB1602E is an I2C based low voltage text LCD panel (based Sitronix ST7032 chip)
- http://strawberry-linux.com/catalog/items?code=27002 (Online shop page (Japanese))
- http://strawberry-linux.com/pub/ST7032i.pdf (datasheet of the chip)
The "Hello" program is available
Import programSB1602E_Hello
A Hello program for the text LCD module SB1602E class driver. The SB1602E's old class driver (TextLCD_SB1602B) has been rewritten in more common manner of I2C devices.
And the "Test" program is available also.
The test program can demonstrate full functionalities of this library.
Import programSB1602E_test
Test program for SB1602E class library
SB1602E.h@1:fce3e353410c, 2015-01-05 (annotated)
- Committer:
- okano
- Date:
- Mon Jan 05 05:19:43 2015 +0000
- Revision:
- 1:fce3e353410c
- Parent:
- 0:995f80348e02
- Child:
- 2:baf578069dfc
correction for file name and online-document
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
okano | 0:995f80348e02 | 1 | /** Text LCD module "SB1602E" class library |
okano | 0:995f80348e02 | 2 | * |
okano | 0:995f80348e02 | 3 | * @author Tedd OKANO & Masato YAMANISHI |
okano | 1:fce3e353410c | 4 | * @version 2.01 |
okano | 1:fce3e353410c | 5 | * @date 05-Jan-2015 |
okano | 0:995f80348e02 | 6 | * |
okano | 0:995f80348e02 | 7 | * SB1602E is an I2C based low voltage text LCD panel (based Sitronix ST7032 chip) |
okano | 0:995f80348e02 | 8 | * The module by StrawberryLinux |
okano | 0:995f80348e02 | 9 | * http://strawberry-linux.com/catalog/items?code=27002 (Online shop page (Japanese)) |
okano | 0:995f80348e02 | 10 | * http://strawberry-linux.com/pub/ST7032i.pdf (datasheet of the chip) |
okano | 0:995f80348e02 | 11 | * |
okano | 0:995f80348e02 | 12 | * This is a library to operate this module easy. |
okano | 0:995f80348e02 | 13 | * |
okano | 0:995f80348e02 | 14 | * Released under the Apache 2 license License |
okano | 0:995f80348e02 | 15 | * |
okano | 0:995f80348e02 | 16 | * revision history (class lib name was "TextLCD_SB1602E") |
okano | 0:995f80348e02 | 17 | * revision 1.0 22-Jan-2010 a. 1st release |
okano | 0:995f80348e02 | 18 | * revision 1.1 23-Jan-2010 a. class name has been changed from lcd_SB1602E to TextLCD_SB1602E |
okano | 0:995f80348e02 | 19 | * b. printf() added |
okano | 0:995f80348e02 | 20 | * c. copyright notice added |
okano | 0:995f80348e02 | 21 | * revision 1.3 02-May-2014 a. puticon() added (for SB1602B) by Masato YAMANISHI san |
okano | 0:995f80348e02 | 22 | * revision 2.0 20-Oct-2014 a. class name is changed and published as "SB1602E" |
okano | 0:995f80348e02 | 23 | * b. re-written for better usability |
okano | 0:995f80348e02 | 24 | */ |
okano | 0:995f80348e02 | 25 | |
okano | 0:995f80348e02 | 26 | #ifndef MBED_SB1602E |
okano | 0:995f80348e02 | 27 | #define MBED_SB1602E |
okano | 0:995f80348e02 | 28 | |
okano | 0:995f80348e02 | 29 | #include <stdarg.h> |
okano | 0:995f80348e02 | 30 | #include "mbed.h" |
okano | 0:995f80348e02 | 31 | #include "SB1602E.h" |
okano | 0:995f80348e02 | 32 | |
okano | 0:995f80348e02 | 33 | |
okano | 0:995f80348e02 | 34 | /** PCA9629A class |
okano | 0:995f80348e02 | 35 | * |
okano | 0:995f80348e02 | 36 | * This is a driver code for the PCA9629A stepper motor controller. |
okano | 0:995f80348e02 | 37 | * This class provides interface for PCA9629A operation and accessing its registers. |
okano | 0:995f80348e02 | 38 | * Detail information is available on next URL. |
okano | 0:995f80348e02 | 39 | * http://www.nxp.com/products/interface_and_connectivity/i2c/i2c_bus_controller_and_bridge_ics/PCA9629APW.html |
okano | 0:995f80348e02 | 40 | * |
okano | 0:995f80348e02 | 41 | * Example: |
okano | 0:995f80348e02 | 42 | * @code |
okano | 0:995f80348e02 | 43 | * #include "mbed.h" |
okano | 0:995f80348e02 | 44 | * #include "SB1602E.h" |
okano | 0:995f80348e02 | 45 | * |
okano | 0:995f80348e02 | 46 | * SB1602E lcd( p9, p10 ); // SDA, SCL |
okano | 0:995f80348e02 | 47 | * |
okano | 0:995f80348e02 | 48 | * int main() { |
okano | 0:995f80348e02 | 49 | * lcd.printf( 0, "Hello world!" ); // line# (0 or 1), string |
okano | 0:995f80348e02 | 50 | * lcd.printf( 1, "pi = %.6f", 3.14159265 ); |
okano | 0:995f80348e02 | 51 | * } |
okano | 0:995f80348e02 | 52 | * @endcode |
okano | 0:995f80348e02 | 53 | */ |
okano | 0:995f80348e02 | 54 | class SB1602E |
okano | 0:995f80348e02 | 55 | { |
okano | 0:995f80348e02 | 56 | public: |
okano | 0:995f80348e02 | 57 | |
okano | 0:995f80348e02 | 58 | /** Create a SB1602E instance which is connected to specified I2C pins with specified address |
okano | 0:995f80348e02 | 59 | * |
okano | 0:995f80348e02 | 60 | * @param I2C_sda I2C-bus SDA pin |
okano | 0:995f80348e02 | 61 | * @param I2C_scl I2C-bus SCL pin |
okano | 0:995f80348e02 | 62 | * @param init_massage string to initialize the LCD |
okano | 0:995f80348e02 | 63 | */ |
okano | 0:995f80348e02 | 64 | SB1602E( PinName I2C_sda, PinName I2C_scl, char *init_massage = NULL ); |
okano | 0:995f80348e02 | 65 | |
okano | 0:995f80348e02 | 66 | /** Create a PCA9629A instance connected to specified I2C pins with specified address |
okano | 0:995f80348e02 | 67 | * |
okano | 0:995f80348e02 | 68 | * @param I2C object (instance) |
okano | 0:995f80348e02 | 69 | * @param init_massage string to initialize the LCD |
okano | 0:995f80348e02 | 70 | */ |
okano | 0:995f80348e02 | 71 | SB1602E( I2C &i2c_, char *init_massage = NULL ); |
okano | 0:995f80348e02 | 72 | |
okano | 0:995f80348e02 | 73 | /** Destractor |
okano | 0:995f80348e02 | 74 | */ |
okano | 0:995f80348e02 | 75 | ~SB1602E(); |
okano | 0:995f80348e02 | 76 | |
okano | 0:995f80348e02 | 77 | /** Printf |
okano | 0:995f80348e02 | 78 | * |
okano | 0:995f80348e02 | 79 | * pirntf function with line number. |
okano | 0:995f80348e02 | 80 | * it can be used like |
okano | 0:995f80348e02 | 81 | * |
okano | 0:995f80348e02 | 82 | * lcd.printf( 0, "Hello world!" ); |
okano | 0:995f80348e02 | 83 | * lcd.printf( 1, "pi = %.6f", 3.14159265 ); |
okano | 0:995f80348e02 | 84 | * |
okano | 0:995f80348e02 | 85 | * @param line line# (0 for upper, 1 for lower) |
okano | 0:995f80348e02 | 86 | * @param format following parameters are compatible to stdout's printf |
okano | 0:995f80348e02 | 87 | */ |
okano | 0:995f80348e02 | 88 | void printf( char line, char *format, ... ); |
okano | 0:995f80348e02 | 89 | |
okano | 0:995f80348e02 | 90 | /** Put character : "putc()" |
okano | 0:995f80348e02 | 91 | * |
okano | 0:995f80348e02 | 92 | * @param line line# (0 for upper, 1 for lower) |
okano | 0:995f80348e02 | 93 | * @param c character code |
okano | 0:995f80348e02 | 94 | */ |
okano | 0:995f80348e02 | 95 | void putc( char line, char c ); |
okano | 0:995f80348e02 | 96 | |
okano | 0:995f80348e02 | 97 | /** Put string : "puts()" |
okano | 0:995f80348e02 | 98 | * |
okano | 0:995f80348e02 | 99 | * @param line line# (0 for upper, 1 for lower) |
okano | 0:995f80348e02 | 100 | * @param s pointer to a string data |
okano | 0:995f80348e02 | 101 | */ |
okano | 0:995f80348e02 | 102 | void puts( char line, char *s ); |
okano | 0:995f80348e02 | 103 | |
okano | 0:995f80348e02 | 104 | /** Put character into specified screen position |
okano | 0:995f80348e02 | 105 | * |
okano | 0:995f80348e02 | 106 | * @param c character code |
okano | 0:995f80348e02 | 107 | * @param x horizontal character position on the LCD |
okano | 0:995f80348e02 | 108 | * @param y vertical character position on the LCD |
okano | 0:995f80348e02 | 109 | */ |
okano | 0:995f80348e02 | 110 | void putcxy( char c, char x, char y ); |
okano | 0:995f80348e02 | 111 | |
okano | 0:995f80348e02 | 112 | /** Clear the LCD |
okano | 0:995f80348e02 | 113 | */ |
okano | 0:995f80348e02 | 114 | void clear( void ); |
okano | 0:995f80348e02 | 115 | |
okano | 0:995f80348e02 | 116 | /** Contrast adjustment |
okano | 0:995f80348e02 | 117 | * |
okano | 0:995f80348e02 | 118 | * @param contrast value (from 0x00 to 0x3E) |
okano | 0:995f80348e02 | 119 | */ |
okano | 0:995f80348e02 | 120 | void contrast( char contrast ); |
okano | 0:995f80348e02 | 121 | |
okano | 0:995f80348e02 | 122 | /** Put a custom character given as bitmap data |
okano | 0:995f80348e02 | 123 | * |
okano | 0:995f80348e02 | 124 | * @param c_code character code |
okano | 0:995f80348e02 | 125 | * @param cg pointer to bitmap data (array of 8 bytes) |
okano | 0:995f80348e02 | 126 | * @param x horizontal character position on the LCD |
okano | 0:995f80348e02 | 127 | * @param y vertical character position on the LCD |
okano | 0:995f80348e02 | 128 | */ |
okano | 0:995f80348e02 | 129 | void put_custom_char( char c_code, const char *cg, char x, char y ); |
okano | 0:995f80348e02 | 130 | |
okano | 0:995f80348e02 | 131 | /** Set CGRAM (set custom bitmap as a character) |
okano | 0:995f80348e02 | 132 | * |
okano | 0:995f80348e02 | 133 | * @param c_code character code |
okano | 0:995f80348e02 | 134 | * @param cg pointer to bitmap data (array of 8 bytes) |
okano | 0:995f80348e02 | 135 | */ |
okano | 0:995f80348e02 | 136 | void set_CGRAM( char char_code, const char* cg ); |
okano | 0:995f80348e02 | 137 | |
okano | 0:995f80348e02 | 138 | /** Set CGRAM (set custom bitmap as a character) |
okano | 0:995f80348e02 | 139 | * |
okano | 0:995f80348e02 | 140 | * @param c_code character code |
okano | 0:995f80348e02 | 141 | * @param v bitmap data (5 bit pattern in this variable are copied to all row of a character bitmap) |
okano | 0:995f80348e02 | 142 | */ |
okano | 0:995f80348e02 | 143 | void set_CGRAM( char char_code, char v ); |
okano | 0:995f80348e02 | 144 | |
okano | 0:995f80348e02 | 145 | /** Icon operation (for SB1602B) |
okano | 0:995f80348e02 | 146 | * |
okano | 0:995f80348e02 | 147 | * @param flg bitpattern to choose ICON |
okano | 0:995f80348e02 | 148 | */ |
okano | 0:995f80348e02 | 149 | void puticon( unsigned short flg ); |
okano | 0:995f80348e02 | 150 | |
okano | 0:995f80348e02 | 151 | private: |
okano | 0:995f80348e02 | 152 | char curs[2]; |
okano | 0:995f80348e02 | 153 | void init( char *init_massage ); |
okano | 0:995f80348e02 | 154 | void clear_lest_of_line( char line ); |
okano | 0:995f80348e02 | 155 | int lcd_write( char first, char second ); |
okano | 0:995f80348e02 | 156 | int lcd_command( char command ); |
okano | 0:995f80348e02 | 157 | int lcd_data( char data ); |
okano | 0:995f80348e02 | 158 | I2C *i2c_p; |
okano | 0:995f80348e02 | 159 | I2C &i2c; |
okano | 0:995f80348e02 | 160 | char i2c_addr; |
okano | 0:995f80348e02 | 161 | |
okano | 0:995f80348e02 | 162 | private: |
okano | 0:995f80348e02 | 163 | typedef enum { |
okano | 0:995f80348e02 | 164 | #ifdef INIT_VALUE_DATASHEET_ORIGINAL |
okano | 0:995f80348e02 | 165 | Comm_FunctionSet_Normal = 0x38, |
okano | 0:995f80348e02 | 166 | Comm_FunctionSet_Extended = 0x39, |
okano | 0:995f80348e02 | 167 | Comm_InternalOscFrequency = 0x14, |
okano | 0:995f80348e02 | 168 | Comm_ContrastSet = 0x78, |
okano | 0:995f80348e02 | 169 | Comm_PwrIconContrast = 0x5E, |
okano | 0:995f80348e02 | 170 | Comm_FollowerCtrl = 0x6A, |
okano | 0:995f80348e02 | 171 | Comm_DisplayOnOff = 0x0C, |
okano | 0:995f80348e02 | 172 | Comm_ClearDisplay = 0x01, |
okano | 0:995f80348e02 | 173 | Comm_EntryModeSet = 0x06, |
okano | 0:995f80348e02 | 174 | #else |
okano | 0:995f80348e02 | 175 | Comm_FunctionSet_Normal = 0x38, |
okano | 0:995f80348e02 | 176 | Comm_FunctionSet_Extended = 0x39, |
okano | 0:995f80348e02 | 177 | Comm_InternalOscFrequency = 0x14, |
okano | 0:995f80348e02 | 178 | Comm_ContrastSet = 0x70, |
okano | 0:995f80348e02 | 179 | Comm_PwrIconContrast = 0x5C, |
okano | 0:995f80348e02 | 180 | Comm_FollowerCtrl = 0x60, |
okano | 0:995f80348e02 | 181 | Comm_DisplayOnOff = 0x0C, |
okano | 0:995f80348e02 | 182 | Comm_ClearDisplay = 0x01, |
okano | 0:995f80348e02 | 183 | Comm_EntryModeSet = 0x04, |
okano | 0:995f80348e02 | 184 | Comm_ReturnHome = 0x02, |
okano | 0:995f80348e02 | 185 | #endif |
okano | 0:995f80348e02 | 186 | Comm_SetCGRAM = 0x40 |
okano | 0:995f80348e02 | 187 | } _commands; |
okano | 0:995f80348e02 | 188 | |
okano | 0:995f80348e02 | 189 | typedef enum { |
okano | 0:995f80348e02 | 190 | MaxCharsInALine = 0x10, // buffer depth for one line (no scroll function used) |
okano | 0:995f80348e02 | 191 | COMMAND = 0x00, |
okano | 0:995f80348e02 | 192 | DATA = 0x40 |
okano | 0:995f80348e02 | 193 | } _constants; |
okano | 0:995f80348e02 | 194 | } |
okano | 0:995f80348e02 | 195 | ; |
okano | 0:995f80348e02 | 196 | |
okano | 0:995f80348e02 | 197 | #endif |
okano | 0:995f80348e02 | 198 | |
okano | 0:995f80348e02 | 199 | |
okano | 0:995f80348e02 | 200 | |
okano | 0:995f80348e02 | 201 | |
okano | 0:995f80348e02 | 202 | |
okano | 0:995f80348e02 | 203 | |
okano | 0:995f80348e02 | 204 | |
okano | 0:995f80348e02 | 205 |