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.
main.cpp
00001 /* Test harness for TextStar serial LCD library 00002 * Paul Griffith 00003 * Last edit: 10 Jan 2010 00004 */ 00005 00006 #include "mbed.h" 00007 #include "TextStar.h" 00008 00009 void bargraph_demo(int); 00010 void printhelps(void); 00011 void bad_args(void); 00012 00013 Serial pc(USBTX, USBRX); 00014 TextStar lcd(p9, p10); // tx, rx 00015 00016 int main() { 00017 char buf[120], *cp; 00018 char arg1[50], arg2[50], arg3[50]; 00019 int argc, cnt = 0, i, j, k, l; 00020 00021 00022 printf("TextStar Serial LCD test harness\n"); 00023 printf("Type ? for help\n"); 00024 lcd.printf("TextStar Serial\rLCD test harness"); 00025 00026 while (1) { 00027 printf("> "); 00028 cp = buf; 00029 while ( (*cp++ = putchar(getchar())) != '\r') ; //get a line of input 00030 *cp = '\0'; //terminate buffer 00031 printf("\n"); 00032 argc = sscanf(buf, "%s%s%s", arg1, arg2, arg3); //extract command and arguments 00033 if (argc < 1) 00034 continue; 00035 switch (arg1[0]) { 00036 00037 case 'b': //bar graph demo 00038 bargraph_demo(0); 00039 wait(1.0); 00040 bargraph_demo(1); 00041 break; 00042 00043 case 'c': //clear display 00044 lcd.cls(); 00045 break; 00046 00047 case 'C': //set cursor style 00048 if (argc != 2) { 00049 bad_args(); 00050 break; 00051 } 00052 sscanf(arg2, "%d", &i); //extract style number 00053 lcd.set_cursor(i); 00054 break; 00055 00056 case 'd': //move cursor down 00057 j = 1; 00058 if (argc == 2) 00059 sscanf(arg2, "%d", &j); 00060 for (i = 0; i < j; i++) 00061 lcd.down(); 00062 break; 00063 00064 case 'D': //define custom character 00065 sscanf(buf, "%s%d%x%x", arg1, &i, &j, &k); //extract arguments 00066 arg3[0] = (j >> 24) & 0xFF; 00067 arg3[1] = (j >> 16) & 0xFF; 00068 arg3[2] = (j >> 8) & 0xFF; 00069 arg3[3] = j & 0xFF; 00070 arg3[4] = (k >> 24) & 0xFF; 00071 arg3[5] = (k >> 16) & 0xFF; 00072 arg3[6] = (k >> 8) & 0xFF; 00073 arg3[7] = k & 0xFF; 00074 lcd.custom_char(i, arg3); 00075 lcd.cls(); 00076 lcd.printf("Custom chars"); 00077 lcd.locate(0, 1); 00078 lcd.printf("128-135 %c%c%c%c%c%c%c%c", 0x80, 0x81, 00079 0x82, 0x83, 0x84, 0x85, 0x86, 0x87); 00080 break; 00081 00082 case 'e': //enter text at current position 00083 if (argc < 2) { 00084 bad_args(); 00085 break; 00086 } 00087 *--cp = '\0'; //get rid of \r at end of buffer 00088 sscanf(buf, "%s%n", arg1, &i); //extract arguments 00089 // cp = buf + i; 00090 // while (*cp++ == ' ') ; //find start of text 00091 // --cp; 00092 cp = buf + i + 1; //allow leading white space 00093 lcd.printf("%s", cp); 00094 break; 00095 00096 case 'h': //cursor home 00097 lcd.home(); 00098 break; 00099 00100 case 'k': //get key states 00101 while (lcd.readable() ) 00102 lcd.getc(); //empty buffer 00103 printf("Key states = "); 00104 lcd.send_keys(); 00105 i = lcd.getc(); 00106 j = lcd.getc(); 00107 k = lcd.getc(); 00108 l = lcd.getc(); 00109 printf("%c%c%c%c\n", i, j, k, l); 00110 break; 00111 00112 case 'K': //get key output until any char typed on pc 00113 printf("Key output: "); 00114 while (pc.readable() == 0) { 00115 if (lcd.readable() ) 00116 pc.putc(lcd.getc() ); 00117 } 00118 while (pc.readable() ) 00119 pc.getc(); 00120 printf("\nAll done\n"); 00121 break; 00122 00123 case 'o': //output demo 00124 lcd.cls(); 00125 j = 20; 00126 if (argc == 2) { 00127 sscanf(arg2, "%d", &j); 00128 } 00129 for (i = 0; i < j; i++) { 00130 lcd.printf("Count = %d\r", cnt++); 00131 wait( (i == 0) ? 1.0 : 0.2); 00132 } 00133 break; 00134 00135 case 'l': //move cursor left 00136 j = 1; 00137 if (argc == 2) 00138 sscanf(arg2, "%d", &j); 00139 for (i = 0; i < j; i++) 00140 lcd.left(); 00141 break; 00142 00143 case 'p': //set cursor position 00144 if (argc < 3) { 00145 bad_args(); 00146 break; 00147 } 00148 sscanf(buf, "%s%d%d", arg1, &i, &j); //extract arguments 00149 lcd.locate(j, i); 00150 break; 00151 00152 case 'q': //quit 00153 exit(1); 00154 break; 00155 00156 case 'r': //move cursor right 00157 j = 1; 00158 if (argc == 2) 00159 sscanf(arg2, "%d", &j); 00160 for (i = 0; i < j; i++) 00161 lcd.right(); 00162 break; 00163 00164 case 'R': //reset display (and set autoblank (and autoscroll) ) 00165 if (argc == 1) { 00166 lcd.reset(); 00167 } 00168 else if (argc == 2) { 00169 sscanf(arg2, "%d", &i); 00170 lcd.reset(i); 00171 } 00172 else if (argc >= 3) { 00173 sscanf(arg2, "%d", &i); 00174 sscanf(arg3, "%d", &j); 00175 lcd.reset(i, j); 00176 } 00177 break; 00178 00179 case 's': //scroll down 00180 j = 1; 00181 if (argc == 2) 00182 sscanf(arg2, "%d", &j); 00183 for (i = 0; i < j; i++) 00184 lcd.scroll_down(); 00185 break; 00186 00187 case 'S': //scroll up 00188 j = 1; 00189 if (argc == 2) 00190 sscanf(arg2, "%d", &j); 00191 for (i = 0; i < j; i++) 00192 lcd.scroll_up(); 00193 break; 00194 00195 case 'u': //move cursor up 00196 j = 1; 00197 if (argc == 2) 00198 sscanf(arg2, "%d", &j); 00199 for (i = 0; i < j; i++) 00200 lcd.up(); 00201 break; 00202 00203 case 'v': //display firmware version 00204 lcd.version(); 00205 break; 00206 00207 00208 case 'w': //move visible window 00209 if (argc != 2) { 00210 bad_args(); 00211 break; 00212 } 00213 sscanf(arg2, "%d", &i); //extract line number 00214 lcd.window(i); 00215 break; 00216 00217 case 'x': //send hex data to display 00218 argc = sscanf(buf, "%s%x%x%x%x", arg1, &i, &j, &k, &l); //extract arguments 00219 if (argc > 1) 00220 lcd.putc(i & 0xFF); 00221 if (argc > 2) 00222 lcd.putc(j & 0xFF); 00223 if (argc > 3) 00224 lcd.putc(k & 0xFF); 00225 if (argc > 4) 00226 lcd.putc(l & 0xFF); 00227 break; 00228 00229 case '?': //print help 00230 printhelps(); 00231 break; 00232 00233 default: 00234 printf("?? Unknown command\n"); 00235 break; 00236 } 00237 } 00238 } 00239 00240 //Command functions 00241 00242 void printhelps(void) { 00243 printf("Command summary:\n"); 00244 printf("b bar graph demo\n"); 00245 printf("c clear display\n"); 00246 printf("C style set cursor style (0-4)\n"); 00247 printf("d [n] cursor down n times (default 1)\n"); 00248 printf("D n bm1 bm2 define custom char n (128-135) with bitmap in hex\n"); 00249 printf(" bm1 = bitmap rows 1-4, bm2 = rows 5-8\n"); 00250 printf("e text enter text at current position\n"); 00251 printf("h cursor home\n"); 00252 printf("k get key states\n"); 00253 printf("K show key output\n"); 00254 printf("l [n] cursor left n times (default 1)\n"); 00255 printf("o output demo\n"); 00256 printf("p line col set cursor position to line (0-15) and column (0-15)\n"); 00257 printf("q quit\n"); 00258 printf("r [n] cursor right n times (default 1)\n"); 00259 printf("R [ab] [as] reset display, set auto-blank (0/1) and auto-scroll (0/1)\n"); 00260 printf("s [n] scroll down n times (default 1)\n"); 00261 printf("S [n] scroll up n times (default 1)\n"); 00262 printf("u [n] cursor up n times (default 1)\n"); 00263 printf("v display firmware version\n"); 00264 printf("w line move display window to specified line (0-14)\n"); 00265 printf("x b b b b send hex data to display, up to 4 bytes\n"); 00266 } 00267 00268 void bargraph_demo(int capped) { 00269 00270 int i; 00271 00272 lcd.cls(); 00273 lcd.printf("BAR GRAPH DEMO %d", capped + 1); 00274 for (i = 0; i <= 100; i++) { 00275 lcd.locate(0, 1); 00276 lcd.bar_graph(capped, 16, i); 00277 wait( (i == 0) ? 1.0 : 0.02); 00278 } 00279 wait(1.0); 00280 for (i = 100; i >= 0; i--) { 00281 lcd.locate(0, 1); 00282 lcd.bar_graph(capped, 16, i); 00283 wait( (i == 0) ? 1.0 : 0.02); 00284 } 00285 } 00286 00287 void bad_args(void) { 00288 printf("?? Bad arguments\n"); 00289 } 00290
Generated on Sun Jul 24 2022 19:15:07 by
1.7.2