Wim Huiskamp / Mbed 2 deprecated mbed_PT6302

Dependencies:   mbed PT6302

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 /* mbed PT6302 Test program, for Princeton PT6302 VFD controller
00002  * Note the PT6302 is identical to the OKI ML9208 
00003  *
00004  * Copyright (c) 2017, v01: WH, Initial version
00005  *
00006  * Permission is hereby granted, free of charge, to any person obtaining a copy
00007  * of this software and associated documentation files (the "Software"), to deal
00008  * in the Software without restriction, including without limitation the rights
00009  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00010  * copies of the Software, and to permit persons to whom the Software is
00011  * furnished to do so, subject to the following conditions:
00012  *
00013  * The above copyright notice and this permission notice shall be included in
00014  * all copies or substantial portions of the Software.
00015  *
00016  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00017  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00018  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00019  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00020  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00021  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00022  * THE SOFTWARE.
00023  */
00024 #include "mbed.h"
00025 #include "PT6302.h"
00026 
00027 
00028 // Select one of the testboards for Princeton PT6302 VFD controller
00029 #include "PT6302_Config.h"
00030 
00031 #if (HANNSTAR_TEST == 1)
00032 
00033 // PT6302 Test
00034 #include "mbed.h"
00035 #include "PT6302.h"
00036 
00037 DigitalOut myled(LED1);
00038 Serial pc(USBTX, USBRX);
00039 
00040 //PT6302_HANNSTAR PT6302(p5, p7, p8);
00041 PT6302_HANNSTAR PT6302(p11, p13, p14);
00042 
00043 void show_menu() {
00044 //    pc.printf("0:   Exit\n\r");
00045     pc.printf("1:   All\n\r");    
00046     pc.printf("2:   Show UDC chars\n\r");    
00047     pc.printf("3:   Show all chars\n\r");
00048     pc.printf("4:   Show all digits\n\r");    
00049 //    pc.printf("5:   Show all icons\n\r");
00050     pc.printf("6:   Counter\n\r");
00051     pc.printf("7:   Floats\n\r");
00052     pc.printf("8:   Kitt\n\r");
00053     pc.printf("9:   Cls\n\r");    
00054     pc.printf("A/B: LED On/Off\n\r");
00055     pc.printf("C:   Bye\n\r");    
00056 }
00057 
00058 
00059 int main() {
00060   pc.printf("Hello World: PT6302 Hannstar test\n\r");
00061 
00062   PT6302.locate(0);    
00063   PT6302.printf("Hello mbed");    
00064 
00065   PT6302.setBrightness(PT6302_BRT_7);
00066   wait(1);  
00067   PT6302.setBrightness(PT6302_BRT_0);
00068   wait(1);  
00069   PT6302.setBrightness(PT6302_BRT_DEF);
00070   wait(1);
00071 
00072     char cmd, cmd2 = '0';
00073     while (1) {
00074       
00075       show_menu();
00076       cmd2 = pc.getc();
00077 
00078       switch (cmd2) {
00079         case '1' : {
00080                       pc.printf("all\r\n");
00081                       PT6302.cls(); 
00082                       PT6302.printf("Hello mbed");
00083                       break;
00084         }
00085 
00086 
00087         case '2' : {
00088                       pc.printf("UDC\r\n");
00089                       PT6302.cls();
00090                      
00091                       // Store UDC_idx=0, 1 
00092                       PT6302.setUDC(0, (char *) udc_LAR); // Left Arrow
00093                       PT6302.setUDC(1, (char *) udc_RAR); // Right Arrow                      
00094 
00095                       // Show UDC_idx=0, 1 
00096                       PT6302.locate(0);
00097                       PT6302.putc((char) 0);
00098                       PT6302.putc((char) 1);                      
00099                     
00100                       break;
00101         }
00102 
00103         case '3' : {
00104 #if(1)
00105 //test to show all chars
00106           pc.printf("Show all alpha chars\r\n");
00107           wait(1);          
00108           PT6302.cls(); 
00109          
00110           for (int i=0; i<26; i++) {
00111             PT6302.printf("%c", char(i + 'A'));
00112             PT6302.printf("%c", char(i + 'a'));            
00113             wait(0.25);                      
00114           }
00115           pc.printf("Show all alpha chars done\r\n");                    
00116 #endif            
00117           break;          
00118         }
00119 
00120         case '4': {
00121 #if(0)
00122 //test to show all digits (base is 10)
00123           pc.printf("Show all digits\r\n");
00124           wait(1);          
00125           PT6302.cls(); 
00126 
00127           for (int i=0; i<PT6302_NR_DIGITS; i++) {
00128 
00129             for (int cnt=0; cnt<10; cnt++) {
00130               PT6302.locate(i);
00131               PT6302.printf("%0d", cnt);
00132 
00133 //              wait(0.5);
00134               cmd = pc.getc(); // wait for key
00135             }  
00136           }
00137           pc.printf("\r\nShow all digits done\r\n");                    
00138 #endif                
00139 
00140 #if(1)
00141 //test to show all digits (base is 0x10)
00142           pc.printf("Show all hex digits\r\n");
00143           wait(1);          
00144           PT6302.cls(); 
00145 
00146           PT6302.printf("%010X", 0x0123ABCDEF);
00147           cmd = pc.getc(); // wait for key
00148           PT6302.locate(0);          
00149           PT6302.printf("%016X", 0x0);
00150                     
00151           for (int i=0; i<HANNSTAR_NR_DIGITS; i++) {
00152 //          for (int i=0; i<1; i++) {
00153 
00154             for (int cnt=0; cnt<0x10; cnt++) {
00155               PT6302.locate(i);
00156               PT6302.printf("%0X", cnt);
00157 //              pc.printf("%0X", cnt);              
00158 //              wait(0.5);
00159               cmd = pc.getc(); // wait for key
00160             }  
00161           }
00162           pc.printf("\r\nShow all hex digits done\r\n");          
00163 #endif                
00164           break;          
00165         }
00166         
00167         case '5':  { 
00168           break;
00169         }                          
00170 
00171         case '6': {
00172           pc.printf("Show counter\r\n");          
00173           PT6302.cls(); // clear all, preserve Icons
00174 
00175 #if(1)
00176           PT6302.locate(0);
00177           PT6302.printf("Cnt=");
00178           for (int cnt=0; cnt<=0xFF; cnt++) {
00179             PT6302.locate(8);
00180             PT6302.printf("%02X", cnt);           
00181             wait(0.2);
00182           }  
00183 #endif
00184           break;          
00185         }
00186 
00187         case '7': {
00188           pc.printf("Show floats\r\n");
00189           
00190           PT6302.cls(); // clear all, preserve Icons
00191           PT6302.printf("%1.7f", -0.1234567);  // test decimal point display
00192           wait(0.5);
00193           PT6302.cls(); // clear all, preserve Icons          
00194           PT6302.printf("%3.6f", 123.456789);  // test decimal point display
00195           break;          
00196         }
00197 
00198         case '8': {
00199 
00200 #if(1)
00201 //test to show KITT
00202           pc.printf("Show KITT scanner\r\n");
00203           
00204 //                          0123456789
00205 const char KITT[][11]  = {{"8         "},
00206                           {"38        "},
00207                           {" 38       "},
00208                           {"  38      "},
00209                           {"   38     "},
00210                           {"    38    "},
00211                           {"     38   "},
00212                           {"      38  "},
00213                           {"       38 "},
00214                           {"        38"},
00215                           {"         3"},
00216                           {"          "},
00217                           {"         8"},
00218                           {"        8E"},
00219                           {"       8E "},
00220                           {"      8E  "},
00221                           {"     8E   "},
00222                           {"    8E    "},                                                                              
00223                           {"   8E     "},
00224                           {"  8E      "},
00225                           {" 8E       "},
00226                           {"8E        "},
00227                           {"E         "},
00228                           {"          "}
00229                         };     
00230          
00231           PT6302.cls(); // clear all, preserve Icons
00232           
00233           while (!pc.readable()) { // wait for key            
00234             for (int i=0; i < (sizeof(KITT) / 11) ; i++) {
00235               PT6302.locate(0);
00236               PT6302.printf("%s", KITT[i]);
00237               wait(0.1);
00238             }
00239           }
00240           cmd = pc.getc(); // read key           
00241           pc.printf("Show KITT done\r\n");
00242 #endif
00243           break;
00244         }  
00245 
00246 
00247         case '9': {
00248           PT6302.cls(true); // clear all, including Icons      
00249           break;
00250         }  
00251 
00252         case 'A': {
00253           pc.printf("LED On\r\n");
00254           PT6302.setPort(0x02);          
00255           break;
00256         } 
00257 
00258         case 'B': {
00259           pc.printf("LED Off\r\n");
00260           PT6302.setPort(0x00);          
00261           break;
00262         } 
00263 
00264         case 'C': {
00265           PT6302.cls(); // clear all, preserve Icons
00266           PT6302.printf("Bye");          
00267        
00268           break;
00269         } 
00270 
00271         default : {
00272           break;
00273         }         
00274      
00275       } //switch cmd
00276 
00277     myled = !myled;
00278     wait(0.3);
00279   }
00280 }
00281 #endif
00282 
00283 
00284 #if (PT6302_TEST == 1)
00285 
00286 // PT6302 Bare Metal Test
00287 #include "mbed.h"
00288 #include "PT6302.h"
00289 
00290 DigitalOut myled(LED1);
00291 Serial pc(USBTX, USBRX);
00292 
00293 // PT6302 declaration, Default setting 16 Grids @ 35 Segments
00294 PT6302 PT6302(p5, p7, p8); // DI, CLK, CS
00295 
00296 int main() {
00297   pc.printf("Hello World: PT6302 test\n\r");
00298 
00299   PT6302.writeData((char)'H', 9);
00300   PT6302.writeData((char)'e', 8);
00301   PT6302.writeData((char)'l', 7);
00302   PT6302.writeData((char)'l', 6);
00303   PT6302.writeData((char)'o', 5);
00304 
00305   PT6302.setBlink(true, (PT6302_GR10 | PT6302_GR9 | PT6302_GR8 | PT6302_GR7 | PT6302_GR6) );
00306                       
00307   while(1) {
00308     myled = !myled;
00309     wait(1);
00310   }
00311 }
00312 #endif