
Test program for SB1602E class library
Fork of TextLCD_SB1602E by
Test 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.
main.cpp@3:d0f83fc5c73d, 2015-07-23 (annotated)
- Committer:
- okano
- Date:
- Thu Jul 23 10:24:04 2015 +0000
- Revision:
- 3:d0f83fc5c73d
- Parent:
- 1:816068edd3c3
revert to previous version because different version committed and published accidentally.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
okano | 0:694061176edf | 1 | /* |
okano | 0:694061176edf | 2 | * LCD module "SB1602E" test application |
okano | 0:694061176edf | 3 | * |
okano | 0:694061176edf | 4 | * SB1602E is an I2C based low voltage text LCD panel (based Sitronix ST7032 chip) |
okano | 0:694061176edf | 5 | * The module by StrawberryLinux |
okano | 0:694061176edf | 6 | * http://strawberry-linux.com/catalog/items?code=27002 (Online shop page (Japanese)) |
okano | 0:694061176edf | 7 | * http://strawberry-linux.com/pub/ST7032i.pdf (datasheet of the chip) |
okano | 0:694061176edf | 8 | * |
okano | 0:694061176edf | 9 | * Copyright (c) 2010 Tedd OKANO |
okano | 0:694061176edf | 10 | * Released under the MIT License: http://mbed.org/license/mit |
okano | 0:694061176edf | 11 | * |
okano | 0:694061176edf | 12 | * revision 1.0 22-Jan-2010 a. 1st release |
okano | 0:694061176edf | 13 | * revision 1.1 23-Jan-2010 a. class and app name has been changed from lcd_SB1602E to TextLCD_SB1602E |
okano | 0:694061176edf | 14 | * b. printf() test added |
okano | 0:694061176edf | 15 | * c. copyright notice added |
okano | 0:694061176edf | 16 | */ |
okano | 0:694061176edf | 17 | |
okano | 0:694061176edf | 18 | #include "mbed.h" |
okano | 1:816068edd3c3 | 19 | #include "SB1602E.h" |
okano | 0:694061176edf | 20 | |
okano | 1:816068edd3c3 | 21 | #define TEST_LOOP 1 |
okano | 1:816068edd3c3 | 22 | #define DEFAULT_TIME_INTERVAL 1.0 |
okano | 1:816068edd3c3 | 23 | #define DEFAULT_TIME_INTERVAL_PUTx 0.2 |
okano | 0:694061176edf | 24 | |
okano | 1:816068edd3c3 | 25 | #define CONTRAST_ADJUST_TEST |
okano | 1:816068edd3c3 | 26 | #define PRINTF_TEST |
okano | 1:816068edd3c3 | 27 | #define CGRAM_FUNCTION_TEST |
okano | 1:816068edd3c3 | 28 | #define PUTS_TEST_WITH_ESCAPE |
okano | 1:816068edd3c3 | 29 | #define PUTS_TEST_WITHOUT_ESCAPE |
okano | 1:816068edd3c3 | 30 | #define PUTC_TEST |
okano | 1:816068edd3c3 | 31 | //#define ICON_TEST (This has not been tested by Okano, sorry) |
okano | 0:694061176edf | 32 | |
okano | 1:816068edd3c3 | 33 | Serial pc( USBTX, USBRX ); // tx, rx |
okano | 1:816068edd3c3 | 34 | SB1602E lcd( p9, p10 ); // SDA, SCL |
okano | 1:816068edd3c3 | 35 | //SB1602E lcd( p28, p27 ); // SDA, SCL |
okano | 0:694061176edf | 36 | |
okano | 0:694061176edf | 37 | static char cg[8][8] = {// I hope I can improve this bitmap sometime in future (^^; |
okano | 0:694061176edf | 38 | { 0x1E, 0x1F, 0x1F, 0x1D, 0x1C, 0x1C, 0x1C, 0x1C }, |
okano | 0:694061176edf | 39 | { 0x01, 0x02, 0x13, 0x1B, 0x1F, 0x1F, 0x0F, 0x15 }, |
okano | 0:694061176edf | 40 | { 0x19, 0x1D, 0x1F, 0x0F, 0x1F, 0x0F, 0x1D, 0x18 }, |
okano | 0:694061176edf | 41 | { 0x1F, 0x1D, 0x16, 0x1E, 0x17, 0x1F, 0x1A, 0x1C }, |
okano | 0:694061176edf | 42 | { 0x1E, 0x1F, 0x07, 0x07, 0x1F, 0x1E, 0x00, 0x00 }, |
okano | 0:694061176edf | 43 | { 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55 }, |
okano | 0:694061176edf | 44 | { 0x44, 0x11, 0x44, 0x11, 0x44, 0x11, 0x44, 0x11 }, |
okano | 0:694061176edf | 45 | { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, |
okano | 0:694061176edf | 46 | }; |
okano | 0:694061176edf | 47 | |
okano | 0:694061176edf | 48 | void lcd_test( void ); |
okano | 0:694061176edf | 49 | void set_lines_fixed_value( char line, char value ); |
okano | 0:694061176edf | 50 | void block_pattaern( char direction, char polarity ); |
okano | 0:694061176edf | 51 | |
okano | 0:694061176edf | 52 | |
okano | 0:694061176edf | 53 | int main() { |
okano | 1:816068edd3c3 | 54 | lcd.puts( 0, "TextLCD SB1602E \r" ); |
okano | 0:694061176edf | 55 | |
okano | 0:694061176edf | 56 | for ( int i = 10; i > 0; i-- ) { |
okano | 0:694061176edf | 57 | lcd.printf( 1, " count down: %2d\r", i ); |
okano | 0:694061176edf | 58 | wait( 1.0 ); |
okano | 0:694061176edf | 59 | } |
okano | 0:694061176edf | 60 | |
okano | 0:694061176edf | 61 | do { |
okano | 0:694061176edf | 62 | lcd_test(); |
okano | 0:694061176edf | 63 | } while ( TEST_LOOP ); |
okano | 0:694061176edf | 64 | } |
okano | 0:694061176edf | 65 | |
okano | 0:694061176edf | 66 | void lcd_test( void ) { |
okano | 0:694061176edf | 67 | char s[ 18 ]; |
okano | 0:694061176edf | 68 | int i; |
okano | 0:694061176edf | 69 | |
okano | 0:694061176edf | 70 | pc.printf( "LCD test runing\n" ); |
okano | 1:816068edd3c3 | 71 | lcd.contrast( DEFAULT_CONTRAST ); |
okano | 0:694061176edf | 72 | |
okano | 0:694061176edf | 73 | #ifdef CONTRAST_ADJUST_TEST |
okano | 0:694061176edf | 74 | pc.printf( " CONTRAST_ADJUST_TEST\n" ); |
okano | 0:694061176edf | 75 | lcd.clear(); |
okano | 0:694061176edf | 76 | lcd.puts( 1, "\x07\x07\x07\x07\x07 contrast()\r" ); |
okano | 0:694061176edf | 77 | wait( DEFAULT_TIME_INTERVAL ); |
okano | 0:694061176edf | 78 | |
okano | 0:694061176edf | 79 | lcd.puts( 0, "ABCDEFGHIJKLMNOP\r" ); |
okano | 0:694061176edf | 80 | |
okano | 0:694061176edf | 81 | for ( int t = 0; t < 2; t++ ) { |
okano | 0:694061176edf | 82 | for ( i = 0; i <= 0x3F; i++ ) { |
okano | 0:694061176edf | 83 | |
okano | 0:694061176edf | 84 | lcd.printf( 1, " cntrst = 0x%02X\r", i ); |
okano | 0:694061176edf | 85 | lcd.contrast( i ); |
okano | 0:694061176edf | 86 | wait ( 0.02 ); |
okano | 0:694061176edf | 87 | } |
okano | 0:694061176edf | 88 | |
okano | 0:694061176edf | 89 | for ( i = 0x3E; i > 0 ; i-- ) { |
okano | 0:694061176edf | 90 | sprintf( s, " cntrst = 0x%02X\r", i ); |
okano | 0:694061176edf | 91 | lcd.puts( 1, s ); |
okano | 0:694061176edf | 92 | lcd.contrast( i ); |
okano | 0:694061176edf | 93 | wait ( 0.02 ); |
okano | 0:694061176edf | 94 | } |
okano | 0:694061176edf | 95 | } |
okano | 0:694061176edf | 96 | |
okano | 1:816068edd3c3 | 97 | lcd.contrast( DEFAULT_CONTRAST ); |
okano | 0:694061176edf | 98 | |
okano | 0:694061176edf | 99 | #endif |
okano | 0:694061176edf | 100 | #ifdef PRINTF_TEST |
okano | 0:694061176edf | 101 | |
okano | 0:694061176edf | 102 | pc.printf( " PRINTF_TEST\n" ); |
okano | 0:694061176edf | 103 | lcd.clear(); |
okano | 0:694061176edf | 104 | lcd.puts( 1, "\x07\x07\x07\x07\x07\x07\x07 printf()\r" ); |
okano | 0:694061176edf | 105 | wait( DEFAULT_TIME_INTERVAL ); |
okano | 0:694061176edf | 106 | |
okano | 0:694061176edf | 107 | lcd.printf( 0, "%%6.4f, %%c, %%X\"\r" ); |
okano | 0:694061176edf | 108 | for ( i = -37; i < 37; i++ ) { |
okano | 0:694061176edf | 109 | lcd.printf( 1, "%6.4f, %c, %x\r", (float)i / 37.0, 'a' + i, i + 37 ); |
okano | 0:694061176edf | 110 | wait ( 0.1 ); |
okano | 0:694061176edf | 111 | } |
okano | 0:694061176edf | 112 | |
okano | 0:694061176edf | 113 | #endif |
okano | 0:694061176edf | 114 | #ifdef CGRAM_FUNCTION_TEST |
okano | 0:694061176edf | 115 | pc.printf( " CGRAM_FUNCTION_TEST\n" ); |
okano | 0:694061176edf | 116 | lcd.clear(); |
okano | 0:694061176edf | 117 | lcd.puts( 1, "\x07\x07\x07\x07 set_CGRAM()\r" ); |
okano | 0:694061176edf | 118 | wait( DEFAULT_TIME_INTERVAL ); |
okano | 0:694061176edf | 119 | |
okano | 0:694061176edf | 120 | for ( i = 0; i < 8; i++ ) |
okano | 0:694061176edf | 121 | lcd.put_custom_char( i, cg[ i ], i, 0 ); |
okano | 0:694061176edf | 122 | |
okano | 0:694061176edf | 123 | for ( i = 0; i < 8; i++ ) |
okano | 0:694061176edf | 124 | lcd.put_custom_char( i, cg[ i ], i + 8, 0 ); |
okano | 0:694061176edf | 125 | |
okano | 0:694061176edf | 126 | for ( i = 0; i < 8; i++ ) |
okano | 0:694061176edf | 127 | lcd.put_custom_char( i, cg[ i ], i, 1 ); |
okano | 0:694061176edf | 128 | |
okano | 0:694061176edf | 129 | for ( i = 0; i < 8; i++ ) |
okano | 0:694061176edf | 130 | lcd.put_custom_char( i, cg[ i ], i + 8, 1 ); |
okano | 0:694061176edf | 131 | |
okano | 0:694061176edf | 132 | wait( DEFAULT_TIME_INTERVAL ); |
okano | 0:694061176edf | 133 | lcd.clear(); |
okano | 0:694061176edf | 134 | lcd.set_CGRAM( 7, '\x1F' ); |
okano | 0:694061176edf | 135 | |
okano | 0:694061176edf | 136 | lcd.set_CGRAM( 0, '\0' ); |
okano | 0:694061176edf | 137 | lcd.set_CGRAM( 1, '\0' ); |
okano | 0:694061176edf | 138 | lcd.set_CGRAM( 0, '\0' ); |
okano | 0:694061176edf | 139 | lcd.set_CGRAM( 1, '\0' ); |
okano | 0:694061176edf | 140 | set_lines_fixed_value( 0, 1 ); |
okano | 0:694061176edf | 141 | set_lines_fixed_value( 1, 0 ); |
okano | 0:694061176edf | 142 | |
okano | 0:694061176edf | 143 | block_pattaern( 0, 0 ); |
okano | 0:694061176edf | 144 | block_pattaern( 0, 1 ); |
okano | 0:694061176edf | 145 | block_pattaern( 1, 0 ); |
okano | 0:694061176edf | 146 | block_pattaern( 1, 1 ); |
okano | 0:694061176edf | 147 | |
okano | 0:694061176edf | 148 | |
okano | 0:694061176edf | 149 | #endif |
okano | 0:694061176edf | 150 | #ifdef PUTS_TEST_WITH_ESCAPE |
okano | 0:694061176edf | 151 | pc.printf( " PUTS_TEST_WITH_ESCAPE\n" ); |
okano | 0:694061176edf | 152 | lcd.clear(); |
okano | 0:694061176edf | 153 | lcd.puts( 1, "\x07\x07\x07 puts(\"..\\r\")\r" ); |
okano | 0:694061176edf | 154 | wait( DEFAULT_TIME_INTERVAL ); |
okano | 0:694061176edf | 155 | |
okano | 0:694061176edf | 156 | lcd.puts( 0, "\rWelcome to mbed!\r" ); |
okano | 0:694061176edf | 157 | lcd.puts( 1, "\rwww.mbed.com\r" ); |
okano | 0:694061176edf | 158 | wait( DEFAULT_TIME_INTERVAL ); |
okano | 0:694061176edf | 159 | lcd.puts( 0, " This is a\r" ); |
okano | 0:694061176edf | 160 | lcd.puts( 1, " LCD test\r" ); |
okano | 0:694061176edf | 161 | wait( DEFAULT_TIME_INTERVAL ); |
okano | 0:694061176edf | 162 | lcd.puts( 0, " 22-Jan-2010\r" ); |
okano | 0:694061176edf | 163 | lcd.puts( 1, " Hello world!\r" ); |
okano | 0:694061176edf | 164 | wait( DEFAULT_TIME_INTERVAL ); |
okano | 0:694061176edf | 165 | |
okano | 0:694061176edf | 166 | #endif |
okano | 0:694061176edf | 167 | #ifdef PUTS_TEST_WITHOUT_ESCAPE |
okano | 0:694061176edf | 168 | pc.printf( " PUTS_TEST_WITHOUT_ESCAPE\n" ); |
okano | 0:694061176edf | 169 | lcd.clear(); |
okano | 0:694061176edf | 170 | lcd.puts( 0, "\r" ); |
okano | 0:694061176edf | 171 | lcd.puts( 1, "\x07\x07\x07\x07\x07 puts(\"..\")\r" ); |
okano | 0:694061176edf | 172 | wait( DEFAULT_TIME_INTERVAL ); |
okano | 0:694061176edf | 173 | |
okano | 0:694061176edf | 174 | lcd.puts( 0, "0" ); |
okano | 0:694061176edf | 175 | lcd.puts( 1, "ABC" ); |
okano | 0:694061176edf | 176 | wait( DEFAULT_TIME_INTERVAL_PUTx ); |
okano | 0:694061176edf | 177 | lcd.puts( 0, "1" ); |
okano | 0:694061176edf | 178 | lcd.puts( 1, "DEF" ); |
okano | 0:694061176edf | 179 | wait( DEFAULT_TIME_INTERVAL_PUTx ); |
okano | 0:694061176edf | 180 | lcd.puts( 0, "2" ); |
okano | 0:694061176edf | 181 | lcd.puts( 1, "GHI" ); |
okano | 0:694061176edf | 182 | wait( DEFAULT_TIME_INTERVAL_PUTx ); |
okano | 0:694061176edf | 183 | lcd.puts( 0, "3" ); |
okano | 0:694061176edf | 184 | lcd.puts( 1, "JKL" ); |
okano | 0:694061176edf | 185 | wait( DEFAULT_TIME_INTERVAL_PUTx ); |
okano | 0:694061176edf | 186 | lcd.puts( 0, "4" ); |
okano | 0:694061176edf | 187 | lcd.puts( 1, "MNO" ); |
okano | 0:694061176edf | 188 | wait( DEFAULT_TIME_INTERVAL_PUTx ); |
okano | 0:694061176edf | 189 | lcd.puts( 0, "5" ); |
okano | 0:694061176edf | 190 | lcd.puts( 1, "PQR" ); |
okano | 0:694061176edf | 191 | wait( DEFAULT_TIME_INTERVAL_PUTx ); |
okano | 0:694061176edf | 192 | lcd.puts( 0, "6" ); |
okano | 0:694061176edf | 193 | wait( DEFAULT_TIME_INTERVAL_PUTx ); |
okano | 0:694061176edf | 194 | lcd.puts( 0, "7" ); |
okano | 0:694061176edf | 195 | wait( DEFAULT_TIME_INTERVAL_PUTx ); |
okano | 0:694061176edf | 196 | lcd.puts( 0, "8" ); |
okano | 0:694061176edf | 197 | wait( DEFAULT_TIME_INTERVAL_PUTx ); |
okano | 0:694061176edf | 198 | lcd.puts( 0, "9" ); |
okano | 0:694061176edf | 199 | wait( DEFAULT_TIME_INTERVAL_PUTx ); |
okano | 0:694061176edf | 200 | lcd.puts( 0, "A" ); |
okano | 0:694061176edf | 201 | wait( DEFAULT_TIME_INTERVAL_PUTx ); |
okano | 0:694061176edf | 202 | lcd.puts( 0, "B" ); |
okano | 0:694061176edf | 203 | wait( DEFAULT_TIME_INTERVAL_PUTx ); |
okano | 0:694061176edf | 204 | lcd.puts( 0, "C" ); |
okano | 0:694061176edf | 205 | wait( DEFAULT_TIME_INTERVAL_PUTx ); |
okano | 0:694061176edf | 206 | lcd.puts( 0, "D" ); |
okano | 0:694061176edf | 207 | wait( DEFAULT_TIME_INTERVAL_PUTx ); |
okano | 0:694061176edf | 208 | lcd.puts( 0, "E" ); |
okano | 0:694061176edf | 209 | wait( DEFAULT_TIME_INTERVAL_PUTx ); |
okano | 0:694061176edf | 210 | lcd.puts( 0, "F" ); |
okano | 0:694061176edf | 211 | wait( DEFAULT_TIME_INTERVAL_PUTx ); |
okano | 0:694061176edf | 212 | |
okano | 0:694061176edf | 213 | #endif |
okano | 0:694061176edf | 214 | #ifdef PUTC_TEST |
okano | 0:694061176edf | 215 | pc.printf( " PUTC_TEST\n" ); |
okano | 0:694061176edf | 216 | lcd.clear(); |
okano | 0:694061176edf | 217 | lcd.puts( 1, "\x07\x07\x07\x07\x07\x07\x07\x07\x07 putc()\r" ); |
okano | 0:694061176edf | 218 | wait( DEFAULT_TIME_INTERVAL ); |
okano | 0:694061176edf | 219 | |
okano | 0:694061176edf | 220 | for ( i = 0; i < 16; i++ ) { |
okano | 0:694061176edf | 221 | lcd.putc( 0, '0' + i ); |
okano | 0:694061176edf | 222 | lcd.putc( 1, 'A' + i ); |
okano | 0:694061176edf | 223 | wait( DEFAULT_TIME_INTERVAL_PUTx ); |
okano | 0:694061176edf | 224 | } |
okano | 0:694061176edf | 225 | #endif |
okano | 1:816068edd3c3 | 226 | #ifdef ICON_TEST |
okano | 1:816068edd3c3 | 227 | pc.printf( " ICON_TEST\n" ); |
okano | 1:816068edd3c3 | 228 | lcd.clear(); |
okano | 1:816068edd3c3 | 229 | lcd.puts( 1, "\x07\x07\x07\x07\x07\x07 puticon()\r" ); |
okano | 1:816068edd3c3 | 230 | unsigned short flg = 0; |
okano | 1:816068edd3c3 | 231 | for (i = 0; i < 13; i++) { |
okano | 1:816068edd3c3 | 232 | flg |= (1 << i); |
okano | 1:816068edd3c3 | 233 | lcd.puticon(flg); |
okano | 1:816068edd3c3 | 234 | wait( DEFAULT_TIME_INTERVAL_PUTx ); |
okano | 1:816068edd3c3 | 235 | } |
okano | 1:816068edd3c3 | 236 | wait( DEFAULT_TIME_INTERVAL ); |
okano | 1:816068edd3c3 | 237 | lcd.puticon(0); |
okano | 1:816068edd3c3 | 238 | #endif |
okano | 0:694061176edf | 239 | } |
okano | 0:694061176edf | 240 | |
okano | 0:694061176edf | 241 | void set_lines_fixed_value( char line, char value ) { |
okano | 0:694061176edf | 242 | for ( int i = 0; i < 16; i++ ) |
okano | 0:694061176edf | 243 | lcd.putc( line, value ); |
okano | 0:694061176edf | 244 | |
okano | 0:694061176edf | 245 | lcd.puts( line, "\r" ); |
okano | 0:694061176edf | 246 | } |
okano | 0:694061176edf | 247 | |
okano | 0:694061176edf | 248 | |
okano | 0:694061176edf | 249 | void block_pattaern( char direction, char polarity ) { |
okano | 0:694061176edf | 250 | char c[ 8 ]; |
okano | 0:694061176edf | 251 | |
okano | 0:694061176edf | 252 | for ( int x = 0; x < 2; x++ ) { |
okano | 0:694061176edf | 253 | for ( int i = 0; i < 8; i++ ) { |
okano | 0:694061176edf | 254 | for ( int j = 0; j < 8; j++ ) { |
okano | 0:694061176edf | 255 | if ( j <= i ) |
okano | 0:694061176edf | 256 | c[ (direction ? j : 7 - j) ] = (polarity ? 0x00: ~0x00 ); |
okano | 0:694061176edf | 257 | else |
okano | 0:694061176edf | 258 | c[ (direction ? j : 7 - j) ] = (polarity ? ~0x00 : 0x00 ); |
okano | 0:694061176edf | 259 | } |
okano | 0:694061176edf | 260 | |
okano | 0:694061176edf | 261 | lcd.set_CGRAM( (x ? (direction ? 0 : 1) : (direction ? 1 : 0)), c ); |
okano | 0:694061176edf | 262 | wait( 0.05 ); |
okano | 0:694061176edf | 263 | } |
okano | 0:694061176edf | 264 | } |
okano | 0:694061176edf | 265 | } |
okano | 3:d0f83fc5c73d | 266 |